@tamagui/web 3.0.0-beta.807.1 → 3.0.0-beta.831.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 (266) hide show
  1. package/dist/cjs/config.cjs +1 -1
  2. package/dist/cjs/config.native.cjs +1 -1
  3. package/dist/cjs/config.native.js +1 -1
  4. package/dist/cjs/config.native.js.map +1 -1
  5. package/dist/cjs/createComponent.cjs +28 -18
  6. package/dist/cjs/createComponent.native.cjs +30 -20
  7. package/dist/cjs/createComponent.native.js +30 -20
  8. package/dist/cjs/createComponent.native.js.map +1 -1
  9. package/dist/cjs/createStyledHOC.cjs +54 -4
  10. package/dist/cjs/createStyledHOC.native.cjs +55 -4
  11. package/dist/cjs/createStyledHOC.native.js +55 -4
  12. package/dist/cjs/createStyledHOC.native.js.map +1 -1
  13. package/dist/cjs/createTokens.cjs +1 -1
  14. package/dist/cjs/createTokens.native.cjs +1 -1
  15. package/dist/cjs/createTokens.native.js +1 -1
  16. package/dist/cjs/createTokens.native.js.map +1 -1
  17. package/dist/cjs/dom/html.cjs +147 -99
  18. package/dist/cjs/dom/htmlRuntime.native.cjs +6 -2
  19. package/dist/cjs/dom/htmlRuntime.native.js +6 -2
  20. package/dist/cjs/dom/htmlRuntime.native.js.map +1 -1
  21. package/dist/cjs/dom/primitives.native.cjs +16 -13
  22. package/dist/cjs/dom/primitives.native.js +16 -13
  23. package/dist/cjs/dom/primitives.native.js.map +1 -1
  24. package/dist/cjs/helpers/componentDisplayName.cjs +1 -11
  25. package/dist/cjs/helpers/componentDisplayName.native.cjs +1 -11
  26. package/dist/cjs/helpers/componentDisplayName.native.js +1 -11
  27. package/dist/cjs/helpers/componentDisplayName.native.js.map +1 -1
  28. package/dist/cjs/helpers/directStyleCSS.cjs +101 -104
  29. package/dist/cjs/helpers/formatDiagnostic.cjs +2 -4
  30. package/dist/cjs/helpers/formatDiagnostic.native.cjs +2 -4
  31. package/dist/cjs/helpers/formatDiagnostic.native.js +2 -4
  32. package/dist/cjs/helpers/formatDiagnostic.native.js.map +1 -1
  33. package/dist/cjs/helpers/getCSSStylesAtomic.cjs +10 -10
  34. package/dist/cjs/helpers/getSplitStyles.cjs +168 -600
  35. package/dist/cjs/helpers/getSplitStyles.native.cjs +168 -762
  36. package/dist/cjs/helpers/getSplitStyles.native.js +168 -762
  37. package/dist/cjs/helpers/getSplitStyles.native.js.map +1 -1
  38. package/dist/cjs/helpers/splitStyleProps.cjs +46 -0
  39. package/dist/cjs/helpers/splitStyleProps.native.cjs +49 -0
  40. package/dist/cjs/helpers/splitStyleProps.native.js +51 -0
  41. package/dist/cjs/helpers/splitStyleProps.native.js.map +1 -0
  42. package/dist/cjs/helpers/styleStaticConfig.cjs +76 -0
  43. package/dist/cjs/helpers/styleStaticConfig.native.cjs +79 -0
  44. package/dist/cjs/helpers/styleStaticConfig.native.js +81 -0
  45. package/dist/cjs/helpers/styleStaticConfig.native.js.map +1 -0
  46. package/dist/cjs/helpers/tokenCategories.cjs +32 -71
  47. package/dist/cjs/helpers/tokenCategories.native.cjs +34 -73
  48. package/dist/cjs/helpers/tokenCategories.native.js +34 -73
  49. package/dist/cjs/helpers/tokenCategories.native.js.map +1 -1
  50. package/dist/cjs/helpers/variantResolvers.cjs +87 -0
  51. package/dist/cjs/helpers/variantResolvers.native.cjs +140 -0
  52. package/dist/cjs/helpers/variantResolvers.native.js +142 -0
  53. package/dist/cjs/helpers/variantResolvers.native.js.map +1 -0
  54. package/dist/cjs/hooks/useSplitStyles.cjs +2 -2
  55. package/dist/cjs/hooks/useSplitStyles.native.cjs +2 -2
  56. package/dist/cjs/hooks/useSplitStyles.native.js +2 -2
  57. package/dist/cjs/hooks/useSplitStyles.native.js.map +1 -1
  58. package/dist/cjs/index.cjs +3 -9
  59. package/dist/cjs/index.native.cjs +3 -9
  60. package/dist/cjs/index.native.js +3 -9
  61. package/dist/cjs/index.native.js.map +1 -1
  62. package/dist/cjs/internal-runtime.cjs +8 -7
  63. package/dist/cjs/internal-runtime.native.cjs +8 -7
  64. package/dist/cjs/internal-runtime.native.js +8 -7
  65. package/dist/cjs/internal-runtime.native.js.map +1 -1
  66. package/dist/cjs/static-resolve.cjs +6 -5
  67. package/dist/cjs/static-resolve.native.cjs +6 -5
  68. package/dist/cjs/static-resolve.native.js +6 -5
  69. package/dist/cjs/static-resolve.native.js.map +1 -1
  70. package/dist/cjs/styled.cjs +4 -56
  71. package/dist/cjs/styled.native.cjs +4 -58
  72. package/dist/cjs/styled.native.js +4 -58
  73. package/dist/cjs/styled.native.js.map +1 -1
  74. package/dist/cjs/types.cjs +1 -21
  75. package/dist/cjs/types.native.cjs +1 -21
  76. package/dist/cjs/types.native.js +1 -21
  77. package/dist/cjs/types.native.js.map +1 -1
  78. package/dist/cjs/views/Text.cjs +4 -2
  79. package/dist/cjs/views/Text.native.cjs +4 -2
  80. package/dist/cjs/views/Text.native.js +4 -2
  81. package/dist/cjs/views/Text.native.js.map +1 -1
  82. package/dist/cjs/views/View.cjs +4 -2
  83. package/dist/cjs/views/View.native.cjs +4 -2
  84. package/dist/cjs/views/View.native.js +4 -2
  85. package/dist/cjs/views/View.native.js.map +1 -1
  86. package/dist/esm/config.mjs +1 -1
  87. package/dist/esm/config.mjs.map +1 -1
  88. package/dist/esm/config.native.js +1 -1
  89. package/dist/esm/config.native.js.map +1 -1
  90. package/dist/esm/createComponent.mjs +29 -19
  91. package/dist/esm/createComponent.mjs.map +1 -1
  92. package/dist/esm/createComponent.native.js +31 -21
  93. package/dist/esm/createComponent.native.js.map +1 -1
  94. package/dist/esm/createStyledHOC.mjs +55 -5
  95. package/dist/esm/createStyledHOC.mjs.map +1 -1
  96. package/dist/esm/createStyledHOC.native.js +56 -5
  97. package/dist/esm/createStyledHOC.native.js.map +1 -1
  98. package/dist/esm/createTokens.mjs +1 -1
  99. package/dist/esm/createTokens.mjs.map +1 -1
  100. package/dist/esm/createTokens.native.js +1 -1
  101. package/dist/esm/createTokens.native.js.map +1 -1
  102. package/dist/esm/dom/html.mjs +147 -99
  103. package/dist/esm/dom/html.mjs.map +1 -1
  104. package/dist/esm/dom/htmlRuntime.native.js +7 -3
  105. package/dist/esm/dom/htmlRuntime.native.js.map +1 -1
  106. package/dist/esm/dom/primitives.native.js +16 -13
  107. package/dist/esm/dom/primitives.native.js.map +1 -1
  108. package/dist/esm/helpers/componentDisplayName.mjs +1 -8
  109. package/dist/esm/helpers/componentDisplayName.mjs.map +1 -1
  110. package/dist/esm/helpers/componentDisplayName.native.js +1 -8
  111. package/dist/esm/helpers/componentDisplayName.native.js.map +1 -1
  112. package/dist/esm/helpers/directStyleCSS.mjs +101 -104
  113. package/dist/esm/helpers/directStyleCSS.mjs.map +1 -1
  114. package/dist/esm/helpers/formatDiagnostic.mjs +2 -4
  115. package/dist/esm/helpers/formatDiagnostic.mjs.map +1 -1
  116. package/dist/esm/helpers/formatDiagnostic.native.js +2 -4
  117. package/dist/esm/helpers/formatDiagnostic.native.js.map +1 -1
  118. package/dist/esm/helpers/getCSSStylesAtomic.mjs +10 -10
  119. package/dist/esm/helpers/getCSSStylesAtomic.mjs.map +1 -1
  120. package/dist/esm/helpers/getSplitStyles.mjs +166 -594
  121. package/dist/esm/helpers/getSplitStyles.mjs.map +1 -1
  122. package/dist/esm/helpers/getSplitStyles.native.js +166 -757
  123. package/dist/esm/helpers/getSplitStyles.native.js.map +1 -1
  124. package/dist/esm/helpers/splitStyleProps.mjs +27 -0
  125. package/dist/esm/helpers/splitStyleProps.mjs.map +1 -0
  126. package/dist/esm/helpers/splitStyleProps.native.js +28 -0
  127. package/dist/esm/helpers/splitStyleProps.native.js.map +1 -0
  128. package/dist/esm/helpers/styleStaticConfig.mjs +57 -0
  129. package/dist/esm/helpers/styleStaticConfig.mjs.map +1 -0
  130. package/dist/esm/helpers/styleStaticConfig.native.js +58 -0
  131. package/dist/esm/helpers/styleStaticConfig.native.js.map +1 -0
  132. package/dist/esm/helpers/tokenCategories.mjs +33 -72
  133. package/dist/esm/helpers/tokenCategories.mjs.map +1 -1
  134. package/dist/esm/helpers/tokenCategories.native.js +35 -74
  135. package/dist/esm/helpers/tokenCategories.native.js.map +1 -1
  136. package/dist/esm/helpers/variantResolvers.mjs +65 -0
  137. package/dist/esm/helpers/variantResolvers.mjs.map +1 -0
  138. package/dist/esm/helpers/variantResolvers.native.js +116 -0
  139. package/dist/esm/helpers/variantResolvers.native.js.map +1 -0
  140. package/dist/esm/hooks/useSplitStyles.mjs +2 -2
  141. package/dist/esm/hooks/useSplitStyles.mjs.map +1 -1
  142. package/dist/esm/hooks/useSplitStyles.native.js +2 -2
  143. package/dist/esm/hooks/useSplitStyles.native.js.map +1 -1
  144. package/dist/esm/index.js +3 -5
  145. package/dist/esm/index.mjs +3 -5
  146. package/dist/esm/index.native.js +3 -5
  147. package/dist/esm/internal-runtime.mjs +8 -7
  148. package/dist/esm/internal-runtime.mjs.map +1 -1
  149. package/dist/esm/internal-runtime.native.js +8 -7
  150. package/dist/esm/internal-runtime.native.js.map +1 -1
  151. package/dist/esm/static-resolve.mjs +8 -6
  152. package/dist/esm/static-resolve.mjs.map +1 -1
  153. package/dist/esm/static-resolve.native.js +8 -6
  154. package/dist/esm/static-resolve.native.js.map +1 -1
  155. package/dist/esm/styled.mjs +6 -57
  156. package/dist/esm/styled.mjs.map +1 -1
  157. package/dist/esm/styled.native.js +6 -59
  158. package/dist/esm/styled.native.js.map +1 -1
  159. package/dist/esm/types.mjs +1 -18
  160. package/dist/esm/types.mjs.map +1 -1
  161. package/dist/esm/types.native.js +1 -18
  162. package/dist/esm/types.native.js.map +1 -1
  163. package/dist/esm/views/Text.mjs +4 -2
  164. package/dist/esm/views/Text.mjs.map +1 -1
  165. package/dist/esm/views/Text.native.js +4 -2
  166. package/dist/esm/views/Text.native.js.map +1 -1
  167. package/dist/esm/views/View.mjs +4 -2
  168. package/dist/esm/views/View.mjs.map +1 -1
  169. package/dist/esm/views/View.native.js +4 -2
  170. package/dist/esm/views/View.native.js.map +1 -1
  171. package/package.json +15 -15
  172. package/src/config.ts +1 -1
  173. package/src/createComponent.tsx +41 -30
  174. package/src/createStyledHOC.tsx +56 -9
  175. package/src/createTokens.ts +1 -1
  176. package/src/dom/html.tsx +778 -877
  177. package/src/dom/htmlRuntime.native.tsx +7 -3
  178. package/src/dom/primitives.native.tsx +30 -39
  179. package/src/helpers/componentDisplayName.ts +0 -11
  180. package/src/helpers/directStyleCSS.ts +91 -112
  181. package/src/helpers/formatDiagnostic.ts +2 -4
  182. package/src/helpers/getCSSStylesAtomic.ts +32 -26
  183. package/src/helpers/getSplitStyles.tsx +315 -1119
  184. package/src/helpers/getVariantExtras.tsx +3 -3
  185. package/src/helpers/splitStyleProps.ts +166 -0
  186. package/src/helpers/styleFrontend.ts +8 -4
  187. package/src/helpers/styleStaticConfig.ts +88 -0
  188. package/src/helpers/tokenCategories.ts +62 -93
  189. package/src/helpers/variantResolvers.ts +121 -0
  190. package/src/hooks/useSplitStyles.tsx +17 -2
  191. package/src/hooks/useTheme.tsx +1 -1
  192. package/src/index.ts +8 -4
  193. package/src/internal-runtime.ts +10 -9
  194. package/src/static-resolve.ts +18 -14
  195. package/src/styled.tsx +7 -264
  196. package/src/types.tsx +19 -40
  197. package/src/views/Text.tsx +6 -7
  198. package/src/views/View.tsx +6 -7
  199. package/types/createComponent.d.ts.map +1 -1
  200. package/types/createStyledHOC.d.ts.map +1 -1
  201. package/types/dom/html.d.ts.map +1 -1
  202. package/types/dom/htmlRuntime.native.d.ts.map +1 -1
  203. package/types/dom/primitives.native.d.ts.map +1 -1
  204. package/types/helpers/componentDisplayName.d.ts +0 -3
  205. package/types/helpers/componentDisplayName.d.ts.map +1 -1
  206. package/types/helpers/directStyleCSS.d.ts.map +1 -1
  207. package/types/helpers/formatDiagnostic.d.ts.map +1 -1
  208. package/types/helpers/getCSSStylesAtomic.d.ts +17 -15
  209. package/types/helpers/getCSSStylesAtomic.d.ts.map +1 -1
  210. package/types/helpers/getSplitStyles.d.ts +6 -6
  211. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  212. package/types/helpers/splitStyleProps.d.ts +44 -0
  213. package/types/helpers/splitStyleProps.d.ts.map +1 -0
  214. package/types/helpers/styleFrontend.d.ts +4 -4
  215. package/types/helpers/styleFrontend.d.ts.map +1 -1
  216. package/types/helpers/styleStaticConfig.d.ts +19 -0
  217. package/types/helpers/styleStaticConfig.d.ts.map +1 -0
  218. package/types/helpers/tokenCategories.d.ts +1 -1
  219. package/types/helpers/tokenCategories.d.ts.map +1 -1
  220. package/types/helpers/variantResolvers.d.ts +9 -0
  221. package/types/helpers/variantResolvers.d.ts.map +1 -0
  222. package/types/hooks/useSplitStyles.d.ts.map +1 -1
  223. package/types/index.d.ts +2 -4
  224. package/types/index.d.ts.map +1 -1
  225. package/types/internal-runtime.d.ts.map +1 -1
  226. package/types/static-resolve.d.ts +2 -2
  227. package/types/static-resolve.d.ts.map +1 -1
  228. package/types/styled.d.ts +3 -39
  229. package/types/styled.d.ts.map +1 -1
  230. package/types/types.d.ts +2 -12
  231. package/types/types.d.ts.map +1 -1
  232. package/types/views/Text.d.ts.map +1 -1
  233. package/types/views/View.d.ts.map +1 -1
  234. package/dist/cjs/helpers/getDefaultProps.cjs +0 -24
  235. package/dist/cjs/helpers/getDefaultProps.native.cjs +0 -28
  236. package/dist/cjs/helpers/getDefaultProps.native.js +0 -30
  237. package/dist/cjs/helpers/getDefaultProps.native.js.map +0 -1
  238. package/dist/cjs/helpers/themeable.cjs +0 -92
  239. package/dist/cjs/helpers/themeable.native.cjs +0 -95
  240. package/dist/cjs/helpers/themeable.native.js +0 -97
  241. package/dist/cjs/helpers/themeable.native.js.map +0 -1
  242. package/dist/cjs/hooks/useProps.cjs +0 -129
  243. package/dist/cjs/hooks/useProps.native.cjs +0 -135
  244. package/dist/cjs/hooks/useProps.native.js +0 -137
  245. package/dist/cjs/hooks/useProps.native.js.map +0 -1
  246. package/dist/esm/helpers/getDefaultProps.mjs +0 -4
  247. package/dist/esm/helpers/getDefaultProps.mjs.map +0 -1
  248. package/dist/esm/helpers/getDefaultProps.native.js +0 -6
  249. package/dist/esm/helpers/getDefaultProps.native.js.map +0 -1
  250. package/dist/esm/helpers/themeable.mjs +0 -67
  251. package/dist/esm/helpers/themeable.mjs.map +0 -1
  252. package/dist/esm/helpers/themeable.native.js +0 -68
  253. package/dist/esm/helpers/themeable.native.js.map +0 -1
  254. package/dist/esm/hooks/useProps.mjs +0 -100
  255. package/dist/esm/hooks/useProps.mjs.map +0 -1
  256. package/dist/esm/hooks/useProps.native.js +0 -104
  257. package/dist/esm/hooks/useProps.native.js.map +0 -1
  258. package/src/helpers/getDefaultProps.ts +0 -3
  259. package/src/helpers/themeable.tsx +0 -96
  260. package/src/hooks/useProps.tsx +0 -186
  261. package/types/helpers/getDefaultProps.d.ts +0 -3
  262. package/types/helpers/getDefaultProps.d.ts.map +0 -1
  263. package/types/helpers/themeable.d.ts +0 -3
  264. package/types/helpers/themeable.d.ts.map +0 -1
  265. package/types/hooks/useProps.d.ts +0 -39
  266. package/types/hooks/useProps.d.ts.map +0 -1
