@tamagui/core 1.0.1-beta.141 → 1.0.1-beta.142

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 (200) hide show
  1. package/dist/cjs/Tamagui.js +2 -2
  2. package/dist/cjs/Tamagui.js.map +2 -2
  3. package/dist/cjs/addTheme.js +28 -22
  4. package/dist/cjs/addTheme.js.map +2 -2
  5. package/dist/cjs/config.js +75 -0
  6. package/dist/cjs/config.js.map +7 -0
  7. package/dist/cjs/constants/platform.js +7 -1
  8. package/dist/cjs/constants/platform.js.map +2 -2
  9. package/dist/cjs/constants/platform.native.js +62 -0
  10. package/dist/cjs/constants/platform.native.js.map +7 -0
  11. package/dist/cjs/createComponent.js +71 -58
  12. package/dist/cjs/createComponent.js.map +2 -2
  13. package/dist/cjs/createComponent.server.js +431 -0
  14. package/dist/cjs/createComponent.server.js.map +7 -0
  15. package/dist/cjs/createTamagui.js +10 -8
  16. package/dist/cjs/createTamagui.js.map +2 -2
  17. package/dist/cjs/createVariable.js +6 -12
  18. package/dist/cjs/createVariable.js.map +2 -2
  19. package/dist/cjs/createVariables.js +5 -2
  20. package/dist/cjs/createVariables.js.map +2 -2
  21. package/dist/cjs/helpers/RNComponents.js +11 -11
  22. package/dist/cjs/helpers/RNComponents.js.map +2 -2
  23. package/dist/cjs/helpers/ThemeManager.js +7 -9
  24. package/dist/cjs/helpers/ThemeManager.js.map +2 -2
  25. package/dist/cjs/helpers/assignNativePropsToWeb.js +0 -1
  26. package/dist/cjs/helpers/assignNativePropsToWeb.js.map +2 -2
  27. package/dist/cjs/helpers/createPropMapper.js +3 -3
  28. package/dist/cjs/helpers/createPropMapper.js.map +2 -2
  29. package/dist/cjs/helpers/expandStyles.js +4 -4
  30. package/dist/cjs/helpers/expandStyles.js.map +2 -2
  31. package/dist/cjs/helpers/getAnimationDriver.js +32 -0
  32. package/dist/cjs/helpers/getAnimationDriver.js.map +7 -0
  33. package/dist/cjs/helpers/getExpandedShorthands.js +3 -3
  34. package/dist/cjs/helpers/getExpandedShorthands.js.map +2 -2
  35. package/dist/cjs/helpers/getFont.js +1 -1
  36. package/dist/cjs/helpers/getFont.js.map +2 -2
  37. package/dist/cjs/helpers/getSize.js +2 -2
  38. package/dist/cjs/helpers/getSize.js.map +2 -2
  39. package/dist/cjs/helpers/getSplitStyles.js +12 -13
  40. package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
  41. package/dist/cjs/helpers/getStylesAtomic.js +6 -4
  42. package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
  43. package/dist/cjs/helpers/getVariantExtras.js +2 -2
  44. package/dist/cjs/helpers/getVariantExtras.js.map +2 -2
  45. package/dist/cjs/helpers/normalizeColor.js +2 -2
  46. package/dist/cjs/helpers/normalizeColor.js.map +2 -2
  47. package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
  48. package/dist/cjs/helpers/useAnimationDriver.js +2 -0
  49. package/dist/cjs/helpers/useAnimationDriver.js.map +7 -0
  50. package/dist/cjs/hooks/getThemeUnwrapped.js +2 -0
  51. package/dist/cjs/hooks/getThemeUnwrapped.js.map +2 -2
  52. package/dist/cjs/hooks/useAnimationDriver.js +2 -0
  53. package/dist/cjs/hooks/useAnimationDriver.js.map +7 -0
  54. package/dist/cjs/hooks/useFeatures.js +2 -2
  55. package/dist/cjs/hooks/useFeatures.js.map +2 -2
  56. package/dist/cjs/hooks/useServerContext.js +21 -0
  57. package/dist/cjs/hooks/useServerContext.js.map +7 -0
  58. package/dist/cjs/hooks/useServerHooks.js +36 -0
  59. package/dist/cjs/hooks/useServerHooks.js.map +7 -0
  60. package/dist/cjs/hooks/useTheme.js +71 -41
  61. package/dist/cjs/hooks/useTheme.js.map +2 -2
  62. package/dist/cjs/index.js +7 -6
  63. package/dist/cjs/index.js.map +2 -2
  64. package/dist/cjs/injectStyles.js +40 -0
  65. package/dist/cjs/injectStyles.js.map +7 -0
  66. package/dist/cjs/insertFont.js +2 -2
  67. package/dist/cjs/insertFont.js.map +2 -2
  68. package/dist/cjs/styled.js +11 -1
  69. package/dist/cjs/styled.js.map +2 -2
  70. package/dist/cjs/types.js.map +1 -1
  71. package/dist/cjs/views/TamaguiProvider.js +6 -1
  72. package/dist/cjs/views/TamaguiProvider.js.map +2 -2
  73. package/dist/cjs/views/ThemeProvider.js +9 -5
  74. package/dist/cjs/views/ThemeProvider.js.map +2 -2
  75. package/dist/esm/Tamagui.js +1 -1
  76. package/dist/esm/Tamagui.js.map +1 -1
  77. package/dist/esm/addTheme.js +27 -21
  78. package/dist/esm/addTheme.js.map +2 -2
  79. package/dist/esm/config.js +43 -0
  80. package/dist/esm/config.js.map +7 -0
  81. package/dist/esm/constants/platform.js +5 -1
  82. package/dist/esm/constants/platform.js.map +2 -2
  83. package/dist/esm/constants/platform.native.js +28 -0
  84. package/dist/esm/constants/platform.native.js.map +7 -0
  85. package/dist/esm/createComponent.js +71 -60
  86. package/dist/esm/createComponent.js.map +2 -2
  87. package/dist/esm/createComponent.server.js +408 -0
  88. package/dist/esm/createComponent.server.js.map +7 -0
  89. package/dist/esm/createTamagui.js +7 -5
  90. package/dist/esm/createTamagui.js.map +2 -2
  91. package/dist/esm/createVariable.js +6 -12
  92. package/dist/esm/createVariable.js.map +2 -2
  93. package/dist/esm/createVariables.js +5 -2
  94. package/dist/esm/createVariables.js.map +2 -2
  95. package/dist/esm/helpers/RNComponents.js +11 -8
  96. package/dist/esm/helpers/RNComponents.js.map +2 -2
  97. package/dist/esm/helpers/ThemeManager.js +6 -8
  98. package/dist/esm/helpers/ThemeManager.js.map +2 -2
  99. package/dist/esm/helpers/assignNativePropsToWeb.js +0 -1
  100. package/dist/esm/helpers/assignNativePropsToWeb.js.map +2 -2
  101. package/dist/esm/helpers/createPropMapper.js +2 -2
  102. package/dist/esm/helpers/createPropMapper.js.map +2 -2
  103. package/dist/esm/helpers/expandStyles.js +3 -3
  104. package/dist/esm/helpers/expandStyles.js.map +2 -2
  105. package/dist/esm/helpers/getAnimationDriver.js +8 -0
  106. package/dist/esm/helpers/getAnimationDriver.js.map +7 -0
  107. package/dist/esm/helpers/getExpandedShorthands.js +2 -2
  108. package/dist/esm/helpers/getExpandedShorthands.js.map +2 -2
  109. package/dist/esm/helpers/getFont.js +1 -1
  110. package/dist/esm/helpers/getFont.js.map +2 -2
  111. package/dist/esm/helpers/getSize.js +1 -1
  112. package/dist/esm/helpers/getSize.js.map +1 -1
  113. package/dist/esm/helpers/getSplitStyles.js +12 -13
  114. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  115. package/dist/esm/helpers/getStylesAtomic.js +5 -3
  116. package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
  117. package/dist/esm/helpers/getVariantExtras.js +1 -1
  118. package/dist/esm/helpers/getVariantExtras.js.map +1 -1
  119. package/dist/esm/helpers/normalizeColor.js +1 -1
  120. package/dist/esm/helpers/normalizeColor.js.map +1 -1
  121. package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
  122. package/dist/esm/helpers/useAnimationDriver.js +1 -0
  123. package/dist/esm/helpers/useAnimationDriver.js.map +7 -0
  124. package/dist/esm/hooks/getThemeUnwrapped.js +2 -0
  125. package/dist/esm/hooks/getThemeUnwrapped.js.map +2 -2
  126. package/dist/esm/hooks/useAnimationDriver.js +1 -0
  127. package/dist/esm/hooks/useAnimationDriver.js.map +7 -0
  128. package/dist/esm/hooks/useFeatures.js +1 -1
  129. package/dist/esm/hooks/useFeatures.js.map +2 -2
  130. package/dist/esm/hooks/useServerContext.js +4 -0
  131. package/dist/esm/hooks/useServerContext.js.map +7 -0
  132. package/dist/esm/hooks/useServerHooks.js +11 -0
  133. package/dist/esm/hooks/useServerHooks.js.map +7 -0
  134. package/dist/esm/hooks/useTheme.js +72 -42
  135. package/dist/esm/hooks/useTheme.js.map +2 -2
  136. package/dist/esm/index.js +2 -1
  137. package/dist/esm/index.js.map +2 -2
  138. package/dist/esm/injectStyles.js +16 -0
  139. package/dist/esm/injectStyles.js.map +7 -0
  140. package/dist/esm/insertFont.js +1 -1
  141. package/dist/esm/insertFont.js.map +1 -1
  142. package/dist/esm/styled.js +11 -1
  143. package/dist/esm/styled.js.map +2 -2
  144. package/dist/esm/views/TamaguiProvider.js +7 -2
  145. package/dist/esm/views/TamaguiProvider.js.map +2 -2
  146. package/dist/esm/views/ThemeProvider.js +9 -5
  147. package/dist/esm/views/ThemeProvider.js.map +2 -2
  148. package/package.json +35 -14
  149. package/src/Tamagui.ts +1 -1
  150. package/src/addTheme.ts +33 -21
  151. package/src/{conf.ts → config.ts} +4 -0
  152. package/src/constants/platform.native.ts +14 -0
  153. package/src/constants/platform.ts +12 -1
  154. package/src/createComponent.tsx +164 -148
  155. package/src/createTamagui.ts +11 -5
  156. package/src/createVariable.ts +8 -25
  157. package/src/createVariables.ts +5 -2
  158. package/src/helpers/RNComponents.tsx +13 -13
  159. package/src/helpers/ThemeManager.tsx +15 -12
  160. package/src/helpers/assignNativePropsToWeb.tsx +0 -1
  161. package/src/helpers/createPropMapper.ts +2 -2
  162. package/src/helpers/expandStyles.ts +4 -3
  163. package/src/helpers/getAnimationDriver.tsx +5 -0
  164. package/src/helpers/getExpandedShorthands.ts +2 -2
  165. package/src/helpers/getFont.tsx +1 -1
  166. package/src/helpers/getSize.ts +1 -1
  167. package/src/helpers/getSplitStyles.tsx +12 -13
  168. package/src/helpers/getStylesAtomic.ts +6 -3
  169. package/src/helpers/getVariantExtras.tsx +2 -2
  170. package/src/helpers/normalizeColor.ts +1 -1
  171. package/src/helpers/normalizeValueWithProperty.ts +2 -0
  172. package/src/hooks/getThemeUnwrapped.tsx +1 -0
  173. package/src/hooks/useFeatures.tsx +2 -1
  174. package/src/hooks/useServerHooks.tsx +13 -0
  175. package/src/hooks/useTheme.tsx +94 -48
  176. package/src/index.ts +2 -1
  177. package/src/injectStyles.ts +20 -0
  178. package/src/insertFont.ts +1 -1
  179. package/src/styled.tsx +15 -1
  180. package/src/types.tsx +33 -0
  181. package/src/views/TamaguiProvider.tsx +11 -4
  182. package/src/views/ThemeProvider.tsx +9 -6
  183. package/types/config.d.ts +27 -0
  184. package/types/constants/platform.d.ts +1 -0
  185. package/types/constants/platform.native.d.ts +13 -0
  186. package/types/createComponent.server.d.ts +36 -0
  187. package/types/createVariable.d.ts +1 -2
  188. package/types/helpers/RNComponents.d.ts +1 -1
  189. package/types/helpers/ThemeManager.d.ts +2 -8
  190. package/types/helpers/getAnimationDriver.d.ts +6 -0
  191. package/types/helpers/useAnimationDriver.d.ts +1 -0
  192. package/types/hooks/useAnimationDriver.d.ts +1 -0
  193. package/types/hooks/useServerContext.d.ts +2 -0
  194. package/types/hooks/useServerHooks.d.ts +4 -0
  195. package/types/hooks/useTheme.d.ts +5 -21
  196. package/types/index.d.ts +2 -1
  197. package/types/injectStyles.d.ts +7 -0
  198. package/types/types.d.ts +23 -0
  199. package/types/views/TamaguiProvider.d.ts +1 -1
  200. package/types/views/ThemeProvider.d.ts +0 -1
