@tamagui/core 1.0.0-alpha.0

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 (333) hide show
  1. package/.ultra.cache.json +1 -0
  2. package/_/constants/constants.js +14 -0
  3. package/_/constants/constants.js.map +7 -0
  4. package/_/constants/platform.js +20 -0
  5. package/_/constants/platform.js.map +7 -0
  6. package/_/constants/pseudos.js +18 -0
  7. package/_/constants/pseudos.js.map +7 -0
  8. package/_/constants/rnw.js +22 -0
  9. package/_/constants/rnw.js.map +7 -0
  10. package/_/createComponent.js +427 -0
  11. package/_/createComponent.js.map +7 -0
  12. package/_/createShorthands.js +10 -0
  13. package/_/createShorthands.js.map +7 -0
  14. package/_/createTamagui.js +122 -0
  15. package/_/createTamagui.js.map +7 -0
  16. package/_/createTheme.js +20 -0
  17. package/_/createTheme.js.map +7 -0
  18. package/_/createTokens.js +29 -0
  19. package/_/createTokens.js.map +7 -0
  20. package/_/createVariable.js +22 -0
  21. package/_/createVariable.js.map +7 -0
  22. package/_/helpers/addStylesUsingClassname.js +32 -0
  23. package/_/helpers/addStylesUsingClassname.js.map +7 -0
  24. package/_/helpers/createMediaStyle.js +34 -0
  25. package/_/helpers/createMediaStyle.js.map +7 -0
  26. package/_/helpers/createTamaguiProvider.js +42 -0
  27. package/_/helpers/createTamaguiProvider.js.map +7 -0
  28. package/_/helpers/extendStaticConfig.js +176 -0
  29. package/_/helpers/extendStaticConfig.js.map +7 -0
  30. package/_/helpers/fixNativeShadow.js +8 -0
  31. package/_/helpers/fixNativeShadow.js.map +7 -0
  32. package/_/helpers/fixNativeShadow.native.js +30 -0
  33. package/_/helpers/fixNativeShadow.native.js.map +7 -0
  34. package/_/helpers/getSplitStyles.js +160 -0
  35. package/_/helpers/getSplitStyles.js.map +7 -0
  36. package/_/helpers/getStylesAtomic.js +84 -0
  37. package/_/helpers/getStylesAtomic.js.map +7 -0
  38. package/_/helpers/getStylesAtomic.native.js +10 -0
  39. package/_/helpers/getStylesAtomic.native.js.map +7 -0
  40. package/_/helpers/insertStyleRule.js +24 -0
  41. package/_/helpers/insertStyleRule.js.map +7 -0
  42. package/_/helpers/matchMedia.js +15 -0
  43. package/_/helpers/matchMedia.js.map +7 -0
  44. package/_/helpers/matchMedia.native.js +8 -0
  45. package/_/helpers/matchMedia.native.js.map +7 -0
  46. package/_/helpers/themeable.js +26 -0
  47. package/_/helpers/themeable.js.map +7 -0
  48. package/_/hooks/useConstant.js +15 -0
  49. package/_/hooks/useConstant.js.map +7 -0
  50. package/_/hooks/useFeatures.js +75 -0
  51. package/_/hooks/useFeatures.js.map +7 -0
  52. package/_/hooks/useForceUpdate.js +28 -0
  53. package/_/hooks/useForceUpdate.js.map +7 -0
  54. package/_/hooks/useMedia.js +173 -0
  55. package/_/hooks/useMedia.js.map +7 -0
  56. package/_/hooks/usePressable.js +14 -0
  57. package/_/hooks/usePressable.js.map +7 -0
  58. package/_/hooks/useTheme.js +94 -0
  59. package/_/hooks/useTheme.js.map +7 -0
  60. package/_/index.js +30 -0
  61. package/_/index.js.map +7 -0
  62. package/_/static/postProcessStyles.js +18 -0
  63. package/_/static/postProcessStyles.js.map +7 -0
  64. package/_/static.js +12 -0
  65. package/_/static.js.map +7 -0
  66. package/_/styled.js +21 -0
  67. package/_/styled.js.map +7 -0
  68. package/_/types.js +1 -0
  69. package/_/types.js.map +7 -0
  70. package/_/views/Animated.js +79 -0
  71. package/_/views/Animated.js.map +7 -0
  72. package/_/views/Stack.js +12 -0
  73. package/_/views/Stack.js.map +7 -0
  74. package/_/views/Text.js +60 -0
  75. package/_/views/Text.js.map +7 -0
  76. package/_/views/TextAncestorContext.js +19 -0
  77. package/_/views/TextAncestorContext.js.map +7 -0
  78. package/_/views/Theme.js +57 -0
  79. package/_/views/Theme.js.map +7 -0
  80. package/_/views/ThemeContext.js +6 -0
  81. package/_/views/ThemeContext.js.map +7 -0
  82. package/_/views/ThemeInverse.js +27 -0
  83. package/_/views/ThemeInverse.js.map +7 -0
  84. package/_/views/ThemeManagerContext.js +56 -0
  85. package/_/views/ThemeManagerContext.js.map +7 -0
  86. package/_/views/ThemeProvider.js +45 -0
  87. package/_/views/ThemeProvider.js.map +7 -0
  88. package/dist/constants/constants.js +14 -0
  89. package/dist/constants/constants.js.map +7 -0
  90. package/dist/constants/platform.js +19 -0
  91. package/dist/constants/platform.js.map +7 -0
  92. package/dist/constants/pseudos.js +18 -0
  93. package/dist/constants/pseudos.js.map +7 -0
  94. package/dist/constants/rnw.js +22 -0
  95. package/dist/constants/rnw.js.map +7 -0
  96. package/dist/constants/styleConstants.js +46 -0
  97. package/dist/constants/styleConstants.js.map +7 -0
  98. package/dist/createComponent.js +445 -0
  99. package/dist/createComponent.js.map +7 -0
  100. package/dist/createFont.js +24 -0
  101. package/dist/createFont.js.map +7 -0
  102. package/dist/createShorthands.js +10 -0
  103. package/dist/createShorthands.js.map +7 -0
  104. package/dist/createTamagui.js +159 -0
  105. package/dist/createTamagui.js.map +7 -0
  106. package/dist/createTheme.js +20 -0
  107. package/dist/createTheme.js.map +7 -0
  108. package/dist/createTokens.js +29 -0
  109. package/dist/createTokens.js.map +7 -0
  110. package/dist/createVariable.js +22 -0
  111. package/dist/createVariable.js.map +7 -0
  112. package/dist/helpers/addStylesUsingClassname.js +57 -0
  113. package/dist/helpers/addStylesUsingClassname.js.map +7 -0
  114. package/dist/helpers/createMediaStyle.js +34 -0
  115. package/dist/helpers/createMediaStyle.js.map +7 -0
  116. package/dist/helpers/createPropMapper.js +153 -0
  117. package/dist/helpers/createPropMapper.js.map +7 -0
  118. package/dist/helpers/createTamaguiProvider.js +25 -0
  119. package/dist/helpers/createTamaguiProvider.js.map +7 -0
  120. package/dist/helpers/extendStaticConfig.js +59 -0
  121. package/dist/helpers/extendStaticConfig.js.map +7 -0
  122. package/dist/helpers/fixNativeShadow.js +8 -0
  123. package/dist/helpers/fixNativeShadow.js.map +7 -0
  124. package/dist/helpers/fixNativeShadow.native.js +30 -0
  125. package/dist/helpers/fixNativeShadow.native.js.map +7 -0
  126. package/dist/helpers/getSplitStyles.js +160 -0
  127. package/dist/helpers/getSplitStyles.js.map +7 -0
  128. package/dist/helpers/getStylesAtomic.js +83 -0
  129. package/dist/helpers/getStylesAtomic.js.map +7 -0
  130. package/dist/helpers/getStylesAtomic.native.js +10 -0
  131. package/dist/helpers/getStylesAtomic.native.js.map +7 -0
  132. package/dist/helpers/insertStyleRule.js +24 -0
  133. package/dist/helpers/insertStyleRule.js.map +7 -0
  134. package/dist/helpers/isObj.js +7 -0
  135. package/dist/helpers/isObj.js.map +7 -0
  136. package/dist/helpers/matchMedia.js +15 -0
  137. package/dist/helpers/matchMedia.js.map +7 -0
  138. package/dist/helpers/matchMedia.native.js +8 -0
  139. package/dist/helpers/matchMedia.native.js.map +7 -0
  140. package/dist/helpers/pseudos.js +1 -0
  141. package/dist/helpers/pseudos.js.map +7 -0
  142. package/dist/helpers/themeable.js +26 -0
  143. package/dist/helpers/themeable.js.map +7 -0
  144. package/dist/hooks/useConstant.js +15 -0
  145. package/dist/hooks/useConstant.js.map +7 -0
  146. package/dist/hooks/useFeatures.js +75 -0
  147. package/dist/hooks/useFeatures.js.map +7 -0
  148. package/dist/hooks/useForceUpdate.js +28 -0
  149. package/dist/hooks/useForceUpdate.js.map +7 -0
  150. package/dist/hooks/useMedia.js +171 -0
  151. package/dist/hooks/useMedia.js.map +7 -0
  152. package/dist/hooks/usePressable.js +13 -0
  153. package/dist/hooks/usePressable.js.map +7 -0
  154. package/dist/hooks/useTheme.js +93 -0
  155. package/dist/hooks/useTheme.js.map +7 -0
  156. package/dist/index.cjs +2125 -0
  157. package/dist/index.cjs.map +7 -0
  158. package/dist/index.js +33 -0
  159. package/dist/index.js.map +7 -0
  160. package/dist/packages/core/src/constants/constants.d.ts +8 -0
  161. package/dist/packages/core/src/constants/constants.d.ts.map +1 -0
  162. package/dist/packages/core/src/constants/platform.d.ts +9 -0
  163. package/dist/packages/core/src/constants/platform.d.ts.map +1 -0
  164. package/dist/packages/core/src/constants/pseudos.d.ts +15 -0
  165. package/dist/packages/core/src/constants/pseudos.d.ts.map +1 -0
  166. package/dist/packages/core/src/constants/rnw.d.ts +2 -0
  167. package/dist/packages/core/src/constants/rnw.d.ts.map +1 -0
  168. package/dist/packages/core/src/createComponent.d.ts +16 -0
  169. package/dist/packages/core/src/createComponent.d.ts.map +1 -0
  170. package/dist/packages/core/src/createShorthands.d.ts +2 -0
  171. package/dist/packages/core/src/createShorthands.d.ts.map +1 -0
  172. package/dist/packages/core/src/createTamagui.d.ts +37 -0
  173. package/dist/packages/core/src/createTamagui.d.ts.map +1 -0
  174. package/dist/packages/core/src/createTheme.d.ts +5 -0
  175. package/dist/packages/core/src/createTheme.d.ts.map +1 -0
  176. package/dist/packages/core/src/createTokens.d.ts +45 -0
  177. package/dist/packages/core/src/createTokens.d.ts.map +1 -0
  178. package/dist/packages/core/src/createVariable.d.ts +14 -0
  179. package/dist/packages/core/src/createVariable.d.ts.map +1 -0
  180. package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts +2 -0
  181. package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts.map +1 -0
  182. package/dist/packages/core/src/helpers/createMediaStyle.d.ts +8 -0
  183. package/dist/packages/core/src/helpers/createMediaStyle.d.ts.map +1 -0
  184. package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts +5 -0
  185. package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts.map +1 -0
  186. package/dist/packages/core/src/helpers/extendStaticConfig.d.ts +5 -0
  187. package/dist/packages/core/src/helpers/extendStaticConfig.d.ts.map +1 -0
  188. package/dist/packages/core/src/helpers/fixNativeShadow.d.ts +2 -0
  189. package/dist/packages/core/src/helpers/fixNativeShadow.d.ts.map +1 -0
  190. package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts +2 -0
  191. package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts.map +1 -0
  192. package/dist/packages/core/src/helpers/getSplitStyles.d.ts +15 -0
  193. package/dist/packages/core/src/helpers/getSplitStyles.d.ts.map +1 -0
  194. package/dist/packages/core/src/helpers/getStylesAtomic.d.ts +3 -0
  195. package/dist/packages/core/src/helpers/getStylesAtomic.d.ts.map +1 -0
  196. package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts +2 -0
  197. package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts.map +1 -0
  198. package/dist/packages/core/src/helpers/insertStyleRule.d.ts +2 -0
  199. package/dist/packages/core/src/helpers/insertStyleRule.d.ts.map +1 -0
  200. package/dist/packages/core/src/helpers/matchMedia.d.ts +2 -0
  201. package/dist/packages/core/src/helpers/matchMedia.d.ts.map +1 -0
  202. package/dist/packages/core/src/helpers/matchMedia.native.d.ts +3 -0
  203. package/dist/packages/core/src/helpers/matchMedia.native.d.ts.map +1 -0
  204. package/dist/packages/core/src/helpers/themeable.d.ts +10 -0
  205. package/dist/packages/core/src/helpers/themeable.d.ts.map +1 -0
  206. package/dist/packages/core/src/hooks/useConstant.d.ts +2 -0
  207. package/dist/packages/core/src/hooks/useConstant.d.ts.map +1 -0
  208. package/dist/packages/core/src/hooks/useFeatures.d.ts +5 -0
  209. package/dist/packages/core/src/hooks/useFeatures.d.ts.map +1 -0
  210. package/dist/packages/core/src/hooks/useForceUpdate.d.ts +2 -0
  211. package/dist/packages/core/src/hooks/useForceUpdate.d.ts.map +1 -0
  212. package/dist/packages/core/src/hooks/useMedia.d.ts +16 -0
  213. package/dist/packages/core/src/hooks/useMedia.d.ts.map +1 -0
  214. package/dist/packages/core/src/hooks/usePressable.d.ts +3 -0
  215. package/dist/packages/core/src/hooks/usePressable.d.ts.map +1 -0
  216. package/dist/packages/core/src/hooks/useTheme.d.ts +18 -0
  217. package/dist/packages/core/src/hooks/useTheme.d.ts.map +1 -0
  218. package/dist/packages/core/src/index.d.ts +27 -0
  219. package/dist/packages/core/src/index.d.ts.map +1 -0
  220. package/dist/packages/core/src/static/postProcessStyles.d.ts +7 -0
  221. package/dist/packages/core/src/static/postProcessStyles.d.ts.map +1 -0
  222. package/dist/packages/core/src/static.d.ts +12 -0
  223. package/dist/packages/core/src/static.d.ts.map +1 -0
  224. package/dist/packages/core/src/styled.d.ts +16 -0
  225. package/dist/packages/core/src/styled.d.ts.map +1 -0
  226. package/dist/packages/core/src/types.d.ts +305 -0
  227. package/dist/packages/core/src/types.d.ts.map +1 -0
  228. package/dist/packages/core/src/views/Animated.d.ts +15 -0
  229. package/dist/packages/core/src/views/Animated.d.ts.map +1 -0
  230. package/dist/packages/core/src/views/Stack.d.ts +3 -0
  231. package/dist/packages/core/src/views/Stack.d.ts.map +1 -0
  232. package/dist/packages/core/src/views/Text.d.ts +3 -0
  233. package/dist/packages/core/src/views/Text.d.ts.map +1 -0
  234. package/dist/packages/core/src/views/TextAncestorContext.d.ts +3 -0
  235. package/dist/packages/core/src/views/TextAncestorContext.d.ts.map +1 -0
  236. package/dist/packages/core/src/views/Theme.d.ts +8 -0
  237. package/dist/packages/core/src/views/Theme.d.ts.map +1 -0
  238. package/dist/packages/core/src/views/ThemeContext.d.ts +18 -0
  239. package/dist/packages/core/src/views/ThemeContext.d.ts.map +1 -0
  240. package/dist/packages/core/src/views/ThemeInverse.d.ts +10 -0
  241. package/dist/packages/core/src/views/ThemeInverse.d.ts.map +1 -0
  242. package/dist/packages/core/src/views/ThemeManagerContext.d.ts +15 -0
  243. package/dist/packages/core/src/views/ThemeManagerContext.d.ts.map +1 -0
  244. package/dist/packages/core/src/views/ThemeProvider.d.ts +10 -0
  245. package/dist/packages/core/src/views/ThemeProvider.d.ts.map +1 -0
  246. package/dist/packages/helpers/src/AllRules.d.ts +3 -0
  247. package/dist/packages/helpers/src/AllRules.d.ts.map +1 -0
  248. package/dist/packages/helpers/src/concatClassName.d.ts +2 -0
  249. package/dist/packages/helpers/src/concatClassName.d.ts.map +1 -0
  250. package/dist/packages/helpers/src/index.d.ts +5 -0
  251. package/dist/packages/helpers/src/index.d.ts.map +1 -0
  252. package/dist/packages/helpers/src/types.d.ts +8 -0
  253. package/dist/packages/helpers/src/types.d.ts.map +1 -0
  254. package/dist/packages/helpers/src/validStyleProps.d.ts +475 -0
  255. package/dist/packages/helpers/src/validStyleProps.d.ts.map +1 -0
  256. package/dist/static/postProcessStyles.js +18 -0
  257. package/dist/static/postProcessStyles.js.map +7 -0
  258. package/dist/static.js +15 -0
  259. package/dist/static.js.map +7 -0
  260. package/dist/styled.js +21 -0
  261. package/dist/styled.js.map +7 -0
  262. package/dist/types.js +1 -0
  263. package/dist/types.js.map +7 -0
  264. package/dist/views/Animated.js +79 -0
  265. package/dist/views/Animated.js.map +7 -0
  266. package/dist/views/SafeAreaProvider.js +30 -0
  267. package/dist/views/SafeAreaProvider.js.map +7 -0
  268. package/dist/views/Stack.js +12 -0
  269. package/dist/views/Stack.js.map +7 -0
  270. package/dist/views/Text.js +60 -0
  271. package/dist/views/Text.js.map +7 -0
  272. package/dist/views/TextAncestorContext.js +18 -0
  273. package/dist/views/TextAncestorContext.js.map +7 -0
  274. package/dist/views/Theme.js +56 -0
  275. package/dist/views/Theme.js.map +7 -0
  276. package/dist/views/ThemeContext.js +6 -0
  277. package/dist/views/ThemeContext.js.map +7 -0
  278. package/dist/views/ThemeInverse.js +27 -0
  279. package/dist/views/ThemeInverse.js.map +7 -0
  280. package/dist/views/ThemeManagerContext.js +55 -0
  281. package/dist/views/ThemeManagerContext.js.map +7 -0
  282. package/dist/views/ThemeProvider.js +45 -0
  283. package/dist/views/ThemeProvider.js.map +7 -0
  284. package/package.json +33 -0
  285. package/src/constants/constants.ts +12 -0
  286. package/src/constants/platform.ts +15 -0
  287. package/src/constants/pseudos.ts +14 -0
  288. package/src/constants/rnw.tsx +20 -0
  289. package/src/createComponent.tsx +596 -0
  290. package/src/createFont.ts +26 -0
  291. package/src/createShorthands.ts +5 -0
  292. package/src/createTamagui.ts +207 -0
  293. package/src/createTheme.ts +19 -0
  294. package/src/createTokens.ts +83 -0
  295. package/src/createVariable.ts +22 -0
  296. package/src/helpers/addStylesUsingClassname.tsx +60 -0
  297. package/src/helpers/createMediaStyle.ts +46 -0
  298. package/src/helpers/createPropMapper.ts +184 -0
  299. package/src/helpers/createTamaguiProvider.tsx +22 -0
  300. package/src/helpers/extendStaticConfig.ts +68 -0
  301. package/src/helpers/fixNativeShadow.native.tsx +27 -0
  302. package/src/helpers/fixNativeShadow.tsx +2 -0
  303. package/src/helpers/getSplitStyles.tsx +210 -0
  304. package/src/helpers/getStylesAtomic.native.ts +3 -0
  305. package/src/helpers/getStylesAtomic.ts +103 -0
  306. package/src/helpers/insertStyleRule.tsx +18 -0
  307. package/src/helpers/isObj.ts +1 -0
  308. package/src/helpers/matchMedia.native.ts +3 -0
  309. package/src/helpers/matchMedia.ts +9 -0
  310. package/src/helpers/themeable.tsx +42 -0
  311. package/src/hooks/useConstant.tsx +10 -0
  312. package/src/hooks/useFeatures.tsx +78 -0
  313. package/src/hooks/useForceUpdate.tsx +26 -0
  314. package/src/hooks/useMedia.tsx +194 -0
  315. package/src/hooks/usePressable.tsx +9 -0
  316. package/src/hooks/useTheme.tsx +107 -0
  317. package/src/index.ts +33 -0
  318. package/src/static/postProcessStyles.tsx +20 -0
  319. package/src/static.ts +22 -0
  320. package/src/styled.ts +82 -0
  321. package/src/types.tsx +561 -0
  322. package/src/views/Animated.tsx +121 -0
  323. package/src/views/SafeAreaProvider.tsx +33 -0
  324. package/src/views/Stack.tsx +21 -0
  325. package/src/views/Text.tsx +66 -0
  326. package/src/views/TextAncestorContext.tsx +12 -0
  327. package/src/views/Theme.tsx +73 -0
  328. package/src/views/ThemeContext.tsx +5 -0
  329. package/src/views/ThemeInverse.tsx +23 -0
  330. package/src/views/ThemeManagerContext.tsx +50 -0
  331. package/src/views/ThemeProvider.tsx +52 -0
  332. package/tsconfig.json +8 -0
  333. package/types.d.ts +558 -0