@@ -33,9 +33,9 @@ export const getVariantExtras = (styleState: GetStyleState) => {
33
33
  const found = fonts[this.fontFamily]
34
34
  if (found) return found
35
35
 
36
- // When a component re-processes already-resolved props (useProps -> inner
37
- // render), fontFamily arrives as the opaque var(--f-family) reference. The
38
- // font identity survives in the font_<name> class.
36
+ // When an inner component re-processes already-resolved props, fontFamily
37
+ // arrives as the opaque var(--f-family) reference. The font identity
38
+ // survives in the font_<name> class.
39
39
  const className = props.className
40
40
  if (typeof className === 'string') {
41
41
  let start = 0
@@ -0,0 +1,166 @@
1
+ import { stylePropsAll } from '@tamagui/helpers'
2
+
3
+ import { getConfig } from '../config'
4
+ import type { Shorthands } from '../types'
5
+
6
+ type StringKey<Props> = Extract<keyof Props, string>
7
+ type Simplify<Value> = { [Key in keyof Value]: Value[Key] }
8
+
9
+ type ExpandedShorthandKey<
10
+ Key extends PropertyKey,
11
+ ShorthandMap extends object = Shorthands,
12
+ > = Key extends keyof ShorthandMap
13
+ ? ShorthandMap[Key] extends PropertyKey
14
+ ? ShorthandMap[Key]
15
+ : Key
16
+ : Key
17
+
18
+ type ShorthandKeysMatchingFilter<
19
+ Filter extends object,
20
+ ShorthandMap extends object = Shorthands,
21
+ > = {
22
+ [Key in keyof ShorthandMap]-?: ShorthandMap[Key] extends keyof Filter ? Key : never
23
+ }[keyof ShorthandMap]
24
+
25
+ type KeysMatchingFilter<Filter extends object, ShorthandMap extends object = Shorthands> =
26
+ | keyof Filter
27
+ | ShorthandKeysMatchingFilter<Filter, ShorthandMap>
28
+
29
+ type StyleKeys = KeysMatchingFilter<typeof stylePropsAll>
30
+
31
+ type ExpandedProps<
32
+ Props extends object,
33
+ Keys extends keyof Props,
34
+ ShorthandMap extends object,
35
+ > = Simplify<
36
+ {
37
+ [Key in Extract<Keys, keyof ShorthandMap> as ExpandedShorthandKey<
38
+ Key,
39
+ ShorthandMap
40
+ >]: Props[Key]
41
+ } & Omit<Pick<Props, Keys>, keyof ShorthandMap>
42
+ >
43
+
44
+ type SelectedProps<
45
+ Props extends object,
46
+ Keys extends keyof Props,
47
+ ExpandShorthands extends boolean,
48
+ ShorthandMap extends object = Shorthands,
49
+ > = ExpandShorthands extends true
50
+ ? ExpandedProps<Props, Keys, ShorthandMap>
51
+ : Pick<Props, Keys>
52
+
53
+ export type SplitStylePropsResult<
54
+ Props extends object,
55
+ Keys extends PropertyKey,
56
+ ExpandShorthands extends boolean = false,
57
+ ShorthandMap extends object = Shorthands,
58
+ > = [
59
+ SelectedProps<Props, Extract<keyof Props, Keys>, ExpandShorthands, ShorthandMap>,
60
+ Omit<Props, Keys>,
61
+ ]
62
+
63
+ export type SplitStylePropsFilterCallback<Props extends object> = (
64
+ key: string,
65
+ value: Props[StringKey<Props>],
66
+ originalKey: StringKey<Props>,
67
+ isStyleProp: boolean
68
+ ) => boolean
69
+
70
+ export type SplitStylePropsFilter<Props extends object> =
71
+ | Readonly<Record<string, unknown>>
72
+ | SplitStylePropsFilterCallback<Props>
73
+
74
+ export type SplitStylePropsOptions<Props extends object> = {
75
+ expandShorthands?: boolean
76
+ filter?: SplitStylePropsFilter<Props>
77
+ }
78
+
79
+ /** partitions authored props in one pass without resolving style values */
80
+ export function splitStyleProps<
81
+ Props extends object,
82
+ const ExpandShorthands extends boolean = false,
83
+ >(
84
+ props: Props,
85
+ options?: { expandShorthands?: ExpandShorthands }
86
+ ): SplitStylePropsResult<Props, StyleKeys, ExpandShorthands>
87
+
88
+ export function splitStyleProps<
89
+ Props extends object,
90
+ const Filter extends Readonly<Record<string, unknown>>,
91
+ const ExpandShorthands extends boolean = false,
92
+ >(
93
+ props: Props,
94
+ options: { expandShorthands?: ExpandShorthands; filter: Filter }
95
+ ): SplitStylePropsResult<Props, KeysMatchingFilter<Filter>, ExpandShorthands>
96
+
97
+ export function splitStyleProps<
98
+ Props extends object,
99
+ SelectedKey extends StringKey<Props>,
100
+ const ExpandShorthands extends boolean = false,
101
+ >(
102
+ props: Props,
103
+ options: {
104
+ expandShorthands?: ExpandShorthands
105
+ filter: (
106
+ key: string,
107
+ value: Props[StringKey<Props>],
108
+ originalKey: StringKey<Props>,
109
+ isStyleProp: boolean
110
+ ) => originalKey is SelectedKey
111
+ }
112
+ ): SplitStylePropsResult<Props, SelectedKey, ExpandShorthands>
113
+
114
+ export function splitStyleProps<
115
+ Props extends object,
116
+ const ExpandShorthands extends boolean = false,
117
+ >(
118
+ props: Props,
119
+ options: {
120
+ expandShorthands?: ExpandShorthands
121
+ filter: SplitStylePropsFilterCallback<Props>
122
+ }
123
+ ): [Partial<SelectedProps<Props, keyof Props, ExpandShorthands>>, Partial<Props>]
124
+
125
+ export function splitStyleProps(
126
+ props: object,
127
+ options: {
128
+ expandShorthands?: boolean
129
+ filter?:
130
+ | Readonly<Record<string, unknown>>
131
+ | ((
132
+ key: string,
133
+ value: unknown,
134
+ originalKey: string,
135
+ isStyleProp: boolean
136
+ ) => boolean)
137
+ } = {}
138
+ ) {
139
+ const styleProps: Record<string, unknown> = {}
140
+ const regularProps: Record<string, unknown> = {}
141
+ const { expandShorthands = false, filter } = options
142
+ const shorthands = getConfig().shorthands
143
+ const filterIsFunction = typeof filter === 'function'
144
+ const propsRecord = props as Record<string, unknown>
145
+
146
+ for (const originalKey in props) {
147
+ if (!Object.hasOwn(props, originalKey)) continue
148
+
149
+ const value = propsRecord[originalKey]
150
+ const key = shorthands[originalKey] || originalKey
151
+ const isStyleProp = key in stylePropsAll
152
+ const selected = filter
153
+ ? filterIsFunction
154
+ ? filter(key, value, originalKey, isStyleProp)
155
+ : Object.hasOwn(filter, key)
156
+ : isStyleProp
157
+
158
+ if (selected) {
159
+ styleProps[expandShorthands ? key : originalKey] = value
160
+ } else {
161
+ regularProps[originalKey] = value
162
+ }
163
+ }
164
+
165
+ return [styleProps, regularProps]
166
+ }
@@ -30,10 +30,14 @@ export type FrontendStaticConfig = {
30
30
  */
31
31
  passthroughClassName?: string
32
32
  variants?: Record<string, Record<string, any>>
33
- compoundVariants?: readonly Record<string, any>[]
34
33
  styleFrontend?: StyleFrontend
35
34
  }
36
35
 
36
+ export type FrontendStaticConfigNormalization = Pick<
37
+ FrontendStaticConfig,
38
+ 'baseStyle' | 'passthroughClassName' | 'variants'
39
+ >
40
+
37
41
  /**
38
42
  * What the internal View/Text factory and a frontend-bound `styled()` hand back: an
39
43
  * opaque component object carrying its static config. Deliberately not core's
@@ -81,13 +85,13 @@ export type StyleFrontend = {
81
85
 
82
86
  /**
83
87
  * Resolves frontend-specific static style input (a class-string base, string
84
- * variant values, string compound-variant styles) into ordinary style objects.
85
- * Called once per (staticConfig, config) pair; implementations memoize.
88
+ * variant values) into ordinary style objects.
89
+ * Called once per (staticConfig, config revision) by the shared runtime cache.
86
90
  */
87
91
  normalizeStaticConfig?: <Config extends FrontendStaticConfig>(
88
92
  staticConfig: Config,
89
93
  config: StyleFrontendConfig
90
- ) => Config
94
+ ) => FrontendStaticConfigNormalization
91
95
  }