@@ -1,5 +1,6 @@
1
+ import { isValidCSSCharCode, simpleHash } from '@tamagui/helpers'
2
+
1
3
  import { isWeb } from './constants/platform'
2
- import { VariableColorVal } from './types'
3
4
 
4
5
  /**
5
6
  * Should rename this to Token
@@ -35,10 +36,12 @@ export const createVariable = <A extends string | number = any>(props: VariableI
35
36
  }
36
37
 
37
38
  // on the client maybe we can change the prototype of variable object toString to keep backwards compat
38
- export function variableToString(vrble?: Variable | VariableColorVal) {
39
+ export function variableToString(vrble?: any) {
39
40
  if (!vrble) return ''
40
- if (typeof vrble === 'string') return vrble
41
- return `${isWeb ? vrble.variable : vrble.val}`
41
+ if (isVariable(vrble)) {
42
+ return `${isWeb ? vrble.variable : vrble.val}`
43
+ }
44
+ return `${vrble}`
42
45
  }
43
46
 
44
47
  export function isVariable(v: Variable | any): v is Variable {
@@ -69,26 +72,6 @@ export const createCSSVariable = (nameProp: string, includeVar = true) => {
69
72
  return ``
70
73
  }
71
74
  }
72
- let name = ''
73
- for (let i = 0; i < nameProp.length; i++) {
74
- const code = nameProp.charCodeAt(i)
75
- if (
76
- // A-Z
77
- (code >= 65 && code <= 90) ||
78
- // a-z
79
- (code >= 97 && code <= 122) ||
80
- // _
81
- code == 95 ||
82
- // -
83
- code === 45 ||
84
- // 0-9
85
- (code >= 48 && code <= 57)
86
- ) {
87
- name += nameProp[i]
88
- } else {
89
- // allow any name but turn it into a stringified num
90
- name += `-c${code}-`
91
- }
92
- }
75
+ const name = simpleHash(nameProp, 60)
93
76
  return includeVar ? `var(--${name})` : name
94
77
  }
@@ -18,19 +18,22 @@ export const createVariables = <A extends DeepTokenObject>(
18
18
  isFont = false
19
19
  ): DeepVariableObject<A> => {
20
20
  const res: any = {}
21
+ let i = 0
21
22
  for (const key in tokens) {
23
+ i++
24
+ const variableName = isFont ? key.slice(0, 2) : i
22
25
  const val = tokens[key]
23
26
  if (isVariable(val)) {
24
27
  res[key] = val
25
28
  continue
26
29
  }
27
- let name = parentPath ? `${parentPath}-${key}` : key
30
+ let name = parentPath ? `${parentPath}-${variableName}` : key
28
31
  if (isFont && name.includes('_')) {
29
32
  name = name.replace(/_[a-z0-9]+/i, '')
30
33
  }
31
34
  if (val && typeof val === 'object') {
32
35
  // recurse
33
- res[key] = createVariables(tokens[key] as any, isFont ? 'f' : name)
36
+ res[key] = createVariables(tokens[key] as any, `${name}`)
34
37
  continue
35
38
  }
36
39
  res[key] = isVariable(val) ? val : createVariable({ val, name, key })
@@ -1,14 +1,14 @@
1
- import * as ReactNative from 'react-native'
1
+ import { Image, Text, TextInput, View } from 'react-native'
2
2
 
3
- // bye bye tree shaking... but only way to properly detect react-native components...
4
- // also neither rnw nor react support tree shaking atm
5
- export const RNComponents = new WeakMap()
6
-
7
- // I was looping over all of them, but casuses deprecation warnings and there's only a few
8
- // we realistically support - lets whitelist rather than blacklist
9
- for (const key of ['Image', 'TextInput', 'Text', 'View']) {
10
- const val = ReactNative[key]
11
- if (val && typeof val === 'object') {
12
- RNComponents.set(val, true)
13
- }
14
- }
3
+ // limited support
4
+ export const RNComponents = new Set<any>([
5
+ Image,
6
+ TextInput,
7
+ Text,
8
+ View,
9
+ // see fake-react-native + styled() check
10
+ 'Image',
11
+ 'TextInput',
12
+ 'Text',
13
+ 'View',
14
+ ])
@@ -1,6 +1,6 @@
1
1
  import { createContext } from 'react'
2
2
 
3
- import { getThemes } from '../conf'
3
+ import { getThemes } from '../config'
4
4
  import { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants'
5
5
  import { getThemeUnwrapped } from '../hooks/getThemeUnwrapped'
6
6
  import { ThemeObject, Themes } from '../types'
@@ -100,7 +100,14 @@ export class ThemeManager {
100
100
  return true
101
101
  }
102
102
 
103
- getNextTheme(props: GetNextThemeProps = {}, debug?: any) {
103
+ getNextTheme(
104
+ props: GetNextThemeProps = {},
105
+ debug?: any
106
+ ): {
107
+ name: string
108
+ theme: ThemeObject | null
109
+ className: string | undefined
110
+ } {
104
111
  const { themes = getThemes(), name, componentName } = props
105
112
 
106
113
  if (props.reset && name) {
@@ -130,6 +137,7 @@ export class ThemeManager {
130
137
  return {
131
138
  name: this.name,
132
139
  theme: this.theme,
140
+ className: undefined,
133
141
  }
134
142
  }
135
143
 
@@ -137,17 +145,11 @@ export class ThemeManager {
137
145
  let parentName = parentIsReset ? this.parentName || this.fullName : this.fullName
138
146
 
139
147
  while (true) {
140
- if (nextName in themes) {
141
- break
142
- }
148
+ if (nextName in themes) break
143
149
  nextName = `${parentName}_${name}`
144
- if (nextName in themes) {
145
- break
146
- }
147
- if (!parentName.includes(THEME_NAME_SEPARATOR)) {
148
- // this is fine - some themes can not have parents
149
- break
150
- }
150
+ if (nextName in themes) break
151
+ // this is fine - some themes can not have parents
152
+ if (!parentName.includes(THEME_NAME_SEPARATOR)) break
151
153
  // go up one
152
154
  parentName = parentName.slice(0, parentName.lastIndexOf(THEME_NAME_SEPARATOR))
153
155
  }
@@ -172,6 +174,7 @@ export class ThemeManager {
172
174
 
173
175
  if (process.env.NODE_ENV === 'development') {
174
176
  if (debug) {
177
+ // eslint-disable-next-line no-console
175
178
  console.log('getNextTheme', this.getClassName(nextName), { props, nextName, parentName })
176
179
  }
177
180
  }
@@ -39,7 +39,6 @@ export function assignNativePropsToWeb(elementType: string, viewProps: any, nati
39
39
  viewProps['aria-colspan'] = nativeProps.accessibilityColumnSpan
40
40
  }
41
41
  if (nativeProps.accessibilityControls != null) {
42
- console.log('wtf', nativeProps.accessibilityControls)
43
42
  viewProps['aria-controls'] = processIDRefList(nativeProps.accessibilityControls)
44
43
  }
45
44
  if (nativeProps.accessibilityCurrent != null) {
@@ -1,4 +1,4 @@
1
- import { getConfig } from '../conf'
1
+ import { getConfig } from '../config'
2
2
  import { isWeb } from '../constants/platform'
3
3
  import { Variable, isVariable } from '../createVariable'
4
4
  import {
@@ -31,7 +31,7 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
31
31
  const variants = staticConfig.variants || {}
32
32
 
33
33
  // temp remove classnames
34
- const defaultProps = mergeProps(staticConfig.defaultProps || {}, {}, true)[0]
34
+ const defaultProps = mergeProps(staticConfig.defaultProps || {}, {}, false)[0]
35
35
 
36
36
  const mapper: PropMapper = (
37
37
  key,
@@ -1,8 +1,8 @@
1
- import { getConfig } from '../conf'
1
+ import { getConfig } from '../config'
2
2
  import { isWeb } from '../constants/platform'
3
3
  import { expandStyle } from './expandStyle'
4
4
  import { colorToRGBA, normalizeColor } from './normalizeColor'
5
- import { normalizeValueWithProperty } from './normalizeValueWithProperty'
5
+ import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
6
6
  import { pseudoDescriptors } from './pseudoDescriptors'
7
7
 
8
8
  let shorthands: Record<string, string> | null = null
@@ -81,12 +81,13 @@ function normalizeShadow({
81
81
  ...(isWeb && {
82
82
  shadowColor: normalizeColor(colorStr, shadowOpacity),
83
83
  }),
84
- ...(!isWeb &&
84
+ ...(process.env.TAMAGUI_TARGET === 'native' &&
85
85
  (() => {
86
86
  // on native fix bug - shadows behave better if turned into non-alpha rgb() + shadowOpacity
87
87
  const rgba = colorToRGBA(colorStr)
88
88
  if (!rgba) {
89
89
  if (process.env.NODE_ENV === 'development') {
90
+ // eslint-disable-next-line no-console
90
91
  console.warn('No rgba form', colorStr)
91
92
  }
92
93
  return {
@@ -0,0 +1,5 @@
1
+ import { getConfig } from '../config'
2
+
3
+ export function getAnimationDriver() {
4
+ return getConfig().animations
5
+ }
@@ -1,4 +1,4 @@
1
- import { getConfig } from '../conf'
1
+ import { getConfig } from '../config'
2
2
  import { Shorthands } from '../types'
3
3
 
4
4
  export function getExpandedShorthands<A extends Object>(props: A): Omit<A, keyof Shorthands> {
@@ -6,7 +6,7 @@ export function getExpandedShorthands<A extends Object>(props: A): Omit<A, keyof
6
6
  if (!shorthands) {
7
7
  return props
8
8
  }
9
- let res: A = {} as any
9
+ const res: A = {} as any
10
10
  for (const key in props) {
11
11
  // @ts-ignore
12
12
  res[shorthands[key] || key] = props[key]
@@ -31,7 +31,7 @@ export const getFont: VariantSpreadFunction<TextProps, FontSizeTokens> = (
31
31
  }
32
32
  if (process.env.NODE_ENV === 'development') {
33
33
  if (props['debug']) {
34
- console.groupCollapsed(' 🔹 getFont', val)
34
+ console.groupCollapsed(' 🔹 getFont', val, props['fontWeight'], props['fow'])
35
35
  console.log({ style, props, font })
36
36
  console.groupEnd()
37
37
  }
@@ -1,4 +1,4 @@
1
- import { getTokens } from '../conf'
1
+ import { getTokens } from '../config'
2
2
  import { SizeTokens, SpaceTokens } from '../types'
3
3
 
4
4
  export const getSize = (size?: SizeTokens | undefined, shift = 0, bounds = [0]) => {
@@ -2,8 +2,8 @@ import { stylePropsText, stylePropsTransform, validPseudoKeys, validStyles } fro
2
2
  import { useInsertionEffect } from 'react'
3
3
  import { ViewStyle } from 'react-native'
4
4
 
5
- import { getConfig } from '../conf'
6
- import { isClient, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
5
+ import { getConfig } from '../config'
6
+ import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
7
7
  import { mediaQueryConfig, mediaState } from '../hooks/useMedia'
8
8
  import type {
9
9
  DebugProp,
@@ -30,7 +30,7 @@ import {
30
30
  updateRules,
31
31
  } from './insertStyleRule'
32
32
  import { mergeTransform } from './mergeTransform'
33
- import { normalizeValueWithProperty } from './normalizeValueWithProperty'
33
+ import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
34
34
  import { pseudoDescriptors } from './pseudoDescriptors'
35
35
 
36
36
  export type SplitStyles = ReturnType<typeof getSplitStyles>
@@ -588,7 +588,7 @@ export const getSplitStyles: StyleSplitter = (
588
588
  * and to avoid re-creating it over and over, use a WeakMap
589
589
  */
