@tamagui/core 1.0.1-beta.219 → 1.0.1-beta.221

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 (302) hide show
  1. package/dist/cjs/addTheme.js +7 -10
  2. package/dist/cjs/addTheme.js.map +3 -3
  3. package/dist/cjs/config.js +8 -4
  4. package/dist/cjs/config.js.map +2 -2
  5. package/dist/cjs/{hooks/useUnmountEffect.js → contexts/ButtonNestingContext.js} +7 -9
  6. package/dist/cjs/contexts/ButtonNestingContext.js.map +7 -0
  7. package/dist/cjs/createComponent.js +63 -67
  8. package/dist/cjs/createComponent.js.map +3 -3
  9. package/dist/cjs/createFont.js +11 -4
  10. package/dist/cjs/createFont.js.map +2 -2
  11. package/dist/cjs/createFont.test.js +125 -0
  12. package/dist/cjs/createFont.test.js.map +7 -0
  13. package/dist/cjs/createTamagui.js +13 -12
  14. package/dist/cjs/createTamagui.js.map +2 -2
  15. package/dist/cjs/createTokens.js.map +2 -2
  16. package/dist/cjs/createTokens.test.js +27 -0
  17. package/dist/cjs/createTokens.test.js.map +7 -0
  18. package/dist/cjs/createVariable.js +4 -9
  19. package/dist/cjs/createVariable.js.map +2 -2
  20. package/dist/cjs/createVariable.test.js +7 -0
  21. package/dist/cjs/createVariable.test.js.map +7 -0
  22. package/dist/cjs/createVariables.js +6 -7
  23. package/dist/cjs/createVariables.js.map +2 -2
  24. package/dist/cjs/helpers/ThemeManager.js +161 -147
  25. package/dist/cjs/helpers/ThemeManager.js.map +3 -3
  26. package/dist/cjs/helpers/ThemeManager.test.js +449 -0
  27. package/dist/cjs/helpers/ThemeManager.test.js.map +7 -0
  28. package/dist/cjs/helpers/{getTokens.js → ThemeManagerContext.js} +8 -8
  29. package/dist/cjs/helpers/ThemeManagerContext.js.map +7 -0
  30. package/dist/cjs/helpers/createPropMapper.js +4 -4
  31. package/dist/cjs/helpers/createPropMapper.js.map +2 -2
  32. package/dist/cjs/helpers/extendStaticConfig.js +2 -4
  33. package/dist/cjs/helpers/extendStaticConfig.js.map +2 -2
  34. package/dist/cjs/helpers/{assignNativePropsToWeb.native.js → getBoundingClientRect.js} +15 -8
  35. package/dist/cjs/helpers/getBoundingClientRect.js.map +7 -0
  36. package/dist/cjs/{hooks/useConstant.js → helpers/getRect.js} +14 -17
  37. package/dist/cjs/helpers/getRect.js.map +7 -0
  38. package/dist/cjs/helpers/getSplitStyles.js +82 -87
  39. package/dist/cjs/helpers/getSplitStyles.js.map +3 -3
  40. package/dist/cjs/helpers/getStylesAtomic.native.js.map +2 -2
  41. package/dist/cjs/helpers/getThemeCSSRules.js +6 -2
  42. package/dist/cjs/helpers/getThemeCSSRules.js.map +2 -2
  43. package/dist/cjs/helpers/insertStyleRule.js +1 -1
  44. package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
  45. package/dist/cjs/helpers/mergeTransform.js +11 -8
  46. package/dist/cjs/helpers/mergeTransform.js.map +2 -2
  47. package/dist/cjs/helpers/pseudoDescriptors.js +1 -0
  48. package/dist/cjs/helpers/pseudoDescriptors.js.map +2 -2
  49. package/dist/cjs/helpers/themeable.js +9 -9
  50. package/dist/cjs/helpers/themeable.js.map +2 -2
  51. package/dist/cjs/hooks/useElementLayout.js +4 -12
  52. package/dist/cjs/hooks/useElementLayout.js.map +2 -2
  53. package/dist/cjs/hooks/useMedia.js +2 -1
  54. package/dist/cjs/hooks/useMedia.js.map +2 -2
  55. package/dist/cjs/hooks/useTheme.js +114 -156
  56. package/dist/cjs/hooks/useTheme.js.map +3 -3
  57. package/dist/cjs/hooks/{useIsMounted.js → useThemeName.js} +23 -14
  58. package/dist/cjs/hooks/useThemeName.js.map +7 -0
  59. package/dist/cjs/index.js +2 -5
  60. package/dist/cjs/index.js.map +2 -2
  61. package/dist/cjs/setupReactNative.js +20 -7
  62. package/dist/cjs/setupReactNative.js.map +2 -2
  63. package/dist/cjs/styled.js +2 -19
  64. package/dist/cjs/styled.js.map +2 -2
  65. package/dist/cjs/types.js.map +1 -1
  66. package/dist/cjs/updateTheme.js +9 -9
  67. package/dist/cjs/updateTheme.js.map +2 -2
  68. package/dist/cjs/views/TamaguiProvider.js +3 -3
  69. package/dist/cjs/views/TamaguiProvider.js.map +2 -2
  70. package/dist/cjs/views/Theme.js +39 -28
  71. package/dist/cjs/views/Theme.js.map +3 -3
  72. package/dist/cjs/views/ThemeInverse.js +4 -2
  73. package/dist/cjs/views/ThemeInverse.js.map +2 -2
  74. package/dist/cjs/views/ThemeProvider.js +8 -33
  75. package/dist/cjs/views/ThemeProvider.js.map +3 -3
  76. package/dist/esm/addTheme.js +7 -10
  77. package/dist/esm/addTheme.js.map +3 -3
  78. package/dist/esm/config.js +8 -3
  79. package/dist/esm/config.js.map +2 -2
  80. package/dist/esm/contexts/ButtonNestingContext.js +6 -0
  81. package/dist/esm/contexts/ButtonNestingContext.js.map +7 -0
  82. package/dist/esm/createComponent.js +65 -70
  83. package/dist/esm/createComponent.js.map +3 -3
  84. package/dist/esm/createFont.js +11 -4
  85. package/dist/esm/createFont.js.map +2 -2
  86. package/dist/esm/createFont.test.js +124 -0
  87. package/dist/esm/createFont.test.js.map +7 -0
  88. package/dist/esm/createTamagui.js +13 -12
  89. package/dist/esm/createTamagui.js.map +2 -2
  90. package/dist/esm/createTokens.js.map +2 -2
  91. package/dist/esm/createTokens.test.js +26 -0
  92. package/dist/esm/createTokens.test.js.map +7 -0
  93. package/dist/esm/createVariable.js +4 -9
  94. package/dist/esm/createVariable.js.map +2 -2
  95. package/dist/esm/createVariable.test.js +6 -0
  96. package/dist/esm/createVariable.test.js.map +7 -0
  97. package/dist/esm/createVariables.js +6 -7
  98. package/dist/esm/createVariables.js.map +2 -2
  99. package/dist/esm/helpers/ThemeManager.js +140 -144
  100. package/dist/esm/helpers/ThemeManager.js.map +3 -3
  101. package/dist/esm/helpers/ThemeManager.test.js +448 -0
  102. package/dist/esm/helpers/ThemeManager.test.js.map +7 -0
  103. package/dist/esm/helpers/ThemeManagerContext.js +6 -0
  104. package/dist/esm/helpers/ThemeManagerContext.js.map +7 -0
  105. package/dist/esm/helpers/createPropMapper.js +4 -4
  106. package/dist/esm/helpers/createPropMapper.js.map +2 -2
  107. package/dist/esm/helpers/extendStaticConfig.js +2 -4
  108. package/dist/esm/helpers/extendStaticConfig.js.map +2 -2
  109. package/dist/esm/helpers/getBoundingClientRect.js +13 -0
  110. package/dist/esm/helpers/getBoundingClientRect.js.map +7 -0
  111. package/dist/esm/helpers/getRect.js +12 -0
  112. package/dist/esm/helpers/getRect.js.map +7 -0
  113. package/dist/esm/helpers/getSplitStyles.js +90 -89
  114. package/dist/esm/helpers/getSplitStyles.js.map +3 -3
  115. package/dist/esm/helpers/getStylesAtomic.native.js.map +2 -2
  116. package/dist/esm/helpers/getThemeCSSRules.js +6 -2
  117. package/dist/esm/helpers/getThemeCSSRules.js.map +2 -2
  118. package/dist/esm/helpers/insertStyleRule.js +1 -1
  119. package/dist/esm/helpers/insertStyleRule.js.map +2 -2
  120. package/dist/esm/helpers/mergeTransform.js +8 -6
  121. package/dist/esm/helpers/mergeTransform.js.map +2 -2
  122. package/dist/esm/helpers/pseudoDescriptors.js +1 -0
  123. package/dist/esm/helpers/pseudoDescriptors.js.map +2 -2
  124. package/dist/esm/helpers/themeable.js +9 -9
  125. package/dist/esm/helpers/themeable.js.map +2 -2
  126. package/dist/esm/hooks/useElementLayout.js +2 -9
  127. package/dist/esm/hooks/useElementLayout.js.map +2 -2
  128. package/dist/esm/hooks/useMedia.js +3 -2
  129. package/dist/esm/hooks/useMedia.js.map +2 -2
  130. package/dist/esm/hooks/useTheme.js +114 -159
  131. package/dist/esm/hooks/useTheme.js.map +3 -3
  132. package/dist/esm/hooks/useThemeName.js +25 -0
  133. package/dist/esm/hooks/useThemeName.js.map +7 -0
  134. package/dist/esm/index.js +3 -5
  135. package/dist/esm/index.js.map +2 -2
  136. package/dist/esm/setupReactNative.js +18 -6
  137. package/dist/esm/setupReactNative.js.map +2 -2
  138. package/dist/esm/styled.js +3 -20
  139. package/dist/esm/styled.js.map +2 -2
  140. package/dist/esm/updateTheme.js +9 -9
  141. package/dist/esm/updateTheme.js.map +2 -2
  142. package/dist/esm/views/TamaguiProvider.js +4 -4
  143. package/dist/esm/views/TamaguiProvider.js.map +2 -2
  144. package/dist/esm/views/Theme.js +40 -29
  145. package/dist/esm/views/Theme.js.map +3 -3
  146. package/dist/esm/views/ThemeInverse.js +4 -2
  147. package/dist/esm/views/ThemeInverse.js.map +2 -2
  148. package/dist/esm/views/ThemeProvider.js +8 -27
  149. package/dist/esm/views/ThemeProvider.js.map +2 -2
  150. package/package.json +13 -13
  151. package/src/__snapshots__/createTokens.test.ts.snap +877 -0
  152. package/src/addTheme.ts +9 -12
  153. package/src/config.ts +10 -2
  154. package/src/contexts/ButtonNestingContext.tsx +3 -0
  155. package/src/createComponent.tsx +117 -108
  156. package/src/createFont.test.ts +129 -0
  157. package/src/createFont.ts +12 -5
  158. package/src/createTamagui.ts +16 -14
  159. package/src/createTokens.test.ts +29 -0
  160. package/src/createTokens.ts +1 -1
  161. package/src/createVariable.test.ts +7 -0
  162. package/src/createVariable.ts +4 -10
  163. package/src/createVariables.ts +7 -7
  164. package/src/helpers/ThemeManager.test.tsx +480 -0
  165. package/src/helpers/ThemeManager.tsx +171 -166
  166. package/src/helpers/ThemeManagerContext.tsx +5 -0
  167. package/src/helpers/createPropMapper.ts +4 -4
  168. package/src/helpers/extendStaticConfig.ts +4 -4
  169. package/src/helpers/getBoundingClientRect.tsx +7 -0
  170. package/src/helpers/getRect.tsx +8 -0
  171. package/src/helpers/getSplitStyles.tsx +98 -94
  172. package/src/helpers/getStylesAtomic.native.ts +1 -0
  173. package/src/helpers/getThemeCSSRules.ts +9 -2
  174. package/src/helpers/insertStyleRule.tsx +2 -2
  175. package/src/helpers/mergeTransform.ts +13 -6
  176. package/src/helpers/pseudoDescriptors.ts +1 -0
  177. package/src/helpers/themeable.tsx +17 -9
  178. package/src/hooks/useElementLayout.tsx +3 -8
  179. package/src/hooks/useMedia.tsx +3 -3
  180. package/src/hooks/useTheme.tsx +138 -211
  181. package/src/hooks/useThemeName.tsx +25 -0
  182. package/src/index.ts +3 -4
  183. package/src/setupReactNative.ts +16 -5
  184. package/src/styled.tsx +4 -23
  185. package/src/types.tsx +42 -17
  186. package/src/updateTheme.ts +12 -9
  187. package/src/views/TamaguiProvider.tsx +5 -5
  188. package/src/views/Theme.tsx +48 -39
  189. package/src/views/ThemeProvider.tsx +11 -33
  190. package/types/Tamagui.d.ts +1 -1
  191. package/types/addTheme.d.ts +23 -2
  192. package/types/config.d.ts +0 -1
  193. package/types/contexts/ButtonNestingContext.d.ts +3 -0
  194. package/types/createFont.test.d.ts +2 -0
  195. package/types/createTokens.test.d.ts +2 -0
  196. package/types/createVariable.d.ts +2 -2
  197. package/types/createVariable.test.d.ts +2 -0
  198. package/types/helpers/ThemeManager.d.ts +20 -30
  199. package/types/helpers/ThemeManager.test.d.ts +2 -0
  200. package/types/helpers/ThemeManagerContext.d.ts +4 -0
  201. package/types/helpers/getBoundingClientRect.d.ts +2 -0
  202. package/types/helpers/getRect.d.ts +9 -0
  203. package/types/helpers/insertStyleRule.d.ts +1 -1
  204. package/types/helpers/mergeTransform.d.ts +5 -3
  205. package/types/helpers/themeable.d.ts +3 -0
  206. package/types/hooks/useElementLayout.d.ts +0 -8
  207. package/types/hooks/useTheme.d.ts +10 -20
  208. package/types/hooks/useThemeName.d.ts +5 -0
  209. package/types/index.d.ts +3 -4
  210. package/types/setupReactNative.d.ts +4 -2
  211. package/types/types.d.ts +35 -10
  212. package/types/updateTheme.d.ts +23 -2
  213. package/types/views/Theme.d.ts +3 -4
  214. package/dist/cjs/constants/platform.js +0 -74
  215. package/dist/cjs/constants/platform.js.map +0 -7
  216. package/dist/cjs/constants/platform.native.js +0 -62
  217. package/dist/cjs/constants/platform.native.js.map +0 -7
  218. package/dist/cjs/helpers/assignNativePropsToWeb.js +0 -188
  219. package/dist/cjs/helpers/assignNativePropsToWeb.js.map +0 -7
  220. package/dist/cjs/helpers/assignNativePropsToWeb.native.js.map +0 -7
  221. package/dist/cjs/helpers/calc.js +0 -71
  222. package/dist/cjs/helpers/calc.js.map +0 -7
  223. package/dist/cjs/helpers/getFont.js +0 -66
  224. package/dist/cjs/helpers/getFont.js.map +0 -7
  225. package/dist/cjs/helpers/getStackSize.js +0 -46
  226. package/dist/cjs/helpers/getStackSize.js.map +0 -7
  227. package/dist/cjs/helpers/getTokens.js.map +0 -7
  228. package/dist/cjs/helpers/startTransition.js +0 -36
  229. package/dist/cjs/helpers/startTransition.js.map +0 -7
  230. package/dist/cjs/helpers/validate.js +0 -2
  231. package/dist/cjs/helpers/validate.js.map +0 -7
  232. package/dist/cjs/hooks/useConstant.js.map +0 -7
  233. package/dist/cjs/hooks/useIsMounted.js.map +0 -7
  234. package/dist/cjs/hooks/usePressable.js +0 -36
  235. package/dist/cjs/hooks/usePressable.js.map +0 -7
  236. package/dist/cjs/hooks/useUnmountEffect.js.map +0 -7
  237. package/dist/cjs/injectStyles.js +0 -40
  238. package/dist/cjs/injectStyles.js.map +0 -7
  239. package/dist/cjs/react-native.js +0 -22
  240. package/dist/cjs/react-native.js.map +0 -7
  241. package/dist/esm/constants/platform.js +0 -39
  242. package/dist/esm/constants/platform.js.map +0 -7
  243. package/dist/esm/constants/platform.native.js +0 -28
  244. package/dist/esm/constants/platform.native.js.map +0 -7
  245. package/dist/esm/helpers/assignNativePropsToWeb.js +0 -164
  246. package/dist/esm/helpers/assignNativePropsToWeb.js.map +0 -7
  247. package/dist/esm/helpers/assignNativePropsToWeb.native.js +0 -6
  248. package/dist/esm/helpers/assignNativePropsToWeb.native.js.map +0 -7
  249. package/dist/esm/helpers/calc.js +0 -47
  250. package/dist/esm/helpers/calc.js.map +0 -7
  251. package/dist/esm/helpers/getFont.js +0 -42
  252. package/dist/esm/helpers/getFont.js.map +0 -7
  253. package/dist/esm/helpers/getStackSize.js +0 -22
  254. package/dist/esm/helpers/getStackSize.js.map +0 -7
  255. package/dist/esm/helpers/getTokens.js +0 -6
  256. package/dist/esm/helpers/getTokens.js.map +0 -7
  257. package/dist/esm/helpers/startTransition.js +0 -6
  258. package/dist/esm/helpers/startTransition.js.map +0 -7
  259. package/dist/esm/helpers/validate.js +0 -1
  260. package/dist/esm/helpers/validate.js.map +0 -7
  261. package/dist/esm/hooks/useConstant.js +0 -15
  262. package/dist/esm/hooks/useConstant.js.map +0 -7
  263. package/dist/esm/hooks/useIsMounted.js +0 -16
  264. package/dist/esm/hooks/useIsMounted.js.map +0 -7
  265. package/dist/esm/hooks/usePressable.js +0 -12
  266. package/dist/esm/hooks/usePressable.js.map +0 -7
  267. package/dist/esm/hooks/useUnmountEffect.js +0 -8
  268. package/dist/esm/hooks/useUnmountEffect.js.map +0 -7
  269. package/dist/esm/injectStyles.js +0 -16
  270. package/dist/esm/injectStyles.js.map +0 -7
  271. package/dist/esm/react-native.js +0 -3
  272. package/dist/esm/react-native.js.map +0 -7
  273. package/src/contexts/ButtonInsideButtonContext.tsx +0 -3
  274. package/src/contexts/ThemeContext.tsx +0 -5
  275. package/src/helpers/areEqualSets.tsx +0 -9
  276. package/src/views/ThemeInverse.tsx +0 -40
  277. package/src/views/ThemeReset.tsx +0 -43
  278. package/types/constants/platform.d.ts +0 -13
  279. package/types/constants/platform.native.d.ts +0 -13
  280. package/types/contexts/ButtonInsideButtonContext.d.ts +0 -3
  281. package/types/contexts/ThemeContext.d.ts +0 -7
  282. package/types/helpers/areEqualSets.d.ts +0 -2
  283. package/types/helpers/assignNativePropsToWeb.d.ts +0 -2
  284. package/types/helpers/assignNativePropsToWeb.native.d.ts +0 -2
  285. package/types/helpers/calc.d.ts +0 -1
  286. package/types/helpers/getFont.d.ts +0 -3
  287. package/types/helpers/getStackSize.d.ts +0 -8
  288. package/types/helpers/getTokens.d.ts +0 -2
  289. package/types/helpers/startTransition.d.ts +0 -3
  290. package/types/helpers/validate.d.ts +0 -1
  291. package/types/hooks/useConstant.d.ts +0 -2
  292. package/types/hooks/useIsMounted.d.ts +0 -3
  293. package/types/hooks/useMedia.test.d.ts +0 -1
  294. package/types/hooks/usePressable.d.ts +0 -3
  295. package/types/hooks/usePressablePressResponder.d.ts +0 -84
  296. package/types/hooks/useUnmountEffect.d.ts +0 -2
  297. package/types/injectStyles.d.ts +0 -7
  298. package/types/react-native.d.ts +0 -8
  299. package/types/views/AbsoluteFill.d.ts +0 -5
  300. package/types/views/AbsoluteFill.native.d.ts +0 -3
  301. package/types/views/ThemeInverse.d.ts +0 -9
  302. package/types/views/ThemeReset.d.ts +0 -4
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createTokens.ts"],
4
- "sourcesContent": ["import { Variable } from './createVariable'\nimport { createVariables } from './createVariables'\nimport { CreateTokens } from './types'\n\n// tokens.color.dark.red ===> { var: `color-dark-red`, val: '' }\nexport function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {\n return createVariables(tokens as any) as any\n}\n\n// verbose but gives us nice types...\ntype MakeTokens<T> = T extends {\n color: infer E\n space: infer F\n size: infer G\n radius: infer H\n zIndex: infer J\n}\n ? {\n color: {\n [Key in keyof E]: E[Key] extends Variable ? E[Key] : Variable<E[Key]>\n }\n space: {\n [Key in keyof F]: F[Key] extends Variable ? F[Key] : Variable<F[Key]>\n }\n size: {\n [Key in keyof G]: G[Key] extends Variable ? G[Key] : Variable<G[Key]>\n }\n radius: {\n [Key in keyof H]: H[Key] extends Variable ? H[Key] : Variable<H[Key]>\n }\n zIndex: {\n [Key in keyof J]: J[Key] extends Variable ? J[Key] : Variable<J[Key]>\n }\n }\n : never\n"],
5
- "mappings": "AACA,SAAS,uBAAuB;AAIzB,SAAS,aAAqC,QAA0B;AAC7E,SAAO,gBAAgB,MAAa;AACtC;",
4
+ "sourcesContent": ["import { Variable } from './createVariable'\nimport { createVariables } from './createVariables'\nimport { CreateTokens } from './types'\n\n// tokens.color.dark.red ===> { var: `color-dark-red`, val: '' }\nexport function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {\n return createVariables(tokens) as any\n}\n\n// verbose but gives us nice types...\ntype MakeTokens<T> = T extends {\n color: infer E\n space: infer F\n size: infer G\n radius: infer H\n zIndex: infer J\n}\n ? {\n color: {\n [Key in keyof E]: E[Key] extends Variable ? E[Key] : Variable<E[Key]>\n }\n space: {\n [Key in keyof F]: F[Key] extends Variable ? F[Key] : Variable<F[Key]>\n }\n size: {\n [Key in keyof G]: G[Key] extends Variable ? G[Key] : Variable<G[Key]>\n }\n radius: {\n [Key in keyof H]: H[Key] extends Variable ? H[Key] : Variable<H[Key]>\n }\n zIndex: {\n [Key in keyof J]: J[Key] extends Variable ? J[Key] : Variable<J[Key]>\n }\n }\n : never\n"],
5
+ "mappings": "AACA,SAAS,uBAAuB;AAIzB,SAAS,aAAqC,QAA0B;AAC7E,SAAO,gBAAgB,MAAM;AAC/B;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,26 @@
1
+ import { getDefaultTamaguiConfig } from "@tamagui/config-default-node";
2
+ import { expect, test } from "vitest";
3
+ import { createTokens } from "./createTokens";
4
+ test("snapshot", () => {
5
+ expect(createTokens(getDefaultTamaguiConfig().tokens)).toMatchSnapshot();
6
+ });
7
+ test("color name no dot", () => {
8
+ expect(
9
+ createTokens({
10
+ color: {
11
+ "yellow.10": "yellow"
12
+ }
13
+ })
14
+ ).toMatchObject({
15
+ color: {
16
+ "yellow.10": {
17
+ isVar: true,
18
+ key: "yellow101a",
19
+ name: "color-1",
20
+ val: "yellow",
21
+ variable: ""
22
+ }
23
+ }
24
+ });
25
+ });
26
+ //# sourceMappingURL=createTokens.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createTokens.test.ts"],
4
+ "sourcesContent": ["import { getDefaultTamaguiConfig } from '@tamagui/config-default-node'\nimport { expect, test } from 'vitest'\n\nimport { createTokens } from './createTokens'\n\ntest('snapshot', () => {\n expect(createTokens(getDefaultTamaguiConfig().tokens)).toMatchSnapshot()\n})\n\ntest('color name no dot', () => {\n expect(\n // @ts-ignore partial\n createTokens({\n color: {\n 'yellow.10': 'yellow',\n },\n })\n ).toMatchObject({\n color: {\n 'yellow.10': {\n isVar: true,\n key: 'yellow101a',\n name: 'color-1',\n val: 'yellow',\n variable: '',\n },\n },\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,+BAA+B;AACxC,SAAS,QAAQ,YAAY;AAE7B,SAAS,oBAAoB;AAE7B,KAAK,YAAY,MAAM;AACrB,SAAO,aAAa,wBAAwB,EAAE,MAAM,CAAC,EAAE,gBAAgB;AACzE,CAAC;AAED,KAAK,qBAAqB,MAAM;AAC9B;AAAA,IAEE,aAAa;AAAA,MACX,OAAO;AAAA,QACL,aAAa;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH,EAAE,cAAc;AAAA,IACd,OAAO;AAAA,MACL,aAAa;AAAA,QACX,OAAO;AAAA,QACP,KAAK;AAAA,QACL,MAAM;AAAA,QACN,KAAK;AAAA,QACL,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -1,11 +1,10 @@
1
1
  import { isWeb } from "@tamagui/constants";
2
2
  import { simpleHash } from "@tamagui/helpers";
3
3
  import { getConfig } from "./config";
4
- const IS_VAR = "__isVar__";
4
+ const IS_VAR = "isVar";
5
5
  const createVariable = (props) => {
6
- if (isVariable(props)) {
6
+ if (isVariable(props))
7
7
  return props;
8
- }
9
8
  return {
10
9
  [IS_VAR]: true,
11
10
  ...props,
@@ -13,14 +12,10 @@ const createVariable = (props) => {
13
12
  };
14
13
  };
15
14
  function variableToString(vrble, getValue = false) {
16
- if (!vrble)
17
- return "";
18
15
  if (isVariable(vrble)) {
19
- if (getValue)
20
- return `${vrble.val}`;
21
- return `${isWeb ? vrble.variable : vrble.val}`;
16
+ return getValue ? `${vrble.val}` : `${isWeb ? vrble.variable : vrble.val}`;
22
17
  }
23
- return `${vrble}`;
18
+ return `${vrble || ""}`;
24
19
  }
25
20
  function isVariable(v) {
26
21
  return !!(v && v[IS_VAR]);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createVariable.ts"],
4
- "sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport { simpleHash } from '@tamagui/helpers'\n\nimport { getConfig } from './config'\n\n/**\n * Should rename this to Token\n * Moving to objects for React Server Components support\n */\n\nconst IS_VAR = '__isVar__'\n\ntype VariableIn<A = any> = {\n val: A\n name: string\n key: string\n isFloating?: boolean\n}\n\nexport type Variable<A = any> = VariableIn<A> & {\n [IS_VAR]?: true\n variable?: string\n}\n\nexport const createVariable = <A extends string | number = any>(props: VariableIn<A>) => {\n if (isVariable(props)) {\n return props\n }\n return {\n [IS_VAR]: true,\n // @ts-ignore\n ...props,\n variable: isWeb ? createCSSVariable(props.name) : '',\n }\n}\n\n// on the client maybe we can change the prototype of variable object toString to keep backwards compat\nexport function variableToString(vrble?: any, getValue = false) {\n if (!vrble) return ''\n if (isVariable(vrble)) {\n if (getValue) return `${vrble.val}`\n return `${isWeb ? vrble.variable : vrble.val}`\n }\n return `${vrble}`\n}\n\nexport function isVariable(v: Variable | any): v is Variable {\n return !!(v && v[IS_VAR])\n}\n\nexport function getVariable(nameOrVariable: Variable | string) {\n if (isVariable(nameOrVariable)) {\n return variableToString(nameOrVariable)\n }\n const tokens = getConfig().tokensParsed\n return variableToString(tokens[nameOrVariable] ?? nameOrVariable)\n}\n\nexport function getVariableValue(v: Variable | any) {\n if (isVariable(v)) return v.val\n return v\n}\n\nexport function getVariableName(v: Variable | any) {\n if (isVariable(v)) return v.name\n return v\n}\n\nexport function getVariableVariable(v: Variable | any) {\n if (isVariable(v)) return v.variable\n return v\n}\n\n// bugfix { space: { 0.5: 10 } } was generating var(--space-0.5) (invalid CSS):\nexport const createCSSVariable = (nameProp: string, includeVar = true) => {\n if (process.env.NODE_ENV === 'development') {\n if (!nameProp || typeof nameProp !== 'string') {\n throw new Error(`createC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AC7C,YAAM,IAAI,MAAM,sCAAsC,UAAU;AAAA,IAClE;AAAA,EACF;AACA,QAAM,OAAO,WAAW,UAAU,EAAE;AACpC,SAAO,aAAa,SAAS,UAAU;AACzC;",
4
+ "sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport { simpleHash } from '@tamagui/helpers'\n\nimport { getConfig } from './config'\n\n/**\n * Should rename this to Token\n * Moving to objects for React Server Components support\n */\n\nconst IS_VAR = 'isVar'\n\ntype VariableIn<A = any> = {\n val: A\n name: string\n key: string\n isFloating?: boolean\n}\n\nexport type Variable<A = any> = VariableIn<A> & {\n [IS_VAR]?: true\n variable?: string\n}\n\nexport const createVariable = <A extends string | number = any>(props: VariableIn<A>) => {\n if (isVariable(props)) return props\n return {\n [IS_VAR]: true,\n ...props,\n variable: isWeb ? createCSSVariable(props.name) : '',\n }\n}\n\nexport function variableToString(vrble?: any, getValue = false) {\n if (isVariable(vrble)) {\n return getValue ? `${vrble.val}` : `${isWeb ? vrble.variable : vrble.val}`\n }\n return `${vrble || ''}`\n}\n\nexport function isVariable(v: Variable | any): v is Variable {\n return !!(v && v[IS_VAR])\n}\n\nexport function getVariable(nameOrVariable: Variable | string) {\n if (isVariable(nameOrVariable)) {\n return variableToString(nameOrVariable)\n }\n const tokens = getConfig().tokensParsed\n return variableToString(tokens[nameOrVariable] ?? nameOrVariable)\n}\n\nexport function getVariableValue(v: Variable | any) {\n if (isVariable(v)) return v.val\n return v\n}\n\nexport function getVariableName(v: Variable | any) {\n if (isVariable(v)) return v.name\n return v\n}\n\nexport function getVariableVariable(v: Variable | any) {\n if (isVariable(v)) return v.variable\n return v\n}\n\n// bugfix { space: { 0.5: 10 } } was generating var(--space-0.5) (invalid CSS):\nexport const createCSSVariable = (nameProp: string, includeVar = true) => {\n if (process.env.NODE_ENV === 'development') {\n if (!nameProp || typeof nameProp !== 'string') {\n throw new Error(`createCSSVariable expected string: ${nameProp}`)\n }\n }\n const name = simpleHash(nameProp, 60)\n return includeVar ? `var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AS,UAAU;AACzC;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,6 @@
1
+ import { expect, test } from "vitest";
2
+ import { createCSSVariable } from "./createVariable";
3
+ test("dots", () => {
4
+ expect(createCSSVariable("yellow.10")).toBe("var(--yellow101a)");
5
+ });
6
+ //# sourceMappingURL=createVariable.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createVariable.test.ts"],
4
+ "sourcesContent": ["import { expect, test } from 'vitest'\n\nimport { createCSSVariable } from './createVariable'\n\ntest('dots', () => {\n expect(createCSSVariable('yellow.10')).toBe('var(--yellow101a)')\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAE7B,SAAS,yBAAyB;AAElC,KAAK,QAAQ,MAAM;AACjB,SAAO,kBAAkB,WAAW,CAAC,EAAE,KAAK,mBAAmB;AACjE,CAAC;",
6
+ "names": []
7
+ }
@@ -1,24 +1,23 @@
1
+ import { simpleHash } from "@tamagui/helpers";
1
2
  import { createVariable, isVariable } from "./createVariable";
2
3
  const createVariables = (tokens, parentPath = "", isFont = false) => {
3
4
  const res = {};
4
5
  let i = 0;
5
6
  for (const key in tokens) {
6
7
  i++;
7
- const variableName = isFont ? key.slice(0, 2) : i;
8
8
  const val = tokens[key];
9
9
  if (isVariable(val)) {
10
10
  res[key] = val;
11
11
  continue;
12
12
  }
13
- let name = parentPath ? `${parentPath}-${variableName}` : key;
14
- if (isFont && name.includes("_")) {
15
- name = name.replace(/_[a-z0-9]+/i, "");
16
- }
13
+ const niceKey = simpleHash(key);
14
+ let name = isFont ? niceKey.slice(0, 2) : i;
15
+ name = parentPath ? `${parentPath}-${name}` : niceKey;
17
16
  if (val && typeof val === "object") {
18
- res[key] = createVariables(tokens[key], `${name}`);
17
+ res[key] = createVariables(tokens[key], name);
19
18
  continue;
20
19
  }
21
- res[key] = isVariable(val) ? val : createVariable({ val, name, key });
20
+ res[key] = isVariable(val) ? val : createVariable({ val, name, key: niceKey });
22
21
  }
23
22
  return res;
24
23
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createVariables.ts"],
4
- "sourcesContent": ["import { Variable, createVariable, isVariable } from './createVariable'\n\ntype DeepTokenObject<Val extends string | number = any> = {\n [key: string]: Val | DeepTokenObject<Val>\n}\n\nexport type DeepVariableObject<A extends DeepTokenObject> = {\n [Key in keyof A]: A[Key] extends string | number\n ? Variable<A[Key]>\n : A[Key] extends DeepTokenObject\n ? DeepVariableObject<A[Key]>\n : never\n}\n\nexport const createVariables = <A extends DeepTokenObject>(\n tokens: A,\n parentPath = '',\n isFont = false\n): DeepVariableObject<A> => {\n const res: any = {}\n let i = 0\n for (const key in tokens) {\n i++\n const variableName = isFont ? key.slice(0, 2) : i\n const val = tokens[key]\n if (isVariable(val)) {\n res[key] = val\n continue\n }\n let name = parentPath ? `${parentPath}-${variableName}` : key\n if (isFont && name.includes('_')) {\n name = name.replace(/_[a-z0-9]+/i, '')\n }\n if (val && typeof val === 'object') {\n // recurse\n res[key] = createVariables(tokens[key] as any, `${name}`)\n continue\n }\n res[key] = isVariable(val) ? val : createVariable({ val, name, key })\n }\n return res\n}\n"],
5
- "mappings": "AAAA,SAAmB,gBAAgB,kBAAkB;AAc9C,MAAM,kBAAkB,CAC7B,QACA,aAAa,IACb,SAAS,UACiB;AAC1B,QAAM,MAAW,CAAC;AAClB,MAAI,IAAI;AACR,aAAW,OAAO,QAAQ;AACxB;AACA,UAAM,eAAe,SAAS,IAAI,MAAM,GAAG,CAAC,IAAI;AAChD,UAAM,MAAM,OAAO;AACnB,QAAI,WAAW,GAAG,GAAG;AACnB,UAAI,OAAO;AACX;AAAA,IACF;AACA,QAAI,OAAO,aAAa,GAAG,cAAc,iBAAiB;AAC1D,QAAI,UAAU,KAAK,SAAS,GAAG,GAAG;AAChC,aAAO,KAAK,QAAQ,eAAe,EAAE;AAAA,IACvC;AACA,QAAI,OAAO,OAAO,QAAQ,UAAU;AAElC,UAAI,OAAO,gBAAgB,OAAO,MAAa,GAAG,MAAM;AACxD;AAAA,IACF;AACA,QAAI,OAAO,WAAW,GAAG,IAAI,MAAM,eAAe,EAAE,KAAK,MAAM,IAAI,CAAC;AAAA,EACtE;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import { simpleHash } from '@tamagui/helpers'\n\nimport { Variable, createVariable, isVariable } from './createVariable'\n\ntype DeepTokenObject<Val extends string | number = any> = {\n [key: string]: Val | DeepTokenObject<Val>\n}\n\nexport type DeepVariableObject<A extends DeepTokenObject> = {\n [Key in keyof A]: A[Key] extends string | number\n ? Variable<A[Key]>\n : A[Key] extends DeepTokenObject\n ? DeepVariableObject<A[Key]>\n : never\n}\n\nexport const createVariables = <A extends DeepTokenObject>(\n tokens: A,\n parentPath = '',\n isFont = false\n): DeepVariableObject<A> => {\n const res: any = {}\n let i = 0\n for (const key in tokens) {\n i++\n const val = tokens[key]\n if (isVariable(val)) {\n res[key] = val\n continue\n }\n const niceKey = simpleHash(key)\n let name = isFont ? niceKey.slice(0, 2) : i\n name = parentPath ? `${parentPath}-${name}` : niceKey\n if (val && typeof val === 'object') {\n // recurse\n res[key] = createVariables(tokens[key] as any, name)\n continue\n }\n res[key] = isVariable(val) ? val : createVariable({ val, name, key: niceKey })\n }\n return res\n}\n"],
5
+ "mappings": "AAAA,SAAS,kBAAkB;AAE3B,SAAmB,gBAAgB,kBAAkB;AAc9C,MAAM,kBAAkB,CAC7B,QACA,aAAa,IACb,SAAS,UACiB;AAC1B,QAAM,MAAW,CAAC;AAClB,MAAI,IAAI;AACR,aAAW,OAAO,QAAQ;AACxB;AACA,UAAM,MAAM,OAAO;AACnB,QAAI,WAAW,GAAG,GAAG;AACnB,UAAI,OAAO;AACX;AAAA,IACF;AACA,UAAM,UAAU,WAAW,GAAG;AAC9B,QAAI,OAAO,SAAS,QAAQ,MAAM,GAAG,CAAC,IAAI;AAC1C,WAAO,aAAa,GAAG,cAAc,SAAS;AAC9C,QAAI,OAAO,OAAO,QAAQ,UAAU;AAElC,UAAI,OAAO,gBAAgB,OAAO,MAAa,IAAI;AACnD;AAAA,IACF;AACA,QAAI,OAAO,WAAW,GAAG,IAAI,MAAM,eAAe,EAAE,KAAK,MAAM,KAAK,QAAQ,CAAC;AAAA,EAC/E;AACA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,180 +1,176 @@
1
- import { createContext } from "react";
2
1
  import { getThemes } from "../config";
3
2
  import { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from "../constants/constants";
4
3
  import { getThemeUnwrapped } from "../hooks/getThemeUnwrapped";
4
+ const emptyState = { name: "" };
5
+ function hasNoThemeUpdatingProps(props) {
6
+ return !props.name && !props.componentName && !props.inverse && !props.reset;
7
+ }
5
8
  class ThemeManager {
6
- constructor(name = "", className = "", theme = null, parentManager = null, reset = false) {
7
- this.name = name;
8
- this.className = className;
9
- this.theme = theme;
10
- this.parentManager = parentManager;
11
- this.reset = reset;
12
- this.keys = /* @__PURE__ */ new Map();
13
- this.listeners = /* @__PURE__ */ new Map();
9
+ constructor(props = {}, parentManager) {
10
+ this.props = props;
14
11
  this.themeListeners = /* @__PURE__ */ new Set();
15
- let parent = parentManager;
16
- let tries = 0;
17
- while (true) {
18
- tries++;
19
- if (tries > 10) {
20
- throw new Error(`Nested 10 of the same theme in a row, likely error`);
12
+ this.parentManager = null;
13
+ this.state = emptyState;
14
+ this.#allKeys = null;
15
+ if (parentManager === "root") {
16
+ this.updateState(props, false);
17
+ return;
18
+ }
19
+ if (!parentManager) {
20
+ throw new Error(`Must set up root first`);
21
+ }
22
+ if (hasNoThemeUpdatingProps(props)) {
23
+ return parentManager;
24
+ }
25
+ if (parentManager) {
26
+ this.parentManager = parentManager;
27
+ }
28
+ const updatedState = this.getStateIfChanged(props);
29
+ if (updatedState) {
30
+ this.state = updatedState;
31
+ return;
32
+ }
33
+ return parentManager || this;
34
+ }
35
+ updateState(props = this.props || {}, notify = true) {
36
+ const shouldFlush = (() => {
37
+ if (props.forceTheme) {
38
+ this.state.theme = props.forceTheme;
39
+ this.state.name = props.name || "";
40
+ return true;
21
41
  }
22
- if (!parent)
23
- break;
24
- if (parent.name === name) {
25
- parent = parent.parentManager;
26
- } else {
27
- this.parentManager = parent;
28
- break;
42
+ const nextState = this.getStateIfChanged(props);
43
+ if (nextState) {
44
+ this.state = nextState;
45
+ return true;
29
46
  }
47
+ })();
48
+ if (shouldFlush) {
49
+ this.#allKeys = null;
50
+ notify && this.notify();
51
+ return this.state;
30
52
  }
31
53
  }
32
- get didChangeTheme() {
33
- return this.parentManager && this.name !== this.parentManager.fullName;
54
+ getStateIfChanged(props = this.props, state = this.state, parentManager = this.parentManager) {
55
+ const _ = getState(props, parentManager) || (process.env.TAMAGUI_TARGET === "native" ? parentManager == null ? void 0 : parentManager.state : void 0);
56
+ if (!_ || !_.theme || _.theme === state.theme) {
57
+ return null;
58
+ }
59
+ return _;
34
60
  }
35
- get parentName() {
36
- var _a;
37
- return ((_a = this.parentManager) == null ? void 0 : _a.name) || null;
61
+ getState(props = this.props) {
62
+ return getState(props, this.parentManager);
38
63
  }
39
- get fullName() {
40
- return this.getNextTheme().name || this.name || "";
64
+ #allKeys;
65
+ get allKeys() {
66
+ var _a;
67
+ this.#allKeys ??= /* @__PURE__ */ new Set([
68
+ ...((_a = this.parentManager) == null ? void 0 : _a.allKeys) || [],
69
+ ...Object.keys(this.state.theme || {})
70
+ ]);
71
+ return this.#allKeys;
41
72
  }
42
- getValue(key) {
43
- let theme = this.theme;
73
+ getValue(key, state) {
74
+ let theme = (state || this.state).theme;
44
75
  let manager = this;
45
- while (true) {
46
- if (!theme)
47
- return;
76
+ while (theme && manager) {
48
77
  if (key in theme) {
49
78
  return theme[key];
50
79
  }
51
- manager = this.parentManager;
52
- if (!manager || manager.theme === theme) {
53
- return;
54
- }
55
- theme = manager.theme;
80
+ manager = manager.parentManager;
81
+ theme = manager == null ? void 0 : manager.state.theme;
56
82
  }
57
83
  }
58
- isTracking(uuid) {
59
- var _a;
60
- return Boolean((_a = this.keys.get(uuid)) == null ? void 0 : _a.size);
84
+ notify() {
85
+ this.themeListeners.forEach((cb) => cb(this.state.name, this));
61
86
  }
62
- update({ name, theme, className } = {}, force = false, notify = true) {
63
- if (!force) {
64
- const nameChanged = name !== this.name;
65
- if (!nameChanged) {
66
- return false;
67
- }
87
+ onChangeTheme(cb) {
88
+ this.themeListeners.add(cb);
89
+ return () => {
90
+ this.themeListeners.delete(cb);
91
+ };
92
+ }
93
+ }
94
+ function getNextThemeClassName(name, isInverting = false) {
95
+ const next = `${THEME_CLASSNAME_PREFIX}${name}`;
96
+ if (isInverting) {
97
+ return next;
98
+ }
99
+ return next.replace("light_", "").replace("dark_", "");
100
+ }
101
+ function getState(props, parentManager) {
102
+ var _a, _b, _c;
103
+ const themes = getThemes();
104
+ if (props.name && props.reset) {
105
+ throw new Error(`Cannot reset + set new name`);
106
+ }
107
+ if (props.reset && !(parentManager == null ? void 0 : parentManager.parentManager)) {
108
+ throw new Error(`Cannot reset no grandparent exists`);
109
+ }
110
+ const nextName = props.reset ? ((_b = (_a = parentManager == null ? void 0 : parentManager.parentManager) == null ? void 0 : _a.state) == null ? void 0 : _b.name) || "" : props.name || "";
111
+ const { componentName } = props;
112
+ const parentName = ((_c = parentManager == null ? void 0 : parentManager.state) == null ? void 0 : _c.name) || "";
113
+ const base = parentName.split(THEME_NAME_SEPARATOR);
114
+ const lastSegment = base[base.length - 1];
115
+ const isParentAComponentTheme = parentName && lastSegment[0].toUpperCase() === lastSegment[0];
116
+ if (isParentAComponentTheme) {
117
+ base.pop();
118
+ }
119
+ const parentBaseTheme = isParentAComponentTheme ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR) : parentName;
120
+ const max = base.length;
121
+ const min = componentName ? max : 0;
122
+ if (process.env.NODE_ENV === "development" && props.debug === "verbose")
123
+ console.log("getState", props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme, parentManager });
124
+ for (let i = max; i >= min; i--) {
125
+ let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR);
126
+ if (props.inverse) {
127
+ prefix = inverseThemeName(prefix);
68
128
  }
69
- this.className = className || "";
70
- this.name = name || "";
71
- this.theme = theme;
72
- if (notify) {
73
- this.notify();
129
+ const potentials = [];
130
+ if (prefix && prefix !== parentBaseTheme) {
131
+ potentials.push(prefix);
74
132
  }
75
- return true;
76
- }
77
- getNextTheme(props = {}, debug) {
78
- var _a;
79
- const { themes = getThemes(), name, componentName } = props;
80
- if (props.reset && name) {
81
- return {
82
- name,
83
- theme: themes[name],
84
- className: this.getCN(name)
85
- };
133
+ if (nextName) {
134
+ potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName);
86
135
  }
87
- const parentIsReset = (_a = this.parentManager) == null ? void 0 : _a.reset;
88
- if (!name) {
89
- if (componentName) {
90
- const names = [
91
- `${this.name}_${componentName}`,
92
- `${withoutComponentName(this.name)}_${componentName}`
93
- ];
94
- for (const name2 of names) {
95
- if (name2 in themes) {
96
- const className = this.getCN(name2);
97
- return { name: name2, theme: themes[name2], className };
98
- }
99
- }
136
+ if (i === 1) {
137
+ const lastSegment2 = potentials.findIndex((x) => !x.includes("_"));
138
+ if (lastSegment2 > 0) {
139
+ potentials.splice(lastSegment2, 0, nextName);
100
140
  }
101
- return {
102
- name: this.name,
103
- theme: this.theme,
104
- className: this.className
105
- };
106
- }
107
- let nextName = name || this.name || "";
108
- let parentName = parentIsReset ? this.parentName || this.fullName : this.fullName;
109
- while (true) {
110
- if (nextName in themes)
111
- break;
112
- nextName = `${parentName}_${name}`;
113
- if (nextName in themes)
114
- break;
115
- if (!parentName.includes(THEME_NAME_SEPARATOR))
116
- break;
117
- parentName = parentName.slice(0, parentName.lastIndexOf(THEME_NAME_SEPARATOR));
118
141
  }
119
142
  if (componentName) {
120
- const names = [
121
- `${nextName}_${componentName}`,
122
- `${withoutComponentName(nextName)}_${componentName}`
123
- ];
124
- for (const name2 of names) {
125
- if (name2 in themes) {
126
- nextName = name2;
127
- }
143
+ if (nextName) {
144
+ potentials.push(`${prefix.replace(/_.*$/, "")}_${nextName}_${componentName}`);
128
145
  }
129
- }
130
- let theme = themes[nextName];
131
- if (!theme) {
132
- theme = themes[`light_${nextName}`];
133
- }
134
- if (process.env.NODE_ENV === "development") {
135
- if (debug) {
136
- console.log("getNextTheme", this.getCN(nextName), { props, nextName, parentName });
146
+ potentials.push(`${prefix}_${componentName}`);
147
+ if (nextName) {
148
+ potentials.unshift(`${prefix}_${nextName}_${componentName}`);
137
149
  }
138
150
  }
139
- return {
140
- name: nextName,
141
- theme: getThemeUnwrapped(theme),
142
- className: this.getCN(nextName)
143
- };
144
- }
145
- getCN(name) {
146
- return `${THEME_CLASSNAME_PREFIX}${name} t_Theme`.replace("light_", "").replace("dark_", "");
147
- }
148
- track(uuid, keys) {
149
- if (!this.name)
150
- return;
151
- this.keys.set(uuid, keys);
152
- }
153
- notify() {
154
- var _a;
155
- if (!this.name) {
156
- this.keys.clear();
157
- }
158
- for (const [uuid, keys] of this.keys.entries()) {
159
- if (keys.size) {
160
- (_a = this.listeners.get(uuid)) == null ? void 0 : _a();
151
+ if (process.env.NODE_ENV === "development" && props.debug === "verbose")
152
+ console.log("getState potentials", potentials);
153
+ const found = potentials.find((t) => t in themes);
154
+ if (found) {
155
+ if (found === parentName) {
156
+ return null;
161
157
  }
158
+ const theme = themes[found];
159
+ return {
160
+ name: found,
161
+ theme: getThemeUnwrapped(theme),
162
+ className: getNextThemeClassName(found, props.inverse),
163
+ parentName
164
+ };
162
165
  }
163
- this.themeListeners.forEach((cb) => cb(this.name, this));
164
- }
165
- onChangeTheme(cb) {
166
- this.themeListeners.add(cb);
167
- return () => {
168
- this.themeListeners.delete(cb);
169
- };
170
166
  }
167
+ return null;
171
168
  }
172
- const ThemeManagerContext = createContext(null);
173
- const emptyManager = new ThemeManager();
174
- const withoutComponentName = (name) => name.replace(/(\_[A-Z][a-zA-Z]+)+$/g, "");
169
+ const inverseThemeName = (themeName) => {
170
+ return themeName.startsWith("light") ? themeName.replace(/^light/, "dark") : themeName.replace(/^dark/, "light");
171
+ };
175
172
  export {
176
173
  ThemeManager,
177
- ThemeManagerContext,
178
- emptyManager
174
+ hasNoThemeUpdatingProps
179
175
  };
180
176
  //# sourceMappingURL=ThemeManager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/ThemeManager.tsx"],
4
- "sourcesContent": ["import { createContext } from 'react'\n\nimport { getThemes } from '../config'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants'\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped'\nimport { ThemeParsed, Themes } from '../types'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n}\n\nexport type GetNextThemeProps = {\n themes?: Themes\n name?: string | null\n componentName?: string | null\n reset?: boolean\n}\n\nexport class ThemeManager {\n keys = new Map<any, Set<string>>()\n listeners = new Map<any, Function>()\n themeListeners = new Set<ThemeListener>()\n\n constructor(\n public name: string = '',\n public className: string = '',\n public theme: ThemeParsed | null = null,\n public parentManager: ThemeManager | null = null,\n public reset: boolean = false\n ) {\n // find the nearest different parentManager\n let parent = parentManager\n let tries = 0\n while (true) {\n tries++\n if (tries > 10) {\n throw new Error(`Nested 10 of the same theme in a row, likely error`)\n }\n if (!parent) break\n if (parent.name === name) {\n // go up if same\n parent = parent.parentManager\n } else {\n this.parentManager = parent\n break\n }\n }\n }\n\n get didChangeTheme() {\n return this.parentManager && this.name !== this.parentManager.fullName\n }\n\n get parentName() {\n return this.parentManager?.name || null\n }\n\n get fullName(): string {\n return this.getNextTheme().name || this.name || ''\n // const parentName = this.parentManager?.fullName || ''\n // const name = this.name || ''\n // const parts = [...new Set([...`${parentName}_${name}`.split('_')])].filter(Boolean)\n // return parts.join('_')\n }\n\n // gets value going up to parents\n getValue(key: string) {\n let theme = this.theme\n let manager = this as ThemeManager | null\n while (true) {\n if (!theme) return\n if (key in theme) {\n return theme[key]\n }\n manager = this.parentManager\n if (!manager || manager.theme === theme) {\n return\n }\n theme = manager.theme\n }\n }\n\n isTracking(uuid: Object) {\n return Boolean(this.keys.get(uuid)?.size)\n }\n\n update({ name, theme, className }: SetActiveThemeProps = {}, force = false, notify = true) {\n if (!force) {\n // className compare on web, avoids light/dark re-renders\n const nameChanged = name !== this.name\n if (!nameChanged) {\n return false\n }\n }\n this.className = className || ''\n this.name = name || ''\n this.theme = theme\n if (notify) {\n this.notify()\n }\n return true\n }\n\n getNextTheme(\n props: GetNextThemeProps = {},\n debug?: any\n ): {\n name: string\n theme: ThemeParsed | null\n className: string | undefined\n } {\n const { themes = getThemes(), name, componentName } = props\n\n if (props.reset && name) {\n return {\n name: name,\n theme: themes[name] as ThemeParsed,\n className: this.getCN(name),\n }\n }\n\n const parentIsReset = this.parentManager?.reset\n\n if (!name) {\n if (componentName) {\n // allow for _Card_Button or just _Button\n const names = [\n `${this.name}_${componentName}`,\n `${withoutComponentName(this.name)}_${componentName}`,\n ]\n for (const name of names) {\n if (name in themes) {\n const className = this.getCN(name)\n return { name, theme: themes[name], className }\n }\n }\n }\n return {\n name: this.name,\n theme: this.theme,\n className: this.className,\n }\n }\n\n let nextName = name || this.name || ''\n let parentName = parentIsReset ? this.parentName || this.fullName : this.fullName\n\n while (true) {\n if (nextName in themes) break\n nextName = `${parentName}_${name}`\n if (nextName in themes) break\n // this is fine - some themes can not have parents\n if (!parentName.includes(THEME_NAME_SEPARATOR)) break\n // go up one\n parentName = parentName.slice(0, parentName.lastIndexOf(THEME_NAME_SEPARATOR))\n }\n\n if (componentName) {\n // allow for _Card_Button or just _Button\n const names = [\n `${nextName}_${componentName}`,\n `${withoutComponentName(nextName)}_${componentName}`,\n ]\n for (const name of names) {\n if (name in themes) {\n nextName = name\n }\n }\n }\n\n let theme = themes[nextName]\n if (!theme) {\n theme = themes[`light_${nextName}`]\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (debug) {\n // eslint-disable-next-line no-console\n console.log('getNextTheme', this.getCN(nextName), { props, nextName, parentName })\n }\n }\n\n return {\n name: nextName,\n theme: getThemeUnwrapped(theme),\n className: this.getCN(nextName),\n }\n }\n\n getCN(name: string) {\n return `${THEME_CLASSNAME_PREFIX}${name} t_Theme`.replace('light_', '').replace('dark_', '')\n }\n\n track(uuid: any, keys: Set<string>) {\n if (!this.name) return\n this.keys.set(uuid, keys)\n }\n\n notify() {\n if (!this.name) {\n this.keys.clear()\n }\n for (const [uuid, keys] of this.keys.entries()) {\n if (keys.size) {\n this.listeners.get(uuid)?.()\n }\n }\n this.themeListeners.forEach((cb) => cb(this.name, this))\n }\n\n onChangeTheme(cb: ThemeListener) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nexport const ThemeManagerContext = createContext<ThemeManager | null>(null)\nexport const emptyManager = new ThemeManager()\n\nconst withoutComponentName = (name: string) => name.replace(/(\\_[A-Z][a-zA-Z]+)+$/g, '')\n"],
5
- "mappings": "AAAA,SAAS,qBAAqB;AAE9B,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB,4BAA4B;AAC7D,SAAS,yBAAyB;AAmB3B,MAAM,aAAa;AAAA,EAKxB,YACS,OAAe,IACf,YAAoB,IACpB,QAA4B,MAC5B,gBAAqC,MACrC,QAAiB,OACxB;AALO;AACA;AACA;AACA;AACA;AATT,gBAAO,oBAAI,IAAsB;AACjC,qBAAY,oBAAI,IAAmB;AACnC,0BAAiB,oBAAI,IAAmB;AAUtC,QAAI,SAAS;AACb,QAAI,QAAQ;AACZ,WAAO,MAAM;AACX;AACA,UAAI,QAAQ,IAAI;AACd,cAAM,IAAI,MAAM,oDAAoD;AAAA,MACtE;AACA,UAAI,CAAC;AAAQ;AACb,UAAI,OAAO,SAAS,MAAM;AAExB,iBAAS,OAAO;AAAA,MAClB,OAAO;AACL,aAAK,gBAAgB;AACr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,EAAE,OAAO,UAAU,WAAW,CAAC;AAAA,MACnF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO,kBAAkB,KAAK;AAAA,MAC9B,WAAW,KAAK,MAAM,QAAQ;AAAA,IAChC;AAAA,EACF;AAAA,EAEA,MAAM,MAAc;AAClB,WAAO,GAAG,yBAAyB,eAAe,QAAQ,UAAU,EAAE,EAAE,QAAQ,SAAS,EAAE;AAAA,EAC7F;AAAA,EAEA,MAAM,MAAW,MAAmB;AAClC,QAAI,CAAC,KAAK;AAAM;AAChB,SAAK,KAAK,IAAI,MAAM,IAAI;AAAA,EAC1B;AAAA,EAEA,SAAS;AA3MX;AA4MI,QAAI,CAAC,KAAK,MAAM;AACd,WAAK,KAAK,MAAM;AAAA,IAClB;AACA,eAAW,CAAC,MAAM,IAAI,KAAK,KAAK,KAAK,QAAQ,GAAG;AAC9C,UAAI,KAAK,MAAM;AACb,mBAAK,UAAU,IAAI,IAAI,MAAvB;AAAA,MACF;AAAA,IACF;AACA,SAAK,eAAe,QAAQ,CAAC,OAAO,GAAG,KAAK,MAAM,IAAI,CAAC;AAAA,EACzD;AAAA,EAEA,cAAc,IAAmB;AAC/B,SAAK,eAAe,IAAI,EAAE;AAC1B,WAAO,MAAM;AACX,WAAK,eAAe,OAAO,EAAE;AAAA,IAC/B;AAAA,EACF;AACF;AAEO,MAAM,sBAAsB,cAAmC,IAAI;AACnE,MAAM,eAAe,IAAI,aAAa;AAE7C,MAAM,uBAAuB,CAAC,SAAiB,KAAK,QAAQ,yBAAyB,EAAE;",
6
- "names": ["name"]
4
+ "sourcesContent": ["import { isWeb } from '@tamagui/constants'\n\nimport { getThemes } from '../config'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants'\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped'\nimport { ThemeParsed, ThemeProps } from '../types'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n reset?: boolean\n}\n\nexport type ThemeManagerState = {\n name: string\n theme?: ThemeParsed | null\n className?: string\n parentName?: string\n}\n\nconst emptyState: ThemeManagerState = { name: '' }\n\nexport function hasNoThemeUpdatingProps(props: ThemeProps) {\n return !props.name && !props.componentName && !props.inverse && !props.reset\n}\n\nexport class ThemeManager {\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManager?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManager === 'root') {\n this.updateState(props, false)\n return\n }\n if (!parentManager) {\n throw new Error(`Must set up root first`)\n }\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n if (parentManager) {\n this.parentManager = parentManager\n }\n const updatedState = this.getStateIfChanged(props)\n if (updatedState) {\n this.state = updatedState\n return\n }\n return parentManager || this\n }\n\n updateState(props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {}, notify = true) {\n const shouldFlush = (() => {\n if (props.forceTheme) {\n this.state.theme = props.forceTheme\n this.state.name = props.name || ''\n return true\n }\n const nextState = this.getStateIfChanged(props)\n if (nextState) {\n this.state = nextState\n return true\n }\n })()\n if (shouldFlush) {\n // reset any derived state\n this.#allKeys = null\n notify && this.notify()\n return this.state\n }\n }\n\n getStateIfChanged(props = this.props, state = this.state, parentManager = this.parentManager) {\n const _ =\n getState(props, parentManager) ||\n (process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state : undefined)\n if (!_ || !_.theme || _.theme === state.theme) {\n return null\n }\n return _\n }\n\n getState(props = this.props) {\n return getState(props, this.parentManager)\n }\n\n #allKeys: Set<string> | null = null\n get allKeys() {\n this.#allKeys ??= new Set([\n ...(this.parentManager?.allKeys || []),\n ...Object.keys(this.state.theme || {}),\n ])\n return this.#allKeys\n }\n\n // gets value going up to parents\n getValue(key: string, state?: ThemeManagerState) {\n let theme = (state || this.state).theme\n let manager = this as ThemeManager | null\n while (theme && manager) {\n if (key in theme) {\n return theme[key]\n }\n manager = manager.parentManager\n theme = manager?.state.theme\n }\n }\n\n notify() {\n this.themeListeners.forEach((cb) => cb(this.state.name, this))\n }\n\n onChangeTheme(cb: ThemeListener) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, isInverting = false) {\n const next = `${THEME_CLASSNAME_PREFIX}${name}`\n if (isInverting) {\n return next\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error(`Cannot reset + set new name`)\n }\n if (props.reset && !parentManager?.parentManager) {\n throw new Error(`Cannot reset no grandparent exists`)\n }\n\n const nextName = props.reset ? parentManager?.parentManager?.state?.name || '' : props.name || ''\n const { componentName } = props\n const parentName = parentManager?.state?.name || ''\n\n // components look for most specific, fallback upwards\n const base = parentName.split(THEME_NAME_SEPARATOR)\n const lastSegment = base[base.length - 1]\n const isParentAComponentTheme = parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentAComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentAComponentTheme\n ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)\n : parentName\n const max = base.length\n const min = componentName\n ? max // component themes don't search upwards\n : 0\n\n // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') console.log('getState', props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme, parentManager })\n\n for (let i = max; i >= min; i--) {\n let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)\n if (props.inverse) {\n prefix = inverseThemeName(prefix)\n }\n const potentials: string[] = []\n if (prefix && prefix !== parentBaseTheme) {\n potentials.push(prefix)\n }\n if (nextName) {\n potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)\n }\n if (i === 1) {\n const lastSegment = potentials.findIndex((x) => !x.includes('_'))\n if (lastSegment > 0) {\n potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent\n }\n }\n if (componentName) {\n // components only look for component themes\n if (nextName) {\n potentials.push(`${prefix.replace(/_.*$/, '')}_${nextName}_${componentName}`)\n }\n potentials.push(`${prefix}_${componentName}`)\n if (nextName) {\n potentials.unshift(`${prefix}_${nextName}_${componentName}`)\n }\n }\n\n // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') console.log('getState potentials', potentials)\n\n const found = potentials.find((t) => t in themes)\n if (found) {\n // optimization return null if not changed\n if (found === parentName) {\n return null\n }\n const theme = themes[found]\n return {\n // need to put concurrent safe things here\n name: found,\n theme: getThemeUnwrapped(theme),\n className: getNextThemeClassName(found, props.inverse),\n parentName,\n }\n }\n }\n\n return null\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\n ? themeName.replace(/^light/, 'dark')\n : themeName.replace(/^dark/, 'light')\n}\n"],
5
+ "mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB,4BAA4B;AAC7D,SAAS,yBAAyB;AAoBlC,MAAM,aAAgC,EAAE,MAAM,GAAG;AAE1C,SAAS,wBAAwB,OAAmB;AACzD,SAAO,CAAC,MAAM,QAAQ,CAAC,MAAM,iBAAiB,CAAC,MAAM,WAAW,CAAC,MAAM;AACzE;AAEO,MAAM,aAAa;AAAA,EAKxB,YACS,QAAoB,CAAC,GAC5B,eACA;AAFO;AALT,0BAAiB,oBAAI,IAAmB;AACxC,yBAAqC;AACrC,iBAA2B;AA+D3B,oBAA+B;AAzD7B,QAAI,kBAAkB,QAAQ;AAC5B,WAAK,YAAY,OAAO,KAAK;AAC7B;AAAA,IACF;AACA,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA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