92
96
 
93
97
  /**
@@ -0,0 +1,88 @@
1
+ import { stylePropsText, validStyles as validStylesView } from '@tamagui/helpers'
2
+ import type { StaticConfig, TamaguiInternalConfig } from '../types'
3
+ import { getConfigRevisionState } from './grammarConfig'
4
+
5
+ export type StyleStaticConfig = {
6
+ baseStyle: Record<string, any> | undefined
7
+ baseVariantProps: Record<string, any> | undefined
8
+ defaultProps: Record<string, any> | undefined
9
+ styledContextKeys: Set<string> | null
10
+ variants: StaticConfig['variants']
11
+ passthroughClassName: string | undefined
12
+ }
13
+
14
+ const styleStaticConfigCache = new WeakMap<
15
+ StaticConfig,
16
+ WeakMap<TamaguiInternalConfig, { revision: number; value: StyleStaticConfig }>
17
+ >()
18
+
19
+ /**
20
+ * styled() takes styles and props in one options object. The styles belong to the
21
+ * base layer the style pass writes before any prop, so call-site props and
22
+ * variants always land on top of them; everything else stays a prop.
23
+ *
24
+ * Split lazily rather than in styled(), because classifying a key needs
25
+ * `conf.shorthands` and styled() runs at module scope before createTamagui.
26
+ */
27
+ export function getStyleStaticConfig(
28
+ staticConfig: StaticConfig,
29
+ conf: TamaguiInternalConfig
30
+ ): StyleStaticConfig {
31
+ let configCache = styleStaticConfigCache.get(staticConfig)
32
+ const revision = getConfigRevisionState(conf).revision
33
+ const cached = configCache?.get(conf)
34
+ if (cached?.revision === revision) return cached.value
35
+
36
+ const normalized = staticConfig.styleFrontend?.normalizeStaticConfig?.(
37
+ staticConfig,
38
+ conf
39
+ )
40
+ const variants = normalized ? normalized.variants : staticConfig.variants
41
+ const authoredBaseStyle = normalized ? normalized.baseStyle : staticConfig.baseStyle
42
+ const authoredDefaultProps = staticConfig.defaultProps
43
+ let baseStyle: Record<string, any> | undefined
44
+ let baseVariantProps: Record<string, any> | undefined
45
+ let defaultProps: Record<string, any> | undefined
46
+ if (authoredDefaultProps) {
47
+ const validStyles =
48
+ staticConfig.validStyles ||
49
+ (staticConfig.isText || staticConfig.isInput ? stylePropsText : validStylesView)
50
+ for (const key in authoredDefaultProps) {
51
+ const isVariant = Boolean(variants?.[key])
52
+ // transition selects an animation driver preset. It stays a prop even
53
+ // though the web style table recognizes the CSS property spelling.
54
+ const isStyle =
55
+ key !== 'transition' && (key in validStyles || key in conf.shorthands)
56
+ if (isVariant || isStyle) {
57
+ ;(baseStyle ||= authoredBaseStyle ? { ...authoredBaseStyle } : {})[key] =
58
+ authoredDefaultProps[key]
59
+ }
60
+ // variants also stay in the merged props for context and HOC forwarding,
61
+ // while their style contribution runs at its authored base position
62
+ if (isVariant || !isStyle) {
63
+ ;(defaultProps ||= {})[key] = authoredDefaultProps[key]
64
+ }
65
+ if (isVariant) {
66
+ ;(baseVariantProps ||= {})[key] = authoredDefaultProps[key]
67
+ }
68
+ }
69
+ }
70
+ const keys = staticConfig.contextProps || staticConfig.context?.propKeys
71
+ const value: StyleStaticConfig = {
72
+ baseStyle: baseStyle || authoredBaseStyle,
73
+ baseVariantProps,
74
+ defaultProps,
75
+ styledContextKeys: keys ? new Set(keys) : null,
76
+ variants,
77
+ passthroughClassName: normalized
78
+ ? normalized.passthroughClassName
79
+ : staticConfig.passthroughClassName,
80
+ }
81
+
82
+ if (!configCache) {
83
+ configCache = new WeakMap()
84
+ styleStaticConfigCache.set(staticConfig, configCache)
85
+ }
86
+ configCache.set(conf, { revision, value })
87
+ return value
88
+ }
@@ -1,104 +1,73 @@
1
- // The prop -> token-category tables.
2
- //
3
- // Its own module because both `propMapper` and `directStyle` bind props to
4
- // these categories, and `propMapper` needs `directStyle`'s condition resolver:
5
- // leaving the tables where the resolver's consumer lives made the two files
6
- // import each other.
7
-
8
- import { tokenCategories } from '@tamagui/helpers'
1
+ import {
2
+ getTokenCategoryName,
3
+ propToTokenCategoryCode,
4
+ tokenCategoryColor,
5
+ tokenCategoryFontFamily,
6
+ tokenCategoryFontSize,
7
+ tokenCategoryFontWeight,
8
+ tokenCategoryLetterSpacing,
9
+ tokenCategoryLineHeight,
10
+ tokenCategoryRadius,
11
+ tokenCategorySize,
12
+ tokenCategorySpace,
13
+ tokenCategoryZIndex,
14
+ } from '@tamagui/helpers'
9
15
 
