@tamagui/web 1.46.2 → 1.47.1

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 (173) hide show
  1. package/dist/cjs/constants/constants.js +15 -15
  2. package/dist/cjs/constants/constants.js.map +1 -1
  3. package/dist/cjs/createComponent.js +82 -106
  4. package/dist/cjs/createComponent.js.map +1 -1
  5. package/dist/cjs/createTamagui.js +0 -1
  6. package/dist/cjs/createTamagui.js.map +1 -1
  7. package/dist/cjs/helpers/ThemeManager.js +6 -5
  8. package/dist/cjs/helpers/ThemeManager.js.map +1 -1
  9. package/dist/cjs/helpers/getSplitStyles.js +78 -98
  10. package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
  11. package/dist/cjs/helpers/getStylesAtomic.js +7 -7
  12. package/dist/cjs/helpers/getStylesAtomic.js.map +1 -1
  13. package/dist/cjs/helpers/getVariantExtras.js +2 -10
  14. package/dist/cjs/helpers/getVariantExtras.js.map +1 -1
  15. package/dist/cjs/helpers/isTamaguiComponent.js +1 -1
  16. package/dist/cjs/helpers/isTamaguiComponent.js.map +1 -1
  17. package/dist/cjs/helpers/mergeProps.js +6 -14
  18. package/dist/cjs/helpers/mergeProps.js.map +1 -1
  19. package/dist/cjs/helpers/normalizeColor.js +2 -1
  20. package/dist/cjs/helpers/normalizeColor.js.map +1 -1
  21. package/dist/cjs/helpers/normalizeValueWithProperty.js +5 -56
  22. package/dist/cjs/helpers/normalizeValueWithProperty.js.map +1 -1
  23. package/dist/cjs/helpers/{createPropMapper.js → propMapper.js} +64 -139
  24. package/dist/cjs/helpers/propMapper.js.map +6 -0
  25. package/dist/cjs/helpers/pseudoDescriptors.js +0 -1
  26. package/dist/cjs/helpers/pseudoDescriptors.js.map +1 -1
  27. package/dist/cjs/helpers/useShallowSetState.js +9 -17
  28. package/dist/cjs/helpers/useShallowSetState.js.map +1 -1
  29. package/dist/cjs/helpers/withStaticProperties.js +9 -0
  30. package/dist/cjs/helpers/withStaticProperties.js.map +1 -1
  31. package/dist/cjs/hooks/useMedia.js +7 -9
  32. package/dist/cjs/hooks/useMedia.js.map +1 -1
  33. package/dist/cjs/hooks/useStyle.js +5 -2
  34. package/dist/cjs/hooks/useStyle.js.map +1 -1
  35. package/dist/cjs/hooks/useTheme.js +28 -32
  36. package/dist/cjs/hooks/useTheme.js.map +1 -1
  37. package/dist/cjs/index.js +2 -2
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/views/Stack.js +1 -4
  40. package/dist/cjs/views/Stack.js.map +1 -1
  41. package/dist/cjs/views/Theme.js +2 -2
  42. package/dist/cjs/views/Theme.js.map +1 -1
  43. package/dist/cjs/views/ThemeDebug.js +2 -2
  44. package/dist/cjs/views/ThemeDebug.js.map +1 -1
  45. package/dist/esm/constants/constants.js +14 -13
  46. package/dist/esm/constants/constants.js.map +1 -1
  47. package/dist/esm/createComponent.js +82 -106
  48. package/dist/esm/createComponent.js.map +1 -1
  49. package/dist/esm/createTamagui.js +0 -1
  50. package/dist/esm/createTamagui.js.map +1 -1
  51. package/dist/esm/helpers/ThemeManager.js +6 -5
  52. package/dist/esm/helpers/ThemeManager.js.map +1 -1
  53. package/dist/esm/helpers/getSplitStyles.js +77 -97
  54. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  55. package/dist/esm/helpers/getStylesAtomic.js +7 -7
  56. package/dist/esm/helpers/getStylesAtomic.js.map +1 -1
  57. package/dist/esm/helpers/getVariantExtras.js +2 -10
  58. package/dist/esm/helpers/getVariantExtras.js.map +1 -1
  59. package/dist/esm/helpers/isTamaguiComponent.js +1 -1
  60. package/dist/esm/helpers/isTamaguiComponent.js.map +1 -1
  61. package/dist/esm/helpers/mergeProps.js +6 -14
  62. package/dist/esm/helpers/mergeProps.js.map +1 -1
  63. package/dist/esm/helpers/normalizeColor.js +2 -1
  64. package/dist/esm/helpers/normalizeColor.js.map +1 -1
  65. package/dist/esm/helpers/normalizeValueWithProperty.js +5 -56
  66. package/dist/esm/helpers/normalizeValueWithProperty.js.map +1 -1
  67. package/dist/esm/helpers/{createPropMapper.js → propMapper.js} +57 -132
  68. package/dist/esm/helpers/propMapper.js.map +6 -0
  69. package/dist/esm/helpers/pseudoDescriptors.js +0 -1
  70. package/dist/esm/helpers/pseudoDescriptors.js.map +1 -1
  71. package/dist/esm/helpers/useShallowSetState.js +9 -17
  72. package/dist/esm/helpers/useShallowSetState.js.map +1 -1
  73. package/dist/esm/helpers/withStaticProperties.js +9 -0
  74. package/dist/esm/helpers/withStaticProperties.js.map +1 -1
  75. package/dist/esm/hooks/useMedia.js +8 -10
  76. package/dist/esm/hooks/useMedia.js.map +1 -1
  77. package/dist/esm/hooks/useStyle.js +5 -2
  78. package/dist/esm/hooks/useStyle.js.map +1 -1
  79. package/dist/esm/hooks/useTheme.js +28 -32
  80. package/dist/esm/hooks/useTheme.js.map +1 -1
  81. package/dist/esm/index.js +1 -1
  82. package/dist/esm/index.js.map +1 -1
  83. package/dist/esm/views/Stack.js +1 -4
  84. package/dist/esm/views/Stack.js.map +1 -1
  85. package/dist/esm/views/Theme.js +2 -2
  86. package/dist/esm/views/Theme.js.map +1 -1
  87. package/dist/esm/views/ThemeDebug.js +2 -2
  88. package/dist/esm/views/ThemeDebug.js.map +1 -1
  89. package/package.json +9 -9
  90. package/src/constants/constants.ts +15 -11
  91. package/src/createComponent.tsx +142 -140
  92. package/src/createTamagui.ts +0 -1
  93. package/src/helpers/ThemeManager.tsx +10 -6
  94. package/src/helpers/getSplitStyles.tsx +144 -173
  95. package/src/helpers/getStylesAtomic.ts +7 -7
  96. package/src/helpers/getVariantExtras.tsx +15 -31
  97. package/src/helpers/isTamaguiComponent.tsx +3 -3
  98. package/src/helpers/mergeProps.ts +5 -20
  99. package/src/helpers/normalizeColor.ts +2 -1
  100. package/src/helpers/normalizeValueWithProperty.ts +8 -64
  101. package/src/helpers/{createPropMapper.ts → propMapper.ts} +72 -164
  102. package/src/helpers/pseudoDescriptors.ts +0 -1
  103. package/src/helpers/useShallowSetState.tsx +10 -16
  104. package/src/helpers/withStaticProperties.tsx +13 -0
  105. package/src/hooks/useMedia.tsx +15 -10
  106. package/src/hooks/useStyle.tsx +7 -4
  107. package/src/hooks/useTheme.tsx +36 -47
  108. package/src/index.ts +1 -1
  109. package/src/types.tsx +20 -33
  110. package/src/views/Stack.tsx +1 -4
  111. package/src/views/Theme.tsx +3 -3
  112. package/src/views/ThemeDebug.tsx +2 -2
  113. package/types/constants/constants.d.ts +0 -15
  114. package/types/constants/constants.d.ts.map +1 -1
  115. package/types/createComponent.d.ts +5 -8
  116. package/types/createComponent.d.ts.map +1 -1
  117. package/types/createTamagui.d.ts.map +1 -1
  118. package/types/helpers/ThemeManager.d.ts +1 -1
  119. package/types/helpers/ThemeManager.d.ts.map +1 -1
  120. package/types/helpers/getSplitStyles.d.ts +3 -7
  121. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  122. package/types/helpers/getVariantExtras.d.ts +1 -1
  123. package/types/helpers/getVariantExtras.d.ts.map +1 -1
  124. package/types/helpers/isTamaguiComponent.d.ts.map +1 -1
  125. package/types/helpers/mergeProps.d.ts +1 -1
  126. package/types/helpers/mergeProps.d.ts.map +1 -1
  127. package/types/helpers/normalizeColor.d.ts.map +1 -1
  128. package/types/helpers/normalizeValueWithProperty.d.ts.map +1 -1
  129. package/types/helpers/{createPropMapper.d.ts → propMapper.d.ts} +3 -3
  130. package/types/helpers/propMapper.d.ts.map +1 -0
  131. package/types/helpers/pseudoDescriptors.d.ts.map +1 -1
  132. package/types/helpers/useShallowSetState.d.ts.map +1 -1
  133. package/types/helpers/withStaticProperties.d.ts.map +1 -1
  134. package/types/hooks/useMedia.d.ts.map +1 -1
  135. package/types/hooks/useStyle.d.ts +2 -2
  136. package/types/hooks/useStyle.d.ts.map +1 -1
  137. package/types/hooks/useTheme.d.ts +7 -13
  138. package/types/hooks/useTheme.d.ts.map +1 -1
  139. package/types/index.d.ts +1 -1
  140. package/types/index.d.ts.map +1 -1
  141. package/types/styled.d.ts +1 -1
  142. package/types/types.d.ts +17 -25
  143. package/types/types.d.ts.map +1 -1
  144. package/types/views/Stack.d.ts.map +1 -1
  145. package/dist/cjs/helpers/createPropMapper.js.map +0 -6
  146. package/dist/cjs/helpers/parseStaticConfig.js +0 -40
  147. package/dist/cjs/helpers/parseStaticConfig.js.map +0 -6
  148. package/dist/cjs/helpers/swapFontFaceOnWeight.js +0 -63
  149. package/dist/cjs/helpers/swapFontFaceOnWeight.js.map +0 -6
  150. package/dist/cjs/hooks/useSafeRef.js +0 -59
  151. package/dist/cjs/hooks/useSafeRef.js.map +0 -6
  152. package/dist/cjs/hooks/useServerHooks.js +0 -36
  153. package/dist/cjs/hooks/useServerHooks.js.map +0 -6
  154. package/dist/esm/helpers/createPropMapper.js.map +0 -6
  155. package/dist/esm/helpers/parseStaticConfig.js +0 -16
  156. package/dist/esm/helpers/parseStaticConfig.js.map +0 -6
  157. package/dist/esm/helpers/swapFontFaceOnWeight.js +0 -39
  158. package/dist/esm/helpers/swapFontFaceOnWeight.js.map +0 -6
  159. package/dist/esm/hooks/useSafeRef.js +0 -35
  160. package/dist/esm/hooks/useSafeRef.js.map +0 -6
  161. package/dist/esm/hooks/useServerHooks.js +0 -11
  162. package/dist/esm/hooks/useServerHooks.js.map +0 -6
  163. package/src/helpers/parseStaticConfig.ts +0 -14
  164. package/src/hooks/useSafeRef.ts +0 -45
  165. package/types/helpers/createPropMapper.d.ts.map +0 -1
  166. package/types/helpers/parseStaticConfig.d.ts +0 -3
  167. package/types/helpers/parseStaticConfig.d.ts.map +0 -1
  168. package/types/helpers/swapFontFaceOnWeight.d.ts +0 -4
  169. package/types/helpers/swapFontFaceOnWeight.d.ts.map +0 -1
  170. package/types/hooks/useSafeRef.d.ts +0 -4
  171. package/types/hooks/useSafeRef.d.ts.map +0 -1
  172. package/types/hooks/useServerHooks.d.ts +0 -4
  173. package/types/hooks/useServerHooks.d.ts.map +0 -1