590
590
  const propProxies = new WeakMap()
591
- function getSubStyleProxiedProps(baseProps: Object, specificProps: Object) {
591
+ function getSubStyleProxiedProps(defaultProps: Object, baseProps: Object, specificProps: Object) {
592
592
  if (!specificProps) {
593
593
  // functional variants may want to eventually do something like:
594
594
  // have a hooks-like rule (no conditionals)
@@ -603,14 +603,11 @@ function getSubStyleProxiedProps(baseProps: Object, specificProps: Object) {
603
603
  return propProxies.get(specificProps)
604
604
  }
605
605
  const next = new Proxy(specificProps, {
606
- ownKeys() {
607
- return [...new Set([...Object.keys(baseProps), ...Object.keys(specificProps)])]
608
- },
609
606
  has(_, key) {
610
- return key in specificProps || key in baseProps
607
+ return key in defaultProps || key in specificProps || key in baseProps
611
608
  },
612
609
  get(_, key) {
613
- return specificProps[key] ?? baseProps[key]
610
+ return defaultProps[key] ?? specificProps[key] ?? baseProps[key]
614
611
  },
615
612
  })
616
613
  propProxies.set(specificProps, next)
@@ -636,7 +633,7 @@ export const getSubStyle = (
636
633
  key,
637
634
  val,
638
635
  theme,
639
- getSubStyleProxiedProps(props, props[subKey]),
636
+ getSubStyleProxiedProps(staticConfig.defaultProps, props, props[subKey]),
640
637
  state,
641
638
  languageContext,
642
639
  avoidDefaultProps
@@ -668,9 +665,11 @@ const useInsertEffectCompat = isWeb ? useInsertionEffect || useIsomorphicLayoutE
668
665
  export const useSplitStyles: StyleSplitter = (...args) => {
669
666
  const res = getSplitStyles(...args)
670
667
 
671
- useInsertEffectCompat(() => {
672
- insertStyleRules(res.rulesToInsert)
673
- }, [res.rulesToInsert])
668
+ if (!isRSC) {
669
+ useInsertEffectCompat(() => {
670
+ insertStyleRules(res.rulesToInsert)
671
+ }, [res.rulesToInsert])
672
+ }
674
673
 
675
674
  return res
676
675
  }
@@ -7,10 +7,10 @@ import { StyleObject, simpleHash } from '@tamagui/helpers'
7
7
  import hyphenateStyleName from 'hyphenate-style-name'
8
8
  import { TextStyle, ViewStyle } from 'react-native'
9
9
 
10
- import { getConfig } from '../conf'
10
+ import { getConfig } from '../config'
11
11
  import { TamaguiInternalConfig } from '../types'
12
12
  import { defaultOffset } from './expandStyles'
13
- import { normalizeValueWithProperty } from './normalizeValueWithProperty'
13
+ import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
14
14
  import { PseudoDescriptor, pseudoDescriptors } from './pseudoDescriptors'
15
15
 
16
16
  // refactor this file away next...
@@ -50,7 +50,10 @@ export function getAtomicStyle(style: ViewOrTextStyle, pseudo?: PseudoDescriptor
50
50
  }
51
51
  } else {
52
52
  if (!style) {
53
- console.warn(`Invalid style`)
53
+ if (process.env.NODE_ENV === 'development') {
54
+ // eslint-disable-next-line no-console
55
+ console.warn(`Invalid style`)
56
+ }
54
57
  return []
55
58
  }
56
59
  }
@@ -1,5 +1,5 @@
1
- import { getConfig } from '../conf'
2
- import { GenericFonts } from '../types'
1
+ import { getConfig } from '../config'
2
+ import { GenericFonts, StaticConfig } from '../types'
3
3
  import { LanguageContextType } from '../views/FontLanguage.types'
4
4
 
5
5
  const extrasCache = new WeakMap()
@@ -1,4 +1,4 @@
1
- import normalizeCSSColor from 'normalize-css-color'
1
+ import normalizeCSSColor from '@tamagui/normalize-css-color-lite'
2
2
 
3
3
  export const normalizeColor = (color?: number | string | null, opacity?: number) => {
4
4
  if (color == null || color == undefined) {
@@ -24,6 +24,8 @@ export function normalizeValueWithProperty(value: any, property?: string): any {
24
24
  return res
25
25
  }
26
26
 
27
+ // TODO react-native-web-lite
28
+
27
29
  const colorProps = {
28
30
  backgroundColor: true,
29
31
  borderColor: true,
@@ -1,4 +1,5 @@
1
1
  export const getThemeUnwrapped = (theme: any) => {
2
+ if (!theme) return null
2
3
  const first = theme[GetThemeUnwrapped]
3
4
  if (first) return first[GetThemeUnwrapped] || first
4
5
  return theme
@@ -2,7 +2,7 @@ import React from 'react'
2
2
  import { RefObject } from 'react'
3
3
  import { View, ViewStyle } from 'react-native'
4
4
 
5
- import { getConfig } from '../conf'
5
+ import { getConfig } from '../config'
6
6
  import { useIsomorphicLayoutEffect } from '../constants/platform'
7
7
  import { getSubStyle } from '../helpers/getSplitStyles'
8
8
  import {
@@ -97,6 +97,7 @@ function loadAnimationFeature() {
97
97
  } = _utils
98
98
 
99
99
  if (!useAnimations) {
100
+ // eslint-disable-next-line no-console
100
101
  console.error('no useAnimations hook provided')
101
102
  return null
102
103
  }
@@ -0,0 +1,13 @@
1
+ import { useRef, useState } from 'react'
2
+
3
+ import { isRSC } from '../constants/platform'
4
+
5
+ export const useServerState = isRSC
6
+ ? (((val: any) => [val, idFn]) as unknown as typeof useState)
7
+ : useState
8
+
9
+ export const useServerRef = isRSC
10
+ ? (((val: any) => ({ current: val })) as unknown as typeof useRef)
11
+ : useRef
12
+
13
+ const idFn = () => {}
@@ -1,8 +1,8 @@
1
1
  import { useForceUpdate } from '@tamagui/use-force-update'
2
2
  import React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'
3
3
 
4
- import { getConfig } from '../conf'
5
- import { isSSR, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
4
+ import { getConfig } from '../config'
5
+ import { isRSC, isSSR, useIsomorphicLayoutEffect } from '../constants/platform'
6
6
  import { ThemeContext } from '../contexts/ThemeContext'
7
7
  import { areEqualSets } from '../helpers/areEqualSets'
8
8
  import {
@@ -14,8 +14,9 @@ import {
14
14
  import { ThemeName, ThemeObject } from '../types'
15
15
  import { GetThemeUnwrapped } from './getThemeUnwrapped'
16
16
  import { useConstant } from './useConstant'
17
+ import { useServerRef } from './useServerHooks'
17
18
 
18
- export type ThemeProps = {
19
+ export interface ThemeProps {
19
20
  className?: string
20
21
  disableThemeClass?: boolean
21
22
  name: Exclude<ThemeName, number> | null
@@ -25,7 +26,7 @@ export type ThemeProps = {
25
26
  debug?: boolean | 'verbose'
26
27
  }
27
28
 
28
- type UseThemeState = {
29
+ interface UseThemeState {
29
30
  uuid: Object
30
31
  keys: Set<string>
31
32
  isRendering: boolean
@@ -37,6 +38,13 @@ export const useTheme = (
37
38
  props?: ThemeProps,
38
39
  forceUpdate?: any
39
40
  ): ThemeObject => {
41
+ // TODO this can use useChangeThemeEffect almost ready
42
+ if (isRSC) {
43
+ const config = getConfig()
44
+ // @ts-ignore
45
+ return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)
46
+ }
47
+
40
48
  const { name, theme, themes, themeManager, className } = useChangeThemeEffect(
41
49
  themeName,
42
50
  componentName,
@@ -51,7 +59,7 @@ export const useTheme = (
51
59
  }
52
60
  }
53
61
 
54
- const state = useRef() as React.MutableRefObject<UseThemeState>
62
+ const state = useServerRef() as React.MutableRefObject<UseThemeState>
55
63
  if (!state.current) {
56
64
  state.current = {
57
65
  uuid: {},
@@ -82,49 +90,60 @@ export const useTheme = (
82
90
  }
83
91
 
84
92
  return useMemo(() => {
85
- return new Proxy(theme, {
86
- has(_, key) {
87
- if (typeof key === 'string') {
88
- if (key[0] === '$') {
89
- key = key.slice(1)
90
- }
91
- }
92
- return Reflect.has(theme, key)
93
- },
94
- get(_, key) {
95
- if (key === GetThemeUnwrapped) {
96
- return theme
97
- }
98
- if (key === GetThemeManager) {
99
- return themeManager
100
- }
101
- if (key === 'name') {
102
- return name
103
- }
104
- if (key === 'className') {
105
- return className
106
- }
107
- if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {
108
- return Reflect.get(_, key)
109
- }
110
- if (!themeManager) {
111
- console.error('No themeManager')
112
- return
113
- }
114
- // auto convert variables to plain
115
- if (key[0] === '$') {
116
- key = key.slice(1)
117
- }
93
+ return getThemeProxied(theme, name, className, themeManager, state, debugProp)
94
+ }, [theme, name, themeManager, className, debugProp])
95
+ }
96
+
97
+ function getThemeProxied(
98
+ theme: any,
99
+ name: string,
100
+ className?: string,
101
+ themeManager?: ThemeManager | null,
102
+ state?: React.MutableRefObject<UseThemeState>,
103
+ debugProp?: boolean | 'verbose'
104
+ ) {
105
+ return new Proxy(theme, {
106
+ has(_, key) {
107
+ if (typeof key === 'string' && key[0] === '$') {
108
+ key = key.slice(1)
109
+ }
110
+ return Reflect.has(theme, key)
111
+ },
112
+ get(_, key) {
113
+ if (key === GetThemeUnwrapped) {
114
+ return theme
115
+ }
116
+ if (key === GetThemeManager) {
117
+ return themeManager
118
+ }
119
+ if (key === 'name') {
120
+ return name
121
+ }
122
+ if (key === 'className') {
123
+ return className
124
+ }
125
+ if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {
126
+ return Reflect.get(_, key)
127
+ }
128
+ // auto convert variables to plain
129
+ if (key[0] === '$') {
130
+ key = key.slice(1)
131
+ }
132
+ if (!themeManager) {
133
+ return theme[key]
134
+ }
135
+ if (state) {
118
136
  if (state.current.isRendering && !state.current.keys.has(key)) {
119
137
  state.current.keys.add(key)
120
138
  if (process.env.NODE_ENV === 'development' && debugProp === 'verbose') {
139
+ // eslint-disable-next-line no-console
121
140
  console.log(' 🔸 tracking theme', key)
122
141
  }
123
142
  }
124
- return themeManager.getValue(key)
125
- },
126
- })
127
- }, [name, theme, componentName, className, debugProp])
143
+ }
144
+ return themeManager.getValue(key)
145
+ },
146
+ })
128
147
  }
129
148
 
130
149
  const GetThemeManager = Symbol()
@@ -135,6 +154,10 @@ export const getThemeManager = (theme: any): ThemeManager | undefined => {
135
154
  }
136
155
 
137
156
  export const useThemeName = (opts?: { parent?: true }) => {
157
+ if (isRSC) {
158
+ const config = getConfig()
159
+ return config.defaultTheme || 'light'
160
+ }
138
161
  const parent = useContext(ThemeManagerContext)
139
162
  const [name, setName] = useState(parent?.name || '')
140
163
 
@@ -161,20 +184,43 @@ export const useChangeThemeEffect = (
161
184
  componentName?: string,
162
185
  props?: ThemeProps,
163
186
  forceUpdateProp?: any
164
- ) => {
187
+ ): {
188
+ themes: Record<string, ThemeObject>
189
+ themeManager: ThemeManager | null
190
+ name: string
191
+ theme: ThemeObject | null
192
+ className?: string
193
+ } => {
194
+ const { themes } = getConfig()
195
+ if (isRSC) {
196
+ // we need context working for this to work well
197
+ const parentManager = new ThemeManager('light', themes.light)
198
+ const next = parentManager.getNextTheme({
199
+ name,
200
+ componentName,
201
+ themes,
202
+ reset: props?.reset,
203
+ })
204
+ return {
205
+ ...next,
206
+ themes,
207
+ themeManager: null,
208
+ }
209
+ }
165
210
  const debug = props && props['debug']
166
211
  const parentManager = useContext(ThemeManagerContext) || emptyManager
167
- const { themes } = useContext(ThemeContext)!
168
212
  const reset = props?.reset || false
169
- const getThemeProps: GetNextThemeProps = { name, componentName, themes, reset }
213
+ const getThemeProps: GetNextThemeProps = {
214
+ name,
215
+ componentName,
216
+ themes,
217
+ reset,
218
+ }
170
219
  const next = parentManager.getNextTheme(getThemeProps, debug)
171
220
  // eslint-disable-next-line react-hooks/rules-of-hooks
172
221
  const forceUpdate = forceUpdateProp || useForceUpdate()
173
222
 
174
223
  const themeManager = useConstant<ThemeManager | null>(() => {
175
- // if (!next) return null
176
- // RSC test
177
- // if (typeof document === 'undefined') return null
178
224
  return new ThemeManager(next.name, next.theme, parentManager, reset)
179
225
  })
180
226
 
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ export * from './types'
15
15
 
16
16
  // for type portability
17
17
  export type { RNWTextProps, RNWViewProps } from './types-rnw'
18
- export { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './conf'
18
+ export { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './config'
19
19
 
20
20
  export * from './constants/constants'
21
21
  export * from './constants/platform'
@@ -25,6 +25,7 @@ export * from './helpers/calc'
25
25
  export * from './helpers/createShallowUpdate'
26
26
  export * from './helpers/getStackSize'
27
27
  export * from './helpers/getVariantExtras'
28
+ export * from './helpers/getAnimationDriver'
28
29
  export * from './helpers/getExpandedShorthands'
29
30
  export * from './helpers/getSize'
30
31
  export * from './helpers/getSplitStyles'