10
16
  export type StyleTokenCategory = 'size' | 'space' | 'radius' | 'zIndex' | 'fontSize'
17
+ export type RuntimeTokenCategory = StyleTokenCategory | 'color' | 'font' | 'fontFamily'
11
18
 
12
- function mapTokenCategory(keys: Record<string, boolean>, category: StyleTokenCategory) {
13
- return Object.fromEntries(Object.keys(keys).map((key) => [key, category]))
14
- }
15
-
16
- // exported so the flat-value grammar adapter binds props to the same token
17
- // categories the bare-token path already uses, rather than keeping a second table
18
- export const tokenCategoryByProperty: Record<string, StyleTokenCategory> = {
19
- ...mapTokenCategory(tokenCategories.size, 'size'),
20
- ...mapTokenCategory(tokenCategories.radius, 'radius'),
21
- ...mapTokenCategory(tokenCategories.zIndex, 'zIndex'),
22
- // the transform family's x/y are lengths from the space scale (v6 decision:
23
- // `x="4"` resolves like `p="4"`), never the size category
24
- x: 'space',
25
- y: 'space',
26
- fontSize: 'fontSize',
27
- borderWidth: 'space',
28
- borderTopWidth: 'space',
29
- borderRightWidth: 'space',
30
- borderBottomWidth: 'space',
31
- borderLeftWidth: 'space',
32
- borderBlockWidth: 'space',
33
- borderBlockStartWidth: 'space',
34
- borderBlockEndWidth: 'space',
35
- borderInlineWidth: 'space',
36
- borderInlineStartWidth: 'space',
37
- borderInlineEndWidth: 'space',
38
- outlineOffset: 'space',
39
- outlineWidth: 'space',
40
- gap: 'space',
41
- rowGap: 'space',
42
- columnGap: 'space',
43
- top: 'space',
44
- right: 'space',
45
- bottom: 'space',
46
- left: 'space',
47
- inset: 'space',
48
- insetBlock: 'space',
49
- insetBlockEnd: 'space',
50
- insetBlockStart: 'space',
51
- insetInline: 'space',
52
- insetInlineEnd: 'space',
53
- insetInlineStart: 'space',
54
- margin: 'space',
55
- marginBlock: 'space',
56
- marginBlockEnd: 'space',
57
- marginBlockStart: 'space',
58
- marginInline: 'space',
59
- marginInlineEnd: 'space',
60
- marginInlineStart: 'space',
61
- marginTop: 'space',
62
- marginRight: 'space',
63
- marginBottom: 'space',
64
- marginEnd: 'space',
65
- marginLeft: 'space',
66
- marginHorizontal: 'space',
67
- marginStart: 'space',
68
- marginVertical: 'space',
69
- padding: 'space',
70
- paddingBlock: 'space',
71
- paddingBlockEnd: 'space',
72
- paddingBlockStart: 'space',
73
- paddingInline: 'space',
74
- paddingInlineEnd: 'space',
75
- paddingInlineStart: 'space',
76
- paddingTop: 'space',
77
- paddingRight: 'space',
78
- paddingBottom: 'space',
79
- paddingEnd: 'space',
80
- paddingLeft: 'space',
81
- paddingHorizontal: 'space',
82
- paddingStart: 'space',
83
- paddingVertical: 'space',
19
+ const legacyCategory = (property: string): StyleTokenCategory | undefined => {
20
+ const category = getTokenCategoryName(propToTokenCategoryCode[property])
21
+ return category === 'space' ||
22
+ category === 'size' ||
23
+ category === 'radius' ||
24
+ category === 'zIndex' ||
25
+ category === 'fontSize'
26
+ ? category
27
+ : undefined
84
28
  }
85
29
 
86
- export type RuntimeTokenCategory = StyleTokenCategory | 'color' | 'font' | 'fontFamily'
30
+ // compatibility view for internal consumers that enumerated the old string map.
31
+ // the proxy keeps the numeric table canonical and only allocates keys on enumeration
32
+ export const tokenCategoryByProperty: Readonly<Record<string, StyleTokenCategory>> =
33
+ /* @__PURE__ */ new Proxy(Object.create(null), {
34
+ get(_, property) {
35
+ return typeof property === 'string' ? legacyCategory(property) : undefined
36
+ },
37
+ has(_, property) {
38
+ return typeof property === 'string' && legacyCategory(property) !== undefined
39
+ },
40
+ ownKeys() {
41
+ return Object.keys(propToTokenCategoryCode).filter(
42
+ (property) => legacyCategory(property) !== undefined
43
+ )
44
+ },
45
+ getOwnPropertyDescriptor(_, property) {
46
+ if (typeof property !== 'string' || legacyCategory(property) === undefined) return
47
+ return { configurable: true, enumerable: true }
48
+ },
49
+ })
87
50
 
88
51
  export function getTokenCategoryForProperty(
89
52
  property: string
90
53
  ): RuntimeTokenCategory | undefined {
91
- if (property === 'fontFamily') return 'fontFamily'
92
- if (
93
- property === 'fontSize' ||
94
- property === 'fontWeight' ||
95
- property === 'lineHeight' ||
96
- property === 'letterSpacing'
97
- ) {
98
- return 'font'
54
+ switch (propToTokenCategoryCode[property]) {
55
+ case tokenCategorySpace:
56
+ return 'space'
57
+ case tokenCategorySize:
58
+ return 'size'
59
+ case tokenCategoryRadius:
60
+ return 'radius'
61
+ case tokenCategoryZIndex:
62
+ return 'zIndex'
63
+ case tokenCategoryColor:
64
+ return 'color'
65
+ case tokenCategoryFontFamily:
66
+ return 'fontFamily'
67
+ case tokenCategoryFontSize:
68
+ case tokenCategoryFontWeight:
69
+ case tokenCategoryLineHeight:
70
+ case tokenCategoryLetterSpacing:
71
+ return 'font'
99
72
  }
100
- return (
101
- tokenCategoryByProperty[property] ||
102
- (property in tokenCategories.color ? 'color' : undefined)
103
- )
104
73
  }
@@ -0,0 +1,121 @@
1
+ import { isVariable } from '../createVariable'
2
+ import type { GetStyleState, TamaguiInternalConfig, VariantResolverName } from '../types'
3
+
4
+ type CompiledVariantResolver = {
5
+ key: string
6
+ parts: VariantResolverName[]
7
+ }
8
+
9
+ const variantResolverCache = new WeakMap<object, readonly CompiledVariantResolver[]>()
10
+
11
+ // a variant key may list several resolvers: `'Size | Space'`. compiled once per
12
+ // variant object on first use, never again on the render path
13
+ export function getCompiledVariantResolvers(variant: object) {
14
+ let compiled = variantResolverCache.get(variant)
15
+ if (!compiled) {
16
+ const next: CompiledVariantResolver[] = []
17
+ for (const key in variant) {
18
+ const parts = parseVariantResolverKey(key)
19
+ if (parts) next.push({ key, parts })
20
+ }
21
+ compiled = next
22
+ variantResolverCache.set(variant, compiled)
23
+ }
24
+ return compiled
25
+ }
26
+
27
+ function parseVariantResolverKey(key: string): VariantResolverName[] | null {
28
+ if (!key) return null
29
+ return key.split('|').map((part) => part.trim()) as VariantResolverName[]
30
+ }
31
+
32
+ // goes through specificity finding best matching variant function
33
+ export function getVariantDefinition(
34
+ variant: any,
35
+ value: any,
36
+ conf: TamaguiInternalConfig,
37
+ { theme }: Partial<GetStyleState>
38
+ ): any {
39
+ if (!variant) return
40
+ if (value === undefined) return
41
+ if (typeof variant === 'function') {
42
+ return variant
43
+ }
44
+ if (value in variant) {
45
+ return variant[value]
46
+ }
47
+ for (const { key, parts } of getCompiledVariantResolvers(variant)) {
48
+ for (const part of parts) {
49
+ if (matchesVariantResolver(part, value, conf, theme)) {
50
+ return variant[key]
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ function matchesVariantResolver(
57
+ resolverName: VariantResolverName,
58
+ value: any,
59
+ conf: TamaguiInternalConfig,
60
+ theme: Partial<GetStyleState>['theme']
61
+ ) {
62
+ const string = typeof value === 'string'
63
+ const number = typeof value === 'number'
64
+ const rem =
65
+ string &&
66
+ value.length > 3 &&
67
+ value.endsWith('rem') &&
68
+ Number.isFinite(Number(value.slice(0, -3)))
69
+
70
+ switch (resolverName) {
71
+ case 'Size':
72
+ case 'Space':
73
+ case 'Radius':
74
+ case 'ZIndex':
75
+ // styles are authored by devs and never validated at runtime: any number
76
+ // or string routes to the token variant, which passes unknown values
77
+ // through. Size keeps its historical variable exclusion so variables
78
+ // route to the Space/Radius/ZIndex fallbacks.
79
+ return (
80
+ value === true ||
81
+ number ||
82
+ string ||
83
+ (resolverName !== 'Size' && isVariable(value))
84
+ )
85
+ // a token or theme color, otherwise any string is taken to be a raw CSS
86
+ // color and left for the browser to resolve. checking that against a CSS
87
+ // color-name table costs 2.3KB gzip to reject values that were never valid
88
+ // anyway. `red/50` opacity modifiers stay limited to token and theme
89
+ // colors, which the branches above already covered.
90
+ case 'Color':
91
+ return string
92
+ case 'Theme':
93
+ return string && !!theme && value in theme
94
+ case 'FontSize':
95
+ return value === true || !!conf.fontsParsed.body?.size?.[value] || number || rem
96
+ case 'FontStyle':
97
+ return (
98
+ !!conf.fontsParsed.body?.style?.[value] ||
99
+ value === 'normal' ||
100
+ value === 'italic'
101
+ )
102
+ case 'FontTransform':
103
+ return (
104
+ !!conf.fontsParsed.body?.transform?.[value] ||
105
+ value === 'none' ||
106
+ value === 'capitalize' ||
107
+ value === 'uppercase' ||
108
+ value === 'lowercase'
109
+ )
110
+ case 'FontLineHeight':
111
+ return !!conf.fontsParsed.body?.lineHeight?.[value] || number || rem
112
+ case 'FontLetterSpacing':
113
+ return !!conf.fontsParsed.body?.letterSpacing?.[value] || number || rem
114
+ case 'number':
115
+ case 'string':
116
+ case 'boolean':
117
+ return typeof value === resolverName
118
+ case 'any':
119
+ return true
120
+ }
121
+ }
@@ -9,10 +9,25 @@ const useInsertEffectCompat = isWeb
9
9
  : () => {}
10
10
 
11
11
  // perf: ...args a bit expensive on native
12
- export const useSplitStyles: StyleSplitter = (a, b, c, d, e, f, g, h, i, j, k, l, m) => {
12
+ export const useSplitStyles: StyleSplitter = (
13
+ a,
14
+ b,
15
+ c,
16
+ d,
17
+ e,
18
+ f,
19
+ g,
20
+ h,
21
+ i,
22
+ j,
23
+ k,
24
+ l,
25
+ m,
26
+ n
27
+ ) => {
13
28
  'use no memo'
14
29
 
15
- const res = getSplitStyles(a, b, c, d, e, f, g, h, i, j, k, l, m)
30
+ const res = getSplitStyles(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
16
31
 
17
32
  if (!process.env.TAMAGUI_DID_OUTPUT_CSS && process.env.TAMAGUI_TARGET !== 'native') {
18
33
  useInsertEffectCompat(() => {
@@ -31,7 +31,7 @@ export const useThemeWithState = (
31
31
  // <Theme> components push their themeState.id into ThemeStateContext,
32
32
  // so their descendants subscribe under this id; <Theme> needs to schedule
33
33
  // descendant updates when its propsKey changes. Leaf styled components
34
- // (createComponent, useProps, useTheme, animation hooks) do NOT push a
34
+ // (createComponent, useTheme, animation hooks) do NOT push a
35
35
  // context — listenersByParent[componentId] is always empty — so the
36
36
  // schedule-update effect is a no-op for them and can be skipped to save
37
37
  // one hook slot per styled component on mount. Theme.tsx passes true.
package/src/index.ts CHANGED
@@ -11,14 +11,13 @@ export { _withStableStyle } from './_withStableStyle'
11
11
  export { _withNativeStyle } from './_withNativeStyle'
12
12
  export { createComponent } from './createComponent'
13
13
  export { createStyledContext } from './helpers/createStyledContext'
14
- export { getDefaultProps } from './helpers/getDefaultProps'
15
14
  export { getCSSStylesAtomic } from './helpers/getCSSStylesAtomic'
16
15
  export { getExpandedShorthand } from './helpers/getExpandedShorthands'
17
16
  export { formatDiagnostic } from './helpers/formatDiagnostic'
18
17
  export {
18
+ getStyleStaticConfig,
19
19
  getSplitStyles,
20
20
  isValidStyleKey,
21
- prepareStyleStaticConfig,
22
21
  } from './helpers/getSplitStyles'
23
22
  export {
24
23
  setNativeStyleEngine,
@@ -42,10 +41,16 @@ export { isTamaguiElement } from './helpers/isTamaguiElement'
42
41
  export { matchMedia, setupMatchMedia } from './helpers/matchMedia'
43
42
  export { mergeProps } from './helpers/mergeProps'
44
43
  export { mergeSlotStyleProps } from './helpers/mergeSlotStyleProps'
44
+ export {
45
+ splitStyleProps,
46
+ type SplitStylePropsFilter,
47
+ type SplitStylePropsFilterCallback,
48
+ type SplitStylePropsOptions,
49
+ type SplitStylePropsResult,
50
+ } from './helpers/splitStyleProps'
45
51
  export { normalizeColor } from './helpers/normalizeColor'
46
52
  export { normalizeStyle } from './helpers/normalizeStyle'
47
53
  export { containsThemeRef, themeRefKey } from './helpers/themeRef'
48
- export { themeable } from './helpers/themeable'
49
54
  export { getStyleTags } from './helpers/wrapStyleTags'
50
55
 
51
56
  export { createFont } from './createFont'
@@ -276,7 +281,6 @@ export {
276
281
  useAnimatedNumbersStyle,
277
282
  useAnimationDriver,
278
283
  } from './hooks/useAnimationDriver'
279
- export { useProps, usePropsAndStyle, useStyle } from './hooks/useProps'
280
284
  export { useTheme } from './hooks/useTheme'
281
285
  export { usePortalThemeState } from './hooks/usePortalThemeState'
282
286
  export { useThemeName } from './hooks/useThemeName'