@@ -0,0 +1,20 @@
1
+ const interopRequire = (src: any) => ('default' in src ? src.default : src)
2
+
3
+ export const rnw: Record<string, any> = {}
4
+
5
+ // in static mode, require them directly since we can't import react-native-web at all (it has flow stuff in it)
6
+ if (process.env.IS_STATIC === 'is_static') {
7
+ const createCompileableStyle = require('react-native-web/dist/cjs/exports/StyleSheet/createCompileableStyle')
8
+ const createReactDOMStyle = require('react-native-web/dist/cjs/exports/StyleSheet/createReactDOMStyle')
9
+ const i18Style = require('react-native-web/dist/cjs/exports/StyleSheet/i18nStyle')
10
+ const atomic = require('react-native-web/dist/cjs/exports/StyleSheet/compile').atomic
11
+ Object.assign(rnw, {
12
+ createCompileableStyle,
13
+ createReactDOMStyle,
14
+ i18Style,
15
+ atomic,
16
+ })
17
+ } else if (process.env.TAMAGUI_TARGET === 'web') {
18
+ // when targeting web (client) import it like so
19
+ Object.assign(rnw, interopRequire(require('react-native-web').TamaguiExports))
20
+ }
@@ -0,0 +1,596 @@
1
+ import { concatClassName, stylePropsView } from '@tamagui/helpers'
2
+ import React, {
3
+ Children,
4
+ Fragment,
5
+ createElement,
6
+ forwardRef,
7
+ useCallback,
8
+ useContext,
9
+ useEffect,
10
+ useRef,
11
+ useState,
12
+ } from 'react'
13
+ import { StyleSheet, Text, View, ViewStyle } from 'react-native'
14
+
15
+ import { stackDefaultStyles } from './constants/constants'
16
+ import { isTouchDevice, isWeb } from './constants/platform'
17
+ import { rnw } from './constants/rnw'
18
+ import { onConfiguredOnce } from './createTamagui'
19
+ import { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStylesUsingClassname'
20
+ import { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'
21
+ import { getSplitStyles } from './helpers/getSplitStyles'
22
+ import { useFeatures } from './hooks/useFeatures'
23
+ import { useForceUpdate } from './hooks/useForceUpdate'
24
+ import { usePressable } from './hooks/usePressable'
25
+ import {
26
+ SpaceTokens,
27
+ StaticComponent,
28
+ StaticConfig,
29
+ StaticConfigParsed,
30
+ TamaguiInternalConfig,
31
+ } from './types'
32
+ import { TextAncestorContext } from './views/TextAncestorContext'
33
+ import { ThemeManagerContext } from './views/ThemeManagerContext'
34
+
35
+ export const mouseUps = new Set<Function>()
36
+
37
+ if (typeof document !== 'undefined') {
38
+ document.addEventListener('mouseup', () => {
39
+ mouseUps.forEach((x) => x())
40
+ mouseUps.clear()
41
+ })
42
+ }
43
+
44
+ type DefaultProps = {}
45
+
46
+ export function createComponent<A extends Object = DefaultProps>(
47
+ configIn: Partial<StaticConfig> | StaticConfigParsed
48
+ ) {
49
+ let staticConfig: StaticConfigParsed
50
+ if ('parsed' in configIn) {
51
+ staticConfig = configIn
52
+ } else {
53
+ staticConfig = parseStaticConfig(configIn)
54
+ }
55
+
56
+ const { Component, validStyles, isText, isZStack } = staticConfig
57
+ const validStyleProps = validStyles ?? stylePropsView
58
+
59
+ // split out default styles vs props so we can assign it to component.defaultProps
60
+ let defaultProps = null as any
61
+ let tamaguiConfig: TamaguiInternalConfig
62
+
63
+ // web uses className, native uses style
64
+ let defaultsStyle: any
65
+ let defaultsClassName = ''
66
+ let initialTheme: any
67
+
68
+ // see onConfiguredOnce below which attaches a name then to this component
69
+
70
+ const component = forwardRef<View, A>((props: any, forwardedRef) => {
71
+ const {
72
+ tag,
73
+ hitSlop,
74
+ children,
75
+ pointerEvents,
76
+ onPress,
77
+ onPressIn,
78
+ onPressOut,
79
+ onHoverIn,
80
+ onHoverOut,
81
+ space,
82
+ disabled,
83
+ onMouseEnter,
84
+ onMouseLeave,
85
+ hrefAttrs,
86
+ onMoveShouldSetResponder,
87
+ onMoveShouldSetResponderCapture,
88
+ onResponderEnd,
89
+ onResponderGrant,
90
+ onResponderMove,
91
+ onResponderReject,
92
+ onResponderRelease,
93
+ onResponderStart,
94
+ onResponderTerminate,
95
+ onResponderTerminationRequest,
96
+ onScrollShouldSetResponder,
97
+ onScrollShouldSetResponderCapture,
98
+ onSelectionChangeShouldSetResponder,
99
+ onSelectionChangeShouldSetResponderCapture,
100
+ onStartShouldSetResponder,
101
+ onStartShouldSetResponderCapture,
102
+ onMouseDown,
103
+ onClick,
104
+ // TODO feature load layou hook
105
+ onLayout,
106
+ } = props
107
+
108
+ const forceUpdate = useForceUpdate()
109
+ const features = useFeatures(props, { forceUpdate })
110
+ const manager = useContext(ThemeManagerContext)
111
+ const [state, set_] = useState(() => ({
112
+ hover: false,
113
+ press: false,
114
+ pressIn: false,
115
+ theme: manager.name,
116
+ }))
117
+ const set = (next: Partial<typeof state>) =>
118
+ set_((prev) => {
119
+ for (const key in next) {
120
+ if (prev[key] !== next[key]) {
121
+ return { ...prev, ...next }
122
+ }
123
+ }
124
+ return prev
125
+ })
126
+
127
+ // from react-native-web
128
+ if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
129
+ Children.toArray(props.children).forEach((item) => {
130
+ if (typeof item === 'string') {
131
+ console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)
132
+ }
133
+ })
134
+ }
135
+
136
+ const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false
137
+ const hostRef = useRef(null)
138
+
139
+ if (isWeb) {
140
+ // from react-native-web
141
+ rnw.useResponderEvents(hostRef, {
142
+ onMoveShouldSetResponder,
143
+ onMoveShouldSetResponderCapture,
144
+ onResponderEnd,
145
+ onResponderGrant,
146
+ onResponderMove,
147
+ onResponderReject,
148
+ onResponderRelease,
149
+ onResponderStart,
150
+ onResponderTerminate,
151
+ onResponderTerminationRequest,
152
+ onScrollShouldSetResponder,
153
+ onScrollShouldSetResponderCapture,
154
+ onSelectionChangeShouldSetResponder,
155
+ onSelectionChangeShouldSetResponderCapture,
156
+ onStartShouldSetResponder,
157
+ onStartShouldSetResponderCapture,
158
+ })
159
+ }
160
+
161
+ const isTracking = useRef(false)
162
+
163
+ const { viewProps, pseudos, style, classNames } = getSplitStyles(
164
+ props,
165
+ staticConfig,
166
+ (manager.theme as any) || initialTheme
167
+ )
168
+
169
+ // hasEverHadEvents prevents repareting if you remove onPress or similar...
170
+ const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()
171
+ if (!internal.current) {
172
+ internal.current = {
173
+ isMounted: true,
174
+ }
175
+ }
176
+
177
+ useEffect(() => {
178
+ internal.current!.isMounted = true
179
+ const dispose = manager?.onChangeTheme((name) => {
180
+ if (isTracking.current) {
181
+ set({ theme: name })
182
+ }
183
+ })
184
+ return () => {
185
+ dispose()
186
+ mouseUps.delete(unPress)
187
+ isTracking.current = false
188
+ internal.current!.isMounted = false
189
+ }
190
+ }, [manager])
191
+
192
+ // element
193
+ const element = isWeb
194
+ ? !Component || typeof Component === 'string'
195
+ ? // default to tag, fallback to component (when both strings)
196
+ tag || Component
197
+ : Component
198
+ : Component
199
+ const ReactView = !isWeb ? View : element || (hasTextAncestor ? 'span' : 'div')
200
+ const ReactText = !isWeb ? Text : element || 'span'
201
+ const ViewComponent = isText ? ReactText : ReactView
202
+
203
+ // styles
204
+ const isHovering = !isTouchDevice && !disabled && pseudos && state.hover
205
+ const isPressing = !disabled && pseudos && state.press
206
+
207
+ const styles = [
208
+ // parity w react-native-web, only for text in text
209
+ // TODO this should be able to be done w css to replicate after extraction:
210
+ // (.text .text { display: inline-flex; }) (but if they set display we'd need stronger precendence)
211
+ // isText && hasTextAncestor && isWeb ? { display: 'inline-flex' } : null,
212
+ style,
213
+ isHovering ? pseudos.hoverStyle || null : null,
214
+ isPressing ? pseudos.pressStyle || null : null,
215
+ ]
216
+
217
+ if (isWeb) {
218
+ const stylesClassNames = useStylesAsClassname(styles)
219
+ const classList = isText
220
+ ? [
221
+ defaultsClassName,
222
+ // hasTextAncestor === true && cssText.textHasAncestor,
223
+ // TODO MOVE TO VARIANTS [number] [any]
224
+ // numberOfLines != null && numberOfLines > 1 && cssText.textMultiLine,
225
+ classNames,
226
+ stylesClassNames,
227
+ props.className,
228
+ ]
229
+ : [defaultsClassName, props.className, classNames, stylesClassNames]
230
+
231
+ const className = concatClassName(...classList)
232
+ if (process.env.NODE_ENV === 'development') {
233
+ if (props['debug']) {
234
+ // prettier-ignore
235
+ console.log('🥚 className', { style, styles, classList, stylesClassNames, className })
236
+ }
237
+ }
238
+ viewProps.className = className
239
+ } else {
240
+ viewProps.style = styles
241
+ }
242
+
243
+ if (pointerEvents) {
244
+ viewProps.pointerEvents = pointerEvents
245
+ }
246
+
247
+ if (isWeb) {
248
+ // from react-native-web
249
+ const platformMethodsRef = rnw.usePlatformMethods(viewProps)
250
+ const setRef = rnw.useMergeRefs(hostRef, platformMethodsRef, forwardedRef)
251
+ viewProps.ref = setRef
252
+ if (props.href != null && hrefAttrs != null) {
253
+ const { download, rel, target } = hrefAttrs
254
+ if (download != null) {
255
+ viewProps.download = download
256
+ }
257
+ if (rel != null) {
258
+ viewProps.rel = rel
259
+ }
260
+ if (typeof target === 'string') {
261
+ viewProps.target = target.charAt(0) !== '_' ? '_' + target : target
262
+ }
263
+ }
264
+ } else {
265
+ if (forwardedRef) {
266
+ viewProps.ref = forwardedRef
267
+ }
268
+ }
269
+
270
+ const attachPress = !!(
271
+ (pseudos && pseudos.pressStyle) ||
272
+ onPress ||
273
+ onPressOut ||
274
+ onPressIn ||
275
+ onClick
276
+ )
277
+ const attachHover =
278
+ isWeb &&
279
+ !isTouchDevice &&
280
+ !!((pseudos && pseudos.hoverStyle) || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)
281
+
282
+ // check presence to prevent reparenting bugs, allows for onPress={x ? function : undefined} usage
283
+ // while avoiding reparenting...
284
+ // once proper reparenting is supported, we can remove this and use that...
285
+ const shouldAttach =
286
+ internal.current.hasEverHadEvents ||
287
+ attachPress ||
288
+ attachHover ||
289
+ 'pressStyle' in props ||
290
+ 'onPress' in props ||
291
+ 'onPressIn' in props ||
292
+ 'onPressOut' in props ||
293
+ (isWeb &&
294
+ ('hoverStyle' in props ||
295
+ 'onClick' in props ||
296
+ 'onHoverIn' in props ||
297
+ 'onHoverOut' in props ||
298
+ 'onMouseEnter' in props ||
299
+ 'onMouseLeave' in props))
300
+
301
+ // never remove events as we wrap in a div (for now, may be able to remove..)
302
+ if (shouldAttach) {
303
+ internal.current.hasEverHadEvents = true
304
+ }
305
+
306
+ const unPress = useCallback(() => {
307
+ if (!internal.current!.isMounted) return
308
+ set({
309
+ press: false,
310
+ pressIn: false,
311
+ })
312
+ }, [])
313
+
314
+ const events = shouldAttach
315
+ ? {
316
+ ...(!isWeb && {
317
+ // non web
318
+ onPressOut: (e) => {
319
+ unPress()
320
+ onPressOut?.(e)
321
+ },
322
+ }),
323
+ ...(isWeb &&
324
+ !isTouchDevice && {
325
+ onMouseEnter:
326
+ attachHover || attachPress
327
+ ? (e) => {
328
+ let next: Partial<typeof state> = {}
329
+ if (attachHover) {
330
+ next.hover = true
331
+ }
332
+ if (state.pressIn) {
333
+ next.press = true
334
+ }
335
+ if (Object.keys(next).length) {
336
+ set(next)
337
+ }
338
+ onHoverIn?.(e)
339
+ onMouseEnter?.(e)
340
+ }
341
+ : undefined,
342
+ onMouseLeave:
343
+ attachHover || attachPress
344
+ ? (e) => {
345
+ let next: Partial<typeof state> = {}
346
+ mouseUps.add(unPress)
347
+ if (attachHover) {
348
+ next.hover = false
349
+ }
350
+ if (state.pressIn) {
351
+ next.press = false
352
+ next.pressIn = false
353
+ }
354
+ if (Object.keys(next).length) {
355
+ set(next)
356
+ }
357
+ onHoverOut?.(e)
358
+ onMouseLeave?.(e)
359
+ }
360
+ : undefined,
361
+ }),
362
+ onMouseDown: attachPress
363
+ ? (e) => {
364
+ set({
365
+ press: true,
366
+ pressIn: true,
367
+ })
368
+ onPressIn?.(e)
369
+ onMouseDown?.(e)
370
+ }
371
+ : (onPressIn as any),
372
+ onClick: attachPress
373
+ ? (e) => {
374
+ // this caused issue with next.js passing href
375
+ // e.preventDefault()
376
+ onPress?.(e)
377
+ onClick?.(e)
378
+ unPress()
379
+ onPressOut?.(e)
380
+ }
381
+ : (onPressOut as any),
382
+ }
383
+ : null
384
+
385
+ if (events) {
386
+ if (typeof ViewComponent !== 'string') {
387
+ // TODO once we do the above we can then rely entirely on pressStyle returned here isntead of above pressStyle logic
388
+ const [pressProps] = usePressable({
389
+ disabled,
390
+ hitSlop,
391
+ onPressIn: events.onMouseDown,
392
+ onPressOut: events.onPressOut,
393
+ onPress: events.onClick,
394
+ })
395
+ Object.assign(viewProps, pressProps)
396
+ } else {
397
+ Object.assign(viewProps, events)
398
+ }
399
+ }
400
+
401
+ const childEls = spacedChildren({
402
+ children,
403
+ space,
404
+ flexDirection: props.flexDirection || defaultProps?.flexDirection,
405
+ isZStack: isZStack,
406
+ })
407
+
408
+ let content: any
409
+
410
+ // replicate react-native-web's `createElement`
411
+ if (isWeb && rnw) {
412
+ const domProps = rnw.createDOMProps(viewProps)
413
+ const className =
414
+ domProps.className && domProps.className !== viewProps.className
415
+ ? `${domProps.className} ${viewProps.className}`
416
+ : viewProps.className
417
+ Object.assign(viewProps, domProps)
418
+ viewProps.className = className
419
+ content = createElement(ViewComponent, viewProps, childEls)
420
+ } else {
421
+ content = createElement(ViewComponent, viewProps, childEls)
422
+ }
423
+
424
+ const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor
425
+ if (shouldWrapTextAncestor) {
426
+ // from react-native-web
427
+ // @ts-ignore
428
+ content = createElement(TextAncestorContext.Provider, { value: true }, content)
429
+ }
430
+
431
+ if (process.env.NODE_ENV === 'development') {
432
+ if (props['debug']) {
433
+ viewProps['debug'] = true
434
+ console.log('🥚 props in:', props)
435
+ console.log('🥚 props out:', viewProps)
436
+ console.log(props.onClick?.toString())
437
+ // prettier-ignore
438
+ console.log('🥚 etc:', { shouldAttach, ViewComponent, viewProps, styles, pseudos, content, childEls })
439
+ // only on browser because node expands it huge
440
+ if (isWeb) {
441
+ console.log('🥚 component info', { staticConfig, tamaguiConfig })
442
+ }
443
+ }
444
+ }
445
+
446
+ return (
447
+ <>
448
+ {features}
449
+ {content}
450
+ </>
451
+ )
452
+ })
453
+
454
+ // Once configuration is run and all components are registered
455
+ // get default props + className and analyze styles
456
+ onConfiguredOnce((conf) => {
457
+ tamaguiConfig = conf
458
+ initialTheme = conf.themes[conf.defaultTheme || Object.keys(conf.themes)[0]]
459
+ const next = getSplitStyles(staticConfig.defaultProps, staticConfig, initialTheme, true)
460
+ if (isWeb) {
461
+ if (next.classNames) {
462
+ defaultsClassName += next.classNames + ' '
463
+ }
464
+ defaultsClassName += addStylesUsingClassname([next.style, next.pseudos])
465
+ } else {
466
+ if (!hasWarnedOnce) {
467
+ hasWarnedOnce = true
468
+ console.log('⚠️ we need to account for default styles for media queries')
469
+ }
470
+ }
471
+ // @ts-ignore
472
+ component.defaultProps = {
473
+ ...next.viewProps,
474
+ ...component.defaultProps,
475
+ }
476
+ if (process.env.NODE_ENV === 'development') {
477
+ if (staticConfig.defaultProps?.debug) {
478
+ console.log('tamagui debug component:', next, defaultsClassName, component.defaultProps)
479
+ }
480
+ }
481
+ })
482
+
483
+ component['staticConfig'] = {
484
+ validStyles: validStyleProps,
485
+ ...staticConfig,
486
+ }
487
+
488
+ const res = component as any as StaticComponent<A, void>
489
+
490
+ // add extractable HoC
491
+ res['extractable'] = (Component: any) => {
492
+ Component['staticConfig'] = extendStaticConfig(res, {
493
+ neverFlatten: true,
494
+ defaultProps: Component.defaultProps,
495
+ })
496
+ return Component
497
+ }
498
+
499
+ return res
500
+ }
501
+
502
+ let hasWarnedOnce = false
503
+
504
+ // dont used styled() here to avoid circular deps
505
+ // keep inline to avoid circular deps
506
+
507
+ export const Spacer = createComponent<{ size?: number | SpaceTokens; flex?: boolean | number }>({
508
+ defaultProps: {
509
+ ...stackDefaultStyles,
510
+ size: true,
511
+ },
512
+ variants: {
513
+ size: {
514
+ '...size': (size, { tokens }) => {
515
+ size = size == true ? '$true' : size
516
+ return {
517
+ width: tokens.size[size] ?? size,
518
+ height: tokens.size[size] ?? size,
519
+ }
520
+ },
521
+ },
522
+
523
+ direction: {
524
+ horizontal: {
525
+ height: 0,
526
+ },
527
+ vertical: {
528
+ width: 0,
529
+ },
530
+ },
531
+ },
532
+ })
533
+
534
+ export function spacedChildren({
535
+ isZStack,
536
+ children,
537
+ space,
538
+ flexDirection,
539
+ }: {
540
+ isZStack?: boolean
541
+ children: any
542
+ space?: any
543
+ flexDirection?: ViewStyle['flexDirection']
544
+ }) {
545
+ if (!space && !isZStack) {
546
+ return children
547
+ }
548
+ const childrenList = Children.toArray(children)
549
+ const len = childrenList.length
550
+ if (len === 1) {
551
+ return children
552
+ }
553
+ const next: any[] = []
554
+ for (const [index, child] of childrenList.entries()) {
555
+ if (child === null || child === undefined) {
556
+ continue
557
+ }
558
+
559
+ const key = `${child?.['key'] ?? index}`
560
+
561
+ next.push(<Fragment key={key}>{isZStack ? <Absolute>{child}</Absolute> : child}</Fragment>)
562
+
563
+ // allows for custom visually hidden components that dont insert spacing
564
+ if (child?.['type']?.['isVisuallyHidden']) {
565
+ continue
566
+ }
567
+
568
+ if (index !== len - 1) {
569
+ if (space) {
570
+ next.push(
571
+ <Spacer
572
+ key={`${key}_spacer`}
573
+ // @ts-ignore TODO
574
+ direction={
575
+ flexDirection === 'row' || flexDirection === 'row-reverse' ? 'horizontal' : 'vertical'
576
+ }
577
+ size={space}
578
+ />
579
+ )
580
+ }
581
+ }
582
+ }
583
+ return next
584
+ }
585
+
586
+ // for now not so "tamagui-y"
587
+ const Absolute = ({ children }) => <View style={sheet.fullscreen}>{children}</View>
588
+ const sheet = StyleSheet.create({
589
+ fullscreen: {
590
+ position: 'absolute',
591
+ top: 0,
592
+ left: 0,
593
+ right: 0,
594
+ bottom: 0,
595
+ },
596
+ })
@@ -0,0 +1,26 @@
1
+ import { GenericFont } from './types'
2
+
3
+ export const createFont = <A extends GenericFont>(font: A): A => {
4
+ // fills in any missing values based on size keys being standard
5
+ const sizeKeys = Object.keys(font.size)
6
+
7
+ for (const key in font) {
8
+ if (key === 'size' || key === 'family') continue
9
+ const section = font[key]
10
+ const keys = Object.keys(section)
11
+
12
+ // fill with first filled in value to start
13
+ let fillVal = section[keys[0]]
14
+
15
+ for (const sKey of sizeKeys) {
16
+ if (!(sKey in section)) {
17
+ section[sKey] = fillVal
18
+ } else {
19
+ // if exists, set as the fillVal
20
+ fillVal = section[sKey]
21
+ }
22
+ }
23
+ }
24
+
25
+ return Object.freeze(font)
26
+ }
@@ -0,0 +1,5 @@
1
+ // type helper
2
+
3
+ export function createShorthands<A extends Record<string, string>>(shorthands: A): A {
4
+ return Object.freeze(shorthands) as any
5
+ }