@@ -3,11 +3,7 @@ import { GenericFonts, GetStyleState } from '../types'
3
3
  import { LanguageContextType } from '../views/FontLanguage.types'
4
4
  import { createProxy } from './createProxy'
5
5
 
6
- export function getVariantExtras(
7
- styleState: GetStyleState,
8
- defaultProps?: any,
9
- avoidDefaultProps = false
10
- ) {
6
+ export function getVariantExtras(styleState: GetStyleState) {
11
7
  const { curProps, conf, languageContext, theme } = styleState
12
8
  let fonts = conf.fontsParsed
13
9
  if (languageContext) {
@@ -27,32 +23,20 @@ export function getVariantExtras(
27
23
  font: fonts[fontFamily],
28
24
  // TODO do this in splitstlye
29
25
  // we avoid passing in default props for media queries because that would confuse things like SizableText.size:
30
- props: avoidDefaultProps
31
- ? curProps
32
- : createProxy(curProps, {
33
- // handles shorthands
34
- get(target, key) {
35
- const shorthand = conf.inverseShorthands[key as any]
36
- // shorthands before longhand because a styled() with longhand combined with inline shorthand
37
- // shorthand will always be the overriding key
38
- if (shorthand && Reflect.has(target, shorthand)) {
39
- return Reflect.get(target, shorthand)
40
- }
41
- if (Reflect.has(target, key)) {
42
- return Reflect.get(target, key)
43
- }
44
- // these props may be extracted into classNames, but we still want to access them
45
- // at runtime, so we proxy back to defaultProps but don't pass them
46
- if (defaultProps) {
47
- if (shorthand && Reflect.has(defaultProps, shorthand)) {
48
- return Reflect.get(defaultProps, shorthand)
49
- }
50
- if (Reflect.has(defaultProps, key)) {
51
- return Reflect.get(defaultProps, key)
52
- }
53
- }
54
- },
55
- }),
26
+ props: createProxy(curProps, {
27
+ // handles shorthands
28
+ get(target, key) {
29
+ const shorthand = conf.inverseShorthands[key as any]
30
+ // shorthands before longhand because a styled() with longhand combined with inline shorthand
31
+ // shorthand will always be the overriding key
32
+ if (shorthand && Reflect.has(target, shorthand)) {
33
+ return Reflect.get(target, shorthand)
34
+ }
35
+ if (Reflect.has(target, key)) {
36
+ return Reflect.get(target, key)
37
+ }
38
+ },
39
+ }),
56
40
  }
57
41
 
58
42
  return next as any
@@ -1,4 +1,4 @@
1
- import { StaticConfig, StaticConfigParsed } from '../types'
1
+ import { StaticConfig } from '../types'
2
2
 
3
3
  export function isTamaguiComponent<A>(
4
4
  comp: A,
@@ -6,6 +6,6 @@ export function isTamaguiComponent<A>(
6
6
  ): comp is A & {
7
7
  staticConfig: StaticConfig
8
8
  } {
9
- const config = comp?.['staticConfig'] as StaticConfigParsed | undefined
10
- return (config?.parsed && (name ? name === config.componentName : true)) || false
9
+ const config = comp?.['staticConfig'] as StaticConfig | undefined
10
+ return Boolean(config && (name ? name === config.componentName : true))
11
11
  }
@@ -16,32 +16,24 @@ import { pseudoDescriptors } from './pseudoDescriptors'
16
16
 
17
17
  type AnyRecord = Record<string, any>
18
18
 
19
- export const mergeProps = (
20
- a: Object,
21
- b?: Object,
22
- leaveOutClassNames = false,
23
- inverseShorthands?: AnyRecord
24
- ) => {
19
+ export const mergeProps = (a: Object, b?: Object, inverseShorthands?: AnyRecord) => {
25
20
  const out: AnyRecord = {}
26
- const outCns: AnyRecord = leaveOutClassNames ? {} : (null as any)
27
21
  for (const key in a) {
28
- mergeProp(out, outCns, a, b, key, leaveOutClassNames, inverseShorthands)
22
+ mergeProp(out, a, b, key, inverseShorthands)
29
23
  }
30
24
  if (b) {
31
25
  for (const key in b) {
32
- mergeProp(out, outCns, b, undefined, key, leaveOutClassNames, inverseShorthands)
26
+ mergeProp(out, b, undefined, key, inverseShorthands)
33
27
  }
34
28
  }
35
- return [out, outCns] as const
29
+ return out
36
30
  }
37
31
 
38
32
  function mergeProp(
39
33
  out: AnyRecord,
40
- outCns: AnyRecord,
41
34
  a: Object,
42
35
  b: Object | undefined,
43
36
  key: string,
44
- leaveOutClassNames: boolean,
45
37
  inverseShorthands?: AnyRecord
46
38
  ) {
47
39
  const shorthand = inverseShorthands?.[key] || null
@@ -56,12 +48,5 @@ function mergeProp(
56
48
  }
57
49
  return
58
50
  }
59
- if (shorthand) {
60
- key = shorthand
61
- }
62
- if (leaveOutClassNames && val?.[0] === '_') {
63
- outCns[key] = val
64
- } else {
65
- out[key] = val
66
- }
51
+ out[shorthand || key] = val
67
52
  }
@@ -11,7 +11,8 @@ export const normalizeColor = (color?: string | null, opacity?: number) => {
11
11
  const colorProcessed = NCC.normalizeCSSColor(color)
12
12
  if (typeof colorProcessed === 'number') {
13
13
  const { r, g, b, a } = rgba(colorProcessed)
14
- const alpha = (opacity ?? a ?? 1).toFixed(2)
14
+ const o = +(opacity ?? a ?? 1)
15
+ const alpha = o.toFixed(2)
15
16
  return `rgba(${r},${g},${b},${alpha})`
16
17
  }
17
18
  if (process.env.TAMAGUI_TARGET === 'native') {
@@ -4,82 +4,26 @@
4
4
  */
5
5
 
6
6
  import { isWeb } from '@tamagui/constants'
7
+ import { stylePropsUnitless } from '@tamagui/helpers'
7
8
 
8
9
  import { getAllSelectors } from './insertStyleRule'
9
- import { names, normalizeColor } from './normalizeColor'
10
- import { normalizeStylePropKeys } from './normalizeStylePropKeys'
11
10
 
12
- const colorCache = new Map()
11
+ // only doing this on web on native it accepts pixel values
13
12
 
14
13
  export function normalizeValueWithProperty(value: any, property?: string): any {
15
- if (property && property in unitlessNumbers) {
16
- return value
17
- }
14
+ if (!isWeb) return value
18
15
  let res = value
19
- if (property && (property in normalizeStylePropKeys || value in names)) {
20
- if (colorCache.has(value)) {
21
- return colorCache.get(value)
22
- }
23
- res = normalizeColor(value)
24
- // avoid memory pressure
25
- if (colorCache.size > 1000) {
26
- colorCache.clear()
27
- }
28
- colorCache.set(value, res)
29
- } else if (
30
- isWeb &&
31
- typeof value === 'number' &&
32
- (property === undefined ||
33
- !(property in unitlessNumbers || property in stringNumbers))
16
+ if (
17
+ (property === undefined || !(property in stylePropsUnitless)) &&
18
+ typeof value === 'number'
34
19
  ) {
35
20
  res = `${value}px`
36
- } else if (isWeb && property !== undefined && property in stringNumbers) {
21
+ } else if (property !== undefined) {
37
22
  res = `${res}`
38
23
  }
39
24
  return res
40
25
  }
41
26
 
42
- const stringNumbers = {
43
- zIndex: true,
44
- }
45
-
46
- const unitlessNumbers = {
47
- WebkitLineClamp: true,
48
- animationIterationCount: true,
49
- aspectRatio: true,
50
- borderImageOutset: true,
51
- borderImageSlice: true,
52
- borderImageWidth: true,
53
- columnCount: true,
54
- flex: true,
55
- flexGrow: true,
56
- flexOrder: true,
57
- flexPositive: true,
58
- flexShrink: true,
59
- flexNegative: true,
60
- fontWeight: true,
61
- gridRow: true,
62
- gridRowEnd: true,
63
- gridRowGap: true,
64
- gridRowStart: true,
65
- gridColumn: true,
66
- gridColumnEnd: true,
67
- gridColumnGap: true,
68
- gridColumnStart: true,
69
- lineClamp: true,
70
- opacity: true,
71
- order: true,
72
- orphans: true,
73
- tabSize: true,
74
- widows: true,
75
- zoom: true,
76
- scale: true,
77
- scaleX: true,
78
- scaleY: true,
79
- scaleZ: true,
80
- shadowOpacity: true,
81
- }
82
-
83
27
  // getting real values for colors for animations (reverse mapped from CSS)
84
28
  // this isn't beautiful, but will do relatively fine performance for now
85
29
  const rcache = {}
@@ -102,7 +46,7 @@ export function reverseMapClassNameToValue(key: string, className: string) {
102
46
  let res: any
103
47
  if (cssVal.startsWith('var(')) {
104
48
  res = cssVal
105
- } else if (unitlessNumbers[key]) {
49
+ } else if (stylePropsUnitless[key]) {
106
50
  res = +cssVal
107
51
  } else if (cssVal.endsWith('px')) {
108
52
  res = +cssVal.replace('px', '')
@@ -1,12 +1,12 @@
1
1
  import { isAndroid, isWeb } from '@tamagui/constants'
2
+ import { tokenCategories } from '@tamagui/helpers'
2
3
 
3
4
  import { isDevTools } from '../constants/isDevTools'
4
5
  import { Variable, getVariableValue, isVariable } from '../createVariable'
5
6
  import type {
6
- DebugProp,
7
7
  GetStyleState,
8
8
  PropMapper,
9
- StaticConfigParsed,
9
+ SplitStyleProps,
10
10
  StyleResolver,
11
11
  TamaguiInternalConfig,
12
12
  VariantSpreadFunction,
@@ -15,99 +15,78 @@ import { expandStyle } from './expandStyle'
15
15
  import { expandStylesAndRemoveNullishValues } from './expandStyles'
16
16
  import { getFontsForLanguage, getVariantExtras } from './getVariantExtras'
17
17
  import { isObj } from './isObj'
18
- import { mergeProps } from './mergeProps'
19
18
  import { pseudoDescriptors } from './pseudoDescriptors'
20
19
 
21
20
  export type ResolveVariableTypes = 'auto' | 'value' | 'variable' | 'both'
22
21
 
23
- export const createPropMapper = (staticConfig: StaticConfigParsed) => {
24
- // temp remove classnames
25
- const defaultProps = mergeProps(staticConfig.defaultProps || {}, {}, false)[0]
26
-
27
- const mapper: PropMapper = (
28
- key,
29
- value,
30
- styleStateIn,
31
- subPropsIn,
32
- avoidDefaultProps = false
33
- ) => {
34
- if (!(process.env.TAMAGUI_TARGET === 'native' && isAndroid)) {
35
- if (key === 'elevationAndroid') return
36
- }
22
+ export const propMapper: PropMapper = (key, value, styleStateIn, subPropsIn) => {
23
+ if (!(process.env.TAMAGUI_TARGET === 'native' && isAndroid)) {
24
+ // this shouldnt be necessary and handled in the outer loop
25
+ if (key === 'elevationAndroid') return
26
+ }
37
27
 
38
- // we use this for the sub-props like pseudos so we need to overwrite the "props" in styleState
39
- // fallbackProps is awkward thanks to static
40
- // also we need to override the props here because subStyles pass in a sub-style props object
41
- const subProps = styleStateIn.state.fallbackProps || subPropsIn
42
- const styleState = subProps
43
- ? {
44
- ...styleStateIn,
45
- curProps: subProps,
46
- }
47
- : styleStateIn
28
+ // we use this for the sub-props like pseudos so we need to overwrite the "props" in styleState
29
+ // fallbackProps is awkward thanks to static
30
+ // also we need to override the props here because subStyles pass in a sub-style props object
31
+ const subProps = styleStateIn.styleProps.fallbackProps || subPropsIn
48
32
 
49
- const { conf, state, fontFamily } = styleState
50
- const returnVariablesAs = state.resolveVariablesAs === 'value' ? 'value' : 'auto'
33
+ const styleState = subProps
34
+ ? new Proxy(styleStateIn, {
35
+ get(_, k) {
36
+ return k === 'curProps' ? subProps : Reflect.get(_, k)
37
+ },
38
+ })
39
+ : styleStateIn
40
+
41
+ const { conf, styleProps, fontFamily, staticConfig } = styleState
42
+ const { variants } = staticConfig
51
43
 
44
+ // prettier-ignore
45
+ if (process.env.NODE_ENV === 'development' && fontFamily && fontFamily[0] === '$' && !(fontFamily in conf.fontsParsed)) {
52
46
  // prettier-ignore
53
- if (process.env.NODE_ENV === 'development' && fontFamily && fontFamily[0] === '$' && !(fontFamily in conf.fontsParsed)) {
54
- // prettier-ignore
55
- console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(', ')}`)
56
- }
47
+ console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(', ')}`)
48
+ }
57
49
 
58
- const variantValue = resolveVariants(
59
- key,
60
- value,
61
- styleState,
62
- defaultProps,
63
- returnVariablesAs,
64
- '',
65
- avoidDefaultProps
66
- )
50
+ if (variants && key in variants && value != null) {
51
+ styleState.curProps[key] = value
67
52
 
53
+ const variantValue = resolveVariants(key, value, styleProps, styleState, '')
68
54
  if (variantValue) {
69
55
  return variantValue
70
56
  }
57
+ }
71
58
 
72
- let shouldReturn = false
73
-
74
- // handle shorthands
75
- if (key in conf.shorthands) {
76
- shouldReturn = true
77
- key = conf.shorthands[key]
78
- }
59
+ let shouldReturn = false
79
60
 
80
- if (value) {
81
- if (value[0] === '$') {
82
- value = getToken(key, value, styleState, returnVariablesAs)
83
- } else if (isVariable(value)) {
84
- value = resolveVariableValue(key, value, returnVariablesAs)
85
- }
86
- }
61
+ // handle shorthands
62
+ if (key in conf.shorthands) {
63
+ shouldReturn = true
64
+ key = conf.shorthands[key]
65
+ }
87
66
 
88
- if (shouldReturn || value != null) {
89
- return expandStyle(key, value) || [[key, value]]
67
+ if (value) {
68
+ if (value[0] === '$') {
69
+ value = getToken(key, value, styleProps, styleState)
70
+ } else if (isVariable(value)) {
71
+ value = resolveVariableValue(value, styleProps)
90
72
  }
91
73
  }
92
74
 
93
- return mapper
75
+ if (shouldReturn || value != null) {
76
+ return expandStyle(key, value) || [[key, value]]
77
+ }
94
78
  }
95
79
 
96
80
  const resolveVariants: StyleResolver = (
97
81
  key,
98
82
  value,
83
+ styleProps,
99
84
  styleState,
100
- defaultProps,
101
- returnVariablesAs,
102
- parentVariantKey,
103
- avoidDefaultProps = false
85
+ parentVariantKey
104
86
  ) => {
105
87
  const { staticConfig, conf, debug } = styleState
106
88
  const { variants } = staticConfig
107
-
108
- if (!variants || !(key in variants) || value == null) {
109
- return
110
- }
89
+ if (!variants) return
111
90
 
112
91
  let variantValue = getVariantDefinition(variants[key], key, value, conf)
113
92
 
@@ -142,10 +121,7 @@ const resolveVariants: StyleResolver = (
142
121
  if (typeof variantValue === 'function') {
143
122
  const fn = variantValue as VariantSpreadFunction<any>
144
123
 
145
- variantValue = fn(
146
- value,
147
- getVariantExtras(styleState, defaultProps, avoidDefaultProps)
148
- )
124
+ variantValue = fn(value, getVariantExtras(styleState))
149
125
 
150
126
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
151
127
  console.groupCollapsed(' expanded functional variant', key)
@@ -155,23 +131,6 @@ const resolveVariants: StyleResolver = (
155
131
  }
156
132
  }
157
133
 
158
- // update curProps for variants expanded:
159
- if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
160
- // rome-ignore lint/nursery/noConsoleLog: <explanation>
161
- console.log(` attaching updated curProps`, {
162
- new: variantValue,
163
- before: styleState.curProps,
164
- after: {
165
- ...styleState.curProps,
166
- ...variantValue,
167
- },
168
- })
169
- }
170
- styleState.curProps = {
171
- ...styleState.curProps,
172
- ...variantValue,
173
- }
174
-
175
134
  let fontFamilyResult: any
176
135
 
177
136
  if (isObj(variantValue)) {
@@ -191,11 +150,9 @@ const resolveVariants: StyleResolver = (
191
150
  variantValue = resolveTokensAndVariants(
192
151
  key,
193
152
  variantValue,
153
+ styleProps,
194
154
  styleState,
195
- defaultProps,
196
- returnVariablesAs,
197
- parentVariantKey,
198
- avoidDefaultProps
155
+ parentVariantKey
199
156
  )
200
157
  }
201
158
 
@@ -228,7 +185,7 @@ export function getFontFamilyFromNameOrVariable(input: any, conf: TamaguiInterna
228
185
  }
229
186
  }
230
187
  } else if (typeof input === 'string') {
231
- if (input?.[0] === '$') {
188
+ if (input[0] === '$') {
232
189
  return input
233
190
  }
234
191
  }
@@ -245,11 +202,9 @@ export const getPropMappedFontFamily = (expanded?: any) => {
245
202
  const resolveTokensAndVariants: StyleResolver<Object> = (
246
203
  key, // we dont use key assume value is object instead
247
204
  value,
205
+ styleProps,
248
206
  styleState,
249
- defaultProps,
250
- returnVariablesAs,
251
- parentVariantKey,
252
- avoidDefaultProps
207
+ parentVariantKey
253
208
  ) => {
254
209
  const { conf, staticConfig, debug, theme } = styleState
255
210
  const { variants } = staticConfig
@@ -265,22 +220,17 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
265
220
  const val = value[rKey]
266
221
 
267
222
  if (variants && fKey in variants) {
223
+ // if its a variant expanded, attach to curProps
224
+ styleState.curProps[fKey] = val
225
+
268
226
  // avoids infinite loop if variant is matching a style prop
269
227
  // eg: { variants: { flex: { true: { flex: 2 } } } }
270
228
  if (parentVariantKey && parentVariantKey === key) {
271
229
  res[fKey] =
272
230
  // SYNC WITH *1
273
- val[0] === '$' ? getToken(fKey, val, styleState, returnVariablesAs) : val
231
+ val[0] === '$' ? getToken(fKey, val, styleProps, styleState) : val
274
232
  } else {
275
- const variantOut = resolveVariants(
276
- fKey,
277
- val,
278
- styleState,
279
- defaultProps,
280
- returnVariablesAs,
281
- key,
282
- avoidDefaultProps
283
- )
233
+ const variantOut = resolveVariants(fKey, val, styleProps, styleState, key)
284
234
 
285
235
  // apply, merging sub-styles
286
236
  if (variantOut) {
@@ -299,28 +249,20 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
299
249
  }
300
250
 
301
251
  if (isVariable(val)) {
302
- res[fKey] = !isWeb || returnVariablesAs === 'value' ? val.val : val.variable
252
+ res[fKey] = resolveVariableValue(val, styleProps)
303
253
  continue
304
254
  }
305
255
 
306
256
  if (typeof val === 'string') {
307
257
  const fVal =
308
258
  // SYNC WITH *1
309
- val[0] === '$' ? getToken(fKey, val, styleState, returnVariablesAs) : val
259
+ val[0] === '$' ? getToken(fKey, val, styleProps, styleState) : val
310
260
  res[fKey] = fVal
311
261
  continue
312
262
  }
313
263
 
314
264
  if (isObj(val)) {
315
- const subObject = resolveTokensAndVariants(
316
- fKey,
317
- val,
318
- styleState,
319
- defaultProps,
320
- returnVariablesAs,
321
- key,
322
- avoidDefaultProps
323
- )
265
+ const subObject = resolveTokensAndVariants(fKey, val, styleProps, styleState, key)
324
266
 
325
267
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
326
268
  // rome-ignore lint/nursery/noConsoleLog: <explanation>
@@ -387,9 +329,8 @@ const fontShorthand = {
387
329
  const getToken = (
388
330
  key: string,
389
331
  value: string,
390
- styleState: GetStyleState,
391
- resolveAs?: ResolveVariableTypes,
392
- debug?: DebugProp
332
+ styleProps: SplitStyleProps,
333
+ styleState: GetStyleState
393
334
  ) => {
394
335
  const { theme, conf, languageContext, fontFamily } = styleState
395
336
 
@@ -397,7 +338,7 @@ const getToken = (
397
338
  let valOrVar: any
398
339
  let hasSet = false
399
340
  if (value in theme) {
400
- if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
341
+ if (process.env.NODE_ENV === 'development' && styleState.debug === 'verbose') {
401
342
  // rome-ignore lint/nursery/noConsoleLog: <explanation>
402
343
  console.log(` - getting theme value for ${key} from ${value} = ${theme[value].val}`)
403
344
  }
@@ -453,14 +394,18 @@ const getToken = (
453
394
  }
454
395
 
455
396
  if (hasSet) {
456
- const out = resolveVariableValue(key, valOrVar, resolveAs)
397
+ const out = resolveVariableValue(valOrVar, styleProps)
457
398
  return out
458
399
  }
459
400
 
460
- if (process.env.NODE_ENV === 'development' && isDevTools && debug === 'verbose') {
401
+ if (
402
+ process.env.NODE_ENV === 'development' &&
403
+ isDevTools &&
404
+ styleState.debug === 'verbose'
405
+ ) {
461
406
  console.groupCollapsed(' ﹒ propMap (val)', key, value)
462
407
  // rome-ignore lint/nursery/noConsoleLog: ok
463
- console.log({ valOrVar, theme, hasSet, resolveAs }, theme[key])
408
+ console.log({ valOrVar, theme, hasSet }, theme[key])
464
409
  console.groupEnd()
465
410
  }
466
411
 
@@ -468,51 +413,14 @@ const getToken = (
468
413
  }
469
414
 
470
415
  function resolveVariableValue(
471
- key: string,
472
416
  valOrVar: Variable | any,
473
- resolveAs: ResolveVariableTypes = 'auto'
417
+ { resolveVariablesAs }: SplitStyleProps
474
418
  ) {
475
419
  if (isVariable(valOrVar)) {
476
- if (resolveAs === 'variable') {
477
- return valOrVar
478
- }
479
- if (!isWeb || resolveAs === 'value') {
420
+ if (!isWeb || resolveVariablesAs === 'value') {
480
421
  return valOrVar.val
481
422
  }
482
423
  return valOrVar.variable
483
424
  }
484
425
  return valOrVar
485
426
  }
486
-
487
- // TODO move to validStyleProps to merge
488
-
489
- // just specificy the least costly, all else go to `space` (most keys - we can exclude)
490
- const tokenCategories = {
491
- radius: {
492
- borderRadius: true,
493
- borderTopLeftRadius: true,
494
- borderTopRightRadius: true,
495
- borderBottomLeftRadius: true,
496
- borderBottomRightRadius: true,
497
- },
498
- size: {
499
- width: true,
500
- height: true,
501
- minWidth: true,
502
- minHeight: true,
503
- maxWidth: true,
504
- maxHeight: true,
505
- },
506
- zIndex: {
507
- zIndex: true,
508
- },
509
- color: {
510
- color: true,
511
- backgroundColor: true,
512
- borderColor: true,
513
- borderBottomColor: true,
514
- borderTopColor: true,
515
- borderLeftColor: true,
516
- borderRightColor: true,
517
- },
518
- }
@@ -24,7 +24,6 @@ export const pseudoDescriptors: Record<
24
24
  },
25
25
  exitStyle: {
26
26
  name: 'exit',
27
- stateKey: 'isExiting',
28
27
  priority: 5,
29
28
  },
30
29
  }
@@ -7,20 +7,14 @@ export function useShallowSetState<State extends TamaguiComponentState>(
7
7
  debug?: DebugProp,
8
8
  debugName?: string
9
9
  ) {
10
- return useCallback(
11
- (next: Partial<State>) => {
12
- setter((prev) => {
13
- for (const key in next) {
14
- if (prev[key] !== next[key]) {
15
- if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
16
- console.warn(` setState ${debugName}`, next)
17
- }
18
- return { ...prev, ...next }
19
- }
20
- }
21
- return prev
22
- })
23
- },
24
- [setter]
25
- )
10
+ return (next: Partial<State>) => setter((prev) => shallow(prev, next))
11
+ }
12
+
13
+ function shallow(prev, next) {
14
+ for (const key in next) {
15
+ if (prev[key] !== next[key]) {
16
+ return { ...prev, ...next }
17
+ }
18
+ }
19
+ return prev
26
20
  }
@@ -1,9 +1,22 @@
1
+ const WarnReAssignSymbol = Symbol()
2
+
1
3
  export const withStaticProperties = function <A extends Function, B>(
2
4
  component: A,
3
5
  staticProps: B
4
6
  ): A & B {
5
7
  // clone if object to stay immutable
6
8
  const next = typeof component === 'function' ? component : { ...(component as any) }
9
+
10
+ // nice dev helper that avoids super confusing errors
11
+ if (process.env.NODE_ENV === 'development') {
12
+ if (next[WarnReAssignSymbol]) {
13
+ throw new Error(
14
+ `Error: You're calling withStaticProperties() on a component that already has withStaticProperties() assigned to it! This will cause super strange errors.`
15
+ )
16
+ }
17
+ next[WarnReAssignSymbol] = true
18
+ }
19
+
7
20
  Object.assign(next, staticProps)
8
21
  return next as A & B
9
22
  }