@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,207 @@
1
+ import { getStyleRules } from '@tamagui/helpers'
2
+
3
+ import { Variable, createVariable, isVariable } from './createVariable'
4
+ import { createTamaguiProvider } from './helpers/createTamaguiProvider'
5
+ import { configureMedia } from './hooks/useMedia'
6
+ import {
7
+ CreateTamaguiConfig,
8
+ GenericTamaguiConfig,
9
+ MediaQueryKey,
10
+ TamaguiInternalConfig,
11
+ TamaguiProviderProps,
12
+ } from './types'
13
+
14
+ export type CreateTamaguiProps = TamaguiProviderProps &
15
+ // we omit and re-declare it because we need to allow instantation types to be flexible
16
+ // user then re-defines the types after createTamagui returns the typed object they want
17
+ Omit<GenericTamaguiConfig, 'themes'> & {
18
+ themes: {
19
+ [key: string]: {
20
+ [key: string]: string | number | Variable
21
+ }
22
+ }
23
+ // for ssr/native, will default to active
24
+ mediaQueryDefaultActive?: MediaQueryKey[]
25
+ }
26
+
27
+ let conf: TamaguiInternalConfig | null
28
+
29
+ export const getHasConfigured = () => !!conf
30
+ export const getTamaguiConfig = () => conf!
31
+
32
+ type ConfigListener = (conf: TamaguiInternalConfig) => void
33
+ const configListeners = new Set<ConfigListener>()
34
+ export const onConfiguredOnce = (cb: ConfigListener) => {
35
+ if (conf) {
36
+ cb(conf)
37
+ } else {
38
+ configListeners.add(cb)
39
+ }
40
+ }
41
+
42
+ const PREFIX = `theme--`
43
+
44
+ export function createTamagui<Conf extends CreateTamaguiProps>(
45
+ config: Conf
46
+ ): Conf extends CreateTamaguiConfig<infer A, infer B, infer C, infer D>
47
+ ? TamaguiInternalConfig<A, B, C, D>
48
+ : unknown {
49
+ // test env loads a few times as it runs diff tests
50
+ if (conf) {
51
+ console.warn('Called createTamagui twice! Should never do so')
52
+ // throw new Error(`#000 createTamagui called twice`)
53
+ }
54
+
55
+ configureMedia({
56
+ queries: config.media as any,
57
+ defaultActive: config.mediaQueryDefaultActive,
58
+ })
59
+
60
+ // TODO can avoid some of this CSS creation on native
61
+ const themeConfig = (() => {
62
+ let cssRules: string[] = []
63
+
64
+ // tokens
65
+ let tokenRule = `:root {`
66
+ const varsByValue = new Map<string, Variable>()
67
+ const addVar = (v: Variable) => {
68
+ varsByValue[v.val] = v
69
+ const rule = `--${v.name}:${typeof v.val === 'number' ? `${v.val}px` : v.val};`
70
+ tokenRule += rule
71
+ }
72
+
73
+ for (const key in config.tokens) {
74
+ for (const skey in config.tokens[key]) {
75
+ const val = config.tokens[key][skey]
76
+ if (key === 'font') {
77
+ for (const fkey in val) {
78
+ if (fkey === 'family') {
79
+ addVar(val[fkey])
80
+ } else {
81
+ for (const fskey in val[fkey]) {
82
+ addVar(val[fkey][fskey])
83
+ }
84
+ }
85
+ }
86
+ } else {
87
+ addVar(val)
88
+ }
89
+ }
90
+ }
91
+ cssRules.push(`${tokenRule}\n}`)
92
+
93
+ // themes
94
+ for (const themeName in config.themes) {
95
+ // to allow using the same theme with diff names, be sure we don't mutate!
96
+ config.themes[themeName] = { ...config.themes[themeName] }
97
+ const theme = config.themes[themeName]
98
+ let vars = ''
99
+ for (const themeKey in theme) {
100
+ const val = theme[themeKey]
101
+ const getVariableCSS = (inv: any) => {
102
+ const v = varsByValue[inv] ?? inv
103
+ return isVariable(v) ? `--${themeKey}:var(--${v.name});` : `--${themeKey}:${v};`
104
+ }
105
+ vars += getVariableCSS(val)
106
+ // TODO sanity check is necessary
107
+ // make everything a variable that gets put into css
108
+ if (!isVariable(val)) {
109
+ theme[themeKey] = createVariable({
110
+ name: themeKey,
111
+ val,
112
+ })
113
+ }
114
+ }
115
+
116
+ const [themeClassName, parentName] = themeName.includes('-')
117
+ ? themeName.split('-')
118
+ : [themeName, '']
119
+ // tiny hack for now assuming light/dark are typical parentName
120
+ const oppositeName = parentName === 'dark' ? 'light' : 'dark'
121
+ const cssParentSel = parentName ? `.${PREFIX}${parentName}` : ''
122
+ const cssChildSel = `.${PREFIX}${themeClassName}`
123
+ const cssSel = `${cssParentSel} ${cssChildSel}`
124
+ // we need to force specificity
125
+ const cssRule = `${cssSel}, .${PREFIX}${oppositeName} ${cssSel} {\n${vars}\n}`
126
+ cssRules.push(cssRule)
127
+ }
128
+
129
+ Object.freeze(cssRules)
130
+
131
+ return {
132
+ cssRules,
133
+ css: cssRules.join('\n'),
134
+ }
135
+ })()
136
+
137
+ // faster lookups token keys become $keys to match input
138
+ const tokensParsed: any = parseTokens(config.tokens)
139
+ // all themes should match key and we just need variable name
140
+ // TODO once w react native we'd want to have a reverse lookup back to value
141
+ const themeParsed: any = {}
142
+ const firstKey = Object.keys(config.themes)[0]
143
+ for (const key in config.themes[firstKey]) {
144
+ // themeParsed[`$${key}`] = config.themes[firstKey][key]
145
+ const val = config.themes[firstKey][key].val
146
+ themeParsed[`$${key}`] = new Variable({ val, name: key })
147
+ }
148
+
149
+ const next: TamaguiInternalConfig = {
150
+ // @ts-ignore
151
+ shorthands: {},
152
+ ...config,
153
+ Provider: createTamaguiProvider({
154
+ defaultTheme: 'light',
155
+ ...config,
156
+ }),
157
+ themeConfig,
158
+ themeParsed,
159
+ tokensParsed,
160
+ getCSS() {
161
+ return `${themeConfig.css}\n${[...getStyleRules()].join('\n')}`
162
+ },
163
+ }
164
+ conf = next
165
+
166
+ if (configListeners.size) {
167
+ configListeners.forEach((cb) => cb(next))
168
+ configListeners.clear()
169
+ }
170
+
171
+ // @ts-expect-error
172
+ return next
173
+ }
174
+
175
+ export function getThemeParentClassName(themeName?: string | null) {
176
+ return `theme-parent ${themeName ? `${PREFIX}${themeName}` : ''}`
177
+ }
178
+
179
+ const parseTokens = (tokens: any) => {
180
+ const res: any = {}
181
+ for (const key in tokens) {
182
+ res[key] = {}
183
+ if (key === 'font') {
184
+ for (const family in tokens.font) {
185
+ const obj = {}
186
+ res.font[`$${family}`] = obj
187
+ for (const attrKey in tokens.font[family]) {
188
+ const attr = tokens.font[family][attrKey]
189
+ if (attrKey === 'family') {
190
+ obj[attrKey] = attr
191
+ continue
192
+ }
193
+ obj[attrKey] = Object.keys(attr).reduce((acc, cur) => {
194
+ acc[`$${cur}`] = attr[cur]
195
+ return acc
196
+ }, {})
197
+ }
198
+ }
199
+ continue
200
+ }
201
+ for (const skey in tokens[key]) {
202
+ res[key][`$${skey}`] = tokens[key][skey]
203
+ }
204
+ }
205
+
206
+ return res
207
+ }
@@ -0,0 +1,19 @@
1
+ import { Variable, createVariable } from './createVariable'
2
+
3
+ export const createTheme = <Theme extends { [key: string]: string | Variable }>(
4
+ theme: Theme
5
+ ): {
6
+ [key in keyof Theme]: Variable
7
+ } => {
8
+ const res = {} as any
9
+ for (const key in theme) {
10
+ const val = theme[key]
11
+ if (!(val instanceof Variable)) {
12
+ res[key] = createVariable({
13
+ name: key,
14
+ val,
15
+ })
16
+ }
17
+ }
18
+ return res
19
+ }
@@ -0,0 +1,83 @@
1
+ import { Variable, createVariable } from './createVariable'
2
+ import { CreateTokens } from './types'
3
+
4
+ // tokens.color.dark.red ===>{ var: `color-dark-red`, val: '' }
5
+
6
+ export function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {
7
+ return setupTokens(tokens) as any
8
+ }
9
+
10
+ function setupTokens(tokens: any) {
11
+ return mapTokensToVariables(tokens)
12
+ }
13
+
14
+ export const mapTokensToVariables = (
15
+ tokens: CreateTokens,
16
+ parentPath = ''
17
+ ): CreateTokens<Variable> => {
18
+ const res = {}
19
+ for (const key in tokens) {
20
+ const val = tokens[key]
21
+ const name = parentPath ? `${parentPath}-${key}` : key
22
+ if (val && typeof val === 'object') {
23
+ res[key] = mapTokensToVariables(tokens[key], name)
24
+ } else {
25
+ res[key] = createVariable({ val, name })
26
+ }
27
+ }
28
+ // @ts-expect-error
29
+ return res
30
+ }
31
+
32
+ // verbose but gives us nice types...
33
+ type MakeTokens<T> = T extends {
34
+ font: {
35
+ [key in infer A]: {
36
+ size: infer B
37
+ lineHeight: infer C
38
+ letterSpacing: infer D
39
+ weight: infer Z
40
+ family: infer Y
41
+ }
42
+ }
43
+ color: infer E
44
+ space: infer F
45
+ size: infer G
46
+ radius: infer H
47
+ zIndex: infer J
48
+ }
49
+ ? {
50
+ font: {
51
+ [key in A]: {
52
+ size: {
53
+ [key in keyof B]: Variable
54
+ }
55
+ lineHeight: {
56
+ [key in keyof C]: Variable
57
+ }
58
+ letterSpacing: {
59
+ [key in keyof D]: Variable
60
+ }
61
+ weight: {
62
+ [key in keyof Z]: Variable
63
+ }
64
+ family: Y
65
+ }
66
+ }
67
+ color: {
68
+ [key in keyof E]: Variable
69
+ }
70
+ space: {
71
+ [key in keyof F]: Variable
72
+ }
73
+ size: {
74
+ [key in keyof G]: Variable
75
+ }
76
+ radius: {
77
+ [key in keyof H]: Variable
78
+ }
79
+ zIndex: {
80
+ [key in keyof J]: Variable
81
+ }
82
+ }
83
+ : never
@@ -0,0 +1,22 @@
1
+ import { isWeb } from './constants/platform'
2
+
3
+ export class Variable {
4
+ name: string
5
+ val: string | number
6
+ variable: string | number
7
+
8
+ constructor({ val, name }: VariableIn) {
9
+ // converting to px breaks rn
10
+ this.val = val //typeof val === 'string' ? val : `${val}px`
11
+ this.name = name
12
+ this.variable = isWeb ? `var(--${name})` : this.val
13
+ }
14
+ }
15
+
16
+ type VariableIn = { val: string | number; name: string }
17
+
18
+ export const createVariable = (props: VariableIn) => new Variable(props)
19
+
20
+ export function isVariable(v: Variable | any): v is Variable {
21
+ return v instanceof Variable
22
+ }
@@ -0,0 +1,60 @@
1
+ // @ts-ignore
2
+ import { useInsertionEffect } from 'react'
3
+
4
+ import { getStylesAtomic } from './getStylesAtomic'
5
+ import { insertStyleRule } from './insertStyleRule'
6
+
7
+ // uses new useInsertionEffect for better perf if available
8
+
9
+ // could be cleared occasionally
10
+ let added = new Set<string>()
11
+
12
+ export function useStylesAsClassname(styles: any[]) {
13
+ if (!useInsertionEffect) {
14
+ return addStylesUsingClassname(styles)
15
+ } else {
16
+ const insertions: any[] = []
17
+ const className = addStylesUsingClassname(styles, (_, rules) => {
18
+ for (const rule of rules) {
19
+ insertions.push(rule)
20
+ }
21
+ })
22
+
23
+ useInsertionEffect(() => {
24
+ for (const ruleset of insertions) {
25
+ insertStyleRule(ruleset)
26
+ }
27
+ })
28
+
29
+ return className
30
+ }
31
+ }
32
+
33
+ export function addStylesUsingClassname(
34
+ styles: any[],
35
+ onAdd?: (identifier: string, rules: string[]) => any
36
+ ) {
37
+ let className = ''
38
+ for (const style of styles) {
39
+ if (!style) continue
40
+ if (Array.isArray(style)) {
41
+ className += ' ' + addStylesUsingClassname(style)
42
+ continue
43
+ }
44
+ for (const { identifier, rules } of getStylesAtomic(style)) {
45
+ className += ` ${identifier}`
46
+ if (added.has(identifier)) {
47
+ continue
48
+ }
49
+ added.add(identifier)
50
+ if (onAdd) {
51
+ onAdd(identifier, rules)
52
+ } else {
53
+ for (const rule of rules) {
54
+ insertStyleRule(rule)
55
+ }
56
+ }
57
+ }
58
+ }
59
+ return className
60
+ }
@@ -0,0 +1,46 @@
1
+ import { StyleObject } from '@tamagui/helpers'
2
+
3
+ import { mediaObjectToString } from '../hooks/useMedia'
4
+ import { MediaQueries } from '../types'
5
+
6
+ // TODO have this be used by extractMediaStyle in tamagui static
7
+
8
+ // not synced to static/constants for now
9
+ export const MEDIA_SEP = '_'
10
+
11
+ export const createMediaStyle = (
12
+ { identifier, rules }: StyleObject,
13
+ mediaKey: string,
14
+ mediaQueries: MediaQueries,
15
+ negate?: boolean,
16
+ importance = 0
17
+ ) => {
18
+ const mediaKeys = Object.keys(mediaQueries)
19
+ const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
20
+ acc[cur] = new Array(importance + 1).fill(':root').join('')
21
+ return acc
22
+ }, {})
23
+ const negKey = negate ? '0' : ''
24
+ const ogPrefix = identifier.slice(0, identifier.indexOf('-') + 1)
25
+ const nextIdentifier = `${identifier.replace(
26
+ ogPrefix,
27
+ `${ogPrefix}${MEDIA_SEP}${mediaKey}${negKey}${MEDIA_SEP}`
28
+ )}`
29
+ const screenStr = negate ? 'not all' : 'screen'
30
+ const mediaSelector = mediaObjectToString(mediaQueries[mediaKey])
31
+ const mediaQuery = `${screenStr} and ${mediaSelector}`
32
+ const precendencePrefix = mediaKeyPrecendence[mediaKey]
33
+ const styleInner = rules[0].replace(identifier, nextIdentifier)
34
+ // combines media queries if they already exist
35
+ let styleRule = ''
36
+ if (styleInner.includes('@media')) {
37
+ // combine
38
+ styleRule = styleInner.replace('{', ` and ${mediaQuery} {`)
39
+ } else {
40
+ styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`
41
+ }
42
+ return {
43
+ styleRule,
44
+ identifier: nextIdentifier,
45
+ }
46
+ }
@@ -0,0 +1,184 @@
1
+ import { getTamaguiConfig } from '../createTamagui'
2
+ import { Variable } from '../createVariable'
3
+ import { StaticConfig, TamaguiInternalConfig } from '../types'
4
+ import { isObj } from './isObj'
5
+
6
+ export const createPropMapper = (c: StaticConfig) => {
7
+ const variants = c.variants
8
+ let variantsParsed
9
+ const defaultProps = c.defaultProps || {}
10
+
11
+ return (key: string, value: any, theme: any, props: any) => {
12
+ const conf = getTamaguiConfig()
13
+ if (!conf) {
14
+ console.trace('no conf! err')
15
+ return
16
+ }
17
+ if (variants && !variantsParsed) {
18
+ variantsParsed = parseVariants(variants, conf)
19
+ }
20
+
21
+ // handled here because we need to resolve this off tokens, its the only one-off like this
22
+ let fontFamily = props.fontFamily || defaultProps.fontFamily || '$body'
23
+
24
+ // expand variants
25
+ const variant = variantsParsed?.[key]
26
+ if (variant && typeof value !== 'undefined') {
27
+ const val =
28
+ value === true
29
+ ? variant['$true'] || variant['true']
30
+ : variant[value] ?? variant['...'] ?? value
31
+
32
+ const res =
33
+ typeof val === 'function'
34
+ ? val(value, { tokens: conf.tokensParsed, theme, props })
35
+ : isObj(val)
36
+ ? { ...val }
37
+ : val
38
+
39
+ if (isObj(res)) {
40
+ resolveTokens(res, conf, fontFamily)
41
+ }
42
+
43
+ return res
44
+ }
45
+
46
+ let shouldReturn = false
47
+
48
+ // handle shorthands
49
+ if (conf.shorthands[key]) {
50
+ shouldReturn = true
51
+ key = conf.shorthands[key]
52
+ }
53
+
54
+ if (value && value[0] === '$') {
55
+ shouldReturn = true
56
+ value = getToken(key, value, conf, fontFamily)
57
+ }
58
+
59
+ if (value instanceof Variable) {
60
+ shouldReturn = true
61
+ value = value.variable
62
+ }
63
+
64
+ if (shouldReturn) {
65
+ return {
66
+ [key]: value,
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ const resolveTokens = (res: any, conf: TamaguiInternalConfig, fontFamily: any) => {
73
+ for (const rKey in res) {
74
+ const fKey = conf.shorthands[rKey] || rKey
75
+ const val = res[rKey]
76
+ if (val instanceof Variable) {
77
+ res[fKey] = val.variable
78
+ } else if (typeof val === 'string') {
79
+ const fVal = val[0] === '$' ? getToken(fKey, val, conf, fontFamily) : val
80
+ res[fKey] = fVal
81
+ } else {
82
+ if (isObj(val)) {
83
+ // for things like shadowOffset which is a sub-object
84
+ resolveTokens(val, conf, fontFamily)
85
+ }
86
+ // nullish values cant be tokens so need no exrta parsing
87
+ }
88
+ }
89
+ }
90
+
91
+ const getToken = (
92
+ key: string,
93
+ value: string,
94
+ { tokensParsed, themeParsed }: TamaguiInternalConfig,
95
+ fontFamily: string | undefined = '$body'
96
+ ) => {
97
+ if (themeParsed[value]) {
98
+ return themeParsed[value].variable
99
+ }
100
+ let valOrVar: any
101
+ if (key === 'fontFamily') {
102
+ valOrVar = tokensParsed.font[value]?.family || value
103
+ }
104
+ if (key === 'fontSize') {
105
+ valOrVar = tokensParsed.font[fontFamily]?.size[value] || value
106
+ }
107
+ if (key === 'lineHeight') {
108
+ valOrVar = tokensParsed.font[fontFamily]?.lineHeight[value] || value
109
+ }
110
+ if (key === 'letterSpacing') {
111
+ valOrVar = tokensParsed.font[fontFamily]?.letterSpacing[value] || value
112
+ }
113
+ if (key === 'fontWeight') {
114
+ valOrVar = tokensParsed.font[fontFamily]?.weight[value] || value
115
+ }
116
+ if (typeof valOrVar !== 'undefined') {
117
+ if (valOrVar instanceof Variable) {
118
+ return valOrVar.variable
119
+ } else {
120
+ return valOrVar
121
+ }
122
+ }
123
+ for (const cat in tokenCategories) {
124
+ if (tokenCategories[cat][key]) {
125
+ const res = tokensParsed[cat][value]
126
+ if (res) {
127
+ return res.variable
128
+ } else {
129
+ const themeVar = themeParsed[value]
130
+ if (themeVar) {
131
+ return themeVar.variable
132
+ }
133
+ }
134
+ }
135
+ }
136
+ const spaceVar = tokensParsed.space[value]
137
+ if (spaceVar) {
138
+ return spaceVar.variable
139
+ }
140
+ return value
141
+ }
142
+
143
+ // just specificy the least costly, all else go to `space` (most keys - we can exclude)
144
+ const tokenCategories = {
145
+ size: {
146
+ width: true,
147
+ height: true,
148
+ minWidth: true,
149
+ minHeight: true,
150
+ maxWidth: true,
151
+ maxHeight: true,
152
+ },
153
+ color: {
154
+ color: true,
155
+ backgroundColor: true,
156
+ borderColor: true,
157
+ borderBottomColor: true,
158
+ borderTopColor: true,
159
+ borderLeftColor: true,
160
+ borderRightColor: true,
161
+ },
162
+ }
163
+
164
+ // turns variant spreads into individual lookups
165
+ function parseVariants(variants: any, conf: TamaguiInternalConfig) {
166
+ return Object.keys(variants).reduce((acc, key) => {
167
+ acc[key] = Object.keys(variants[key]).reduce((vacc, vkey) => {
168
+ const variantVal = variants[key][vkey]
169
+ if (vkey.startsWith('...')) {
170
+ // set the default one at '...' for easy fallback on non-exact-variant-match
171
+ vacc['...'] = variantVal
172
+ const tokenKey = vkey.slice(3)
173
+ const tokens = conf.tokens[tokenKey]
174
+ for (const tkey in tokens) {
175
+ vacc[`$${tkey}`] = variantVal
176
+ }
177
+ } else {
178
+ vacc[vkey] = variantVal
179
+ }
180
+ return vacc
181
+ }, {})
182
+ return acc
183
+ }, {})
184
+ }
@@ -0,0 +1,22 @@
1
+ import * as React from 'react'
2
+
3
+ import { TamaguiProviderProps } from '../types'
4
+ import { TextAncestorProvider } from '../views/TextAncestorContext'
5
+ import { ThemeProvider, ThemeProviderProps } from '../views/ThemeProvider'
6
+
7
+ export function createTamaguiProvider(themeProps: ThemeProviderProps) {
8
+ return function TamaguiProvider({
9
+ initialWindowMetrics,
10
+ fallback,
11
+ children,
12
+ ...themePropsProvider
13
+ }: TamaguiProviderProps) {
14
+ return (
15
+ <TextAncestorProvider>
16
+ <ThemeProvider {...themeProps} {...themePropsProvider}>
17
+ <React.Suspense fallback={fallback || null}>{children}</React.Suspense>
18
+ </ThemeProvider>
19
+ </TextAncestorProvider>
20
+ )
21
+ }
22
+ }