@tamagui/core 1.0.0-alpha.11 → 1.0.0-alpha.12

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 (241) hide show
  1. package/dist/cjs/types.js.map +1 -1
  2. package/dist/esm/constants/constants.js +14 -0
  3. package/dist/esm/constants/constants.js.map +7 -0
  4. package/dist/esm/constants/platform.js +19 -0
  5. package/dist/esm/constants/platform.js.map +7 -0
  6. package/dist/esm/constants/pseudos.js +18 -0
  7. package/dist/esm/constants/pseudos.js.map +7 -0
  8. package/dist/esm/constants/rnw.js +22 -0
  9. package/dist/esm/constants/rnw.js.map +7 -0
  10. package/dist/esm/createComponent.js +464 -0
  11. package/dist/esm/createComponent.js.map +7 -0
  12. package/dist/esm/createFont.js +28 -0
  13. package/dist/esm/createFont.js.map +7 -0
  14. package/dist/esm/createShorthands.js +10 -0
  15. package/dist/esm/createShorthands.js.map +7 -0
  16. package/dist/esm/createTamagui.js +168 -0
  17. package/dist/esm/createTamagui.js.map +7 -0
  18. package/dist/esm/createTheme.js +20 -0
  19. package/dist/esm/createTheme.js.map +7 -0
  20. package/dist/esm/createTokens.js +33 -0
  21. package/dist/esm/createTokens.js.map +7 -0
  22. package/dist/esm/createVariable.js +25 -0
  23. package/dist/esm/createVariable.js.map +7 -0
  24. package/dist/esm/helpers/addStylesUsingClassname.js +57 -0
  25. package/dist/esm/helpers/addStylesUsingClassname.js.map +7 -0
  26. package/dist/esm/helpers/createMediaStyle.js +34 -0
  27. package/dist/esm/helpers/createMediaStyle.js.map +7 -0
  28. package/dist/esm/helpers/createPropMapper.js +160 -0
  29. package/dist/esm/helpers/createPropMapper.js.map +7 -0
  30. package/dist/esm/helpers/createTamaguiProvider.js +25 -0
  31. package/dist/esm/helpers/createTamaguiProvider.js.map +7 -0
  32. package/dist/esm/helpers/extendStaticConfig.js +59 -0
  33. package/dist/esm/helpers/extendStaticConfig.js.map +7 -0
  34. package/dist/esm/helpers/fixNativeShadow.js +8 -0
  35. package/dist/esm/helpers/fixNativeShadow.js.map +7 -0
  36. package/dist/esm/helpers/fixNativeShadow.native.js +30 -0
  37. package/dist/esm/helpers/fixNativeShadow.native.js.map +7 -0
  38. package/dist/esm/helpers/getSplitStyles.js +150 -0
  39. package/dist/esm/helpers/getSplitStyles.js.map +7 -0
  40. package/dist/esm/helpers/getStylesAtomic.js +83 -0
  41. package/dist/esm/helpers/getStylesAtomic.js.map +7 -0
  42. package/dist/esm/helpers/getStylesAtomic.native.js +10 -0
  43. package/dist/esm/helpers/getStylesAtomic.native.js.map +7 -0
  44. package/dist/esm/helpers/insertStyleRule.js +24 -0
  45. package/dist/esm/helpers/insertStyleRule.js.map +7 -0
  46. package/dist/esm/helpers/isObj.js +7 -0
  47. package/dist/esm/helpers/isObj.js.map +7 -0
  48. package/dist/esm/helpers/isTamaguiElement.js +10 -0
  49. package/dist/esm/helpers/isTamaguiElement.js.map +7 -0
  50. package/dist/esm/helpers/matchMedia.js +18 -0
  51. package/dist/esm/helpers/matchMedia.js.map +7 -0
  52. package/dist/esm/helpers/matchMedia.native.js +9 -0
  53. package/dist/esm/helpers/matchMedia.native.js.map +7 -0
  54. package/dist/esm/helpers/themeable.js +26 -0
  55. package/dist/esm/helpers/themeable.js.map +7 -0
  56. package/dist/esm/helpers/validate.js +60 -0
  57. package/dist/esm/helpers/validate.js.map +7 -0
  58. package/dist/esm/hooks/useConstant.js +15 -0
  59. package/dist/esm/hooks/useConstant.js.map +7 -0
  60. package/dist/esm/hooks/useFeatures.js +63 -0
  61. package/dist/esm/hooks/useFeatures.js.map +7 -0
  62. package/dist/esm/hooks/useMedia.js +173 -0
  63. package/dist/esm/hooks/useMedia.js.map +7 -0
  64. package/dist/esm/hooks/usePressable.js +13 -0
  65. package/dist/esm/hooks/usePressable.js.map +7 -0
  66. package/dist/esm/hooks/useTheme.js +89 -0
  67. package/dist/esm/hooks/useTheme.js.map +7 -0
  68. package/dist/esm/index.js +32 -0
  69. package/dist/esm/index.js.map +7 -0
  70. package/dist/esm/static/postProcessStyles.js +18 -0
  71. package/dist/esm/static/postProcessStyles.js.map +7 -0
  72. package/dist/esm/static.js +15 -0
  73. package/dist/esm/static.js.map +7 -0
  74. package/dist/esm/styled.js +21 -0
  75. package/dist/esm/styled.js.map +7 -0
  76. package/dist/esm/types.js +1 -0
  77. package/dist/esm/types.js.map +7 -0
  78. package/dist/esm/views/Animated.js +79 -0
  79. package/dist/esm/views/Animated.js.map +7 -0
  80. package/dist/esm/views/Stack.js +12 -0
  81. package/dist/esm/views/Stack.js.map +7 -0
  82. package/dist/esm/views/Text.js +60 -0
  83. package/dist/esm/views/Text.js.map +7 -0
  84. package/dist/esm/views/TextAncestorContext.js +18 -0
  85. package/dist/esm/views/TextAncestorContext.js.map +7 -0
  86. package/dist/esm/views/Theme.js +68 -0
  87. package/dist/esm/views/Theme.js.map +7 -0
  88. package/dist/esm/views/ThemeContext.js +6 -0
  89. package/dist/esm/views/ThemeContext.js.map +7 -0
  90. package/dist/esm/views/ThemeInverse.js +26 -0
  91. package/dist/esm/views/ThemeInverse.js.map +7 -0
  92. package/dist/esm/views/ThemeManagerContext.js +61 -0
  93. package/dist/esm/views/ThemeManagerContext.js.map +7 -0
  94. package/dist/esm/views/ThemeProvider.js +45 -0
  95. package/dist/esm/views/ThemeProvider.js.map +7 -0
  96. package/dist/jsx/constants/constants.js +13 -0
  97. package/dist/jsx/constants/platform.js +18 -0
  98. package/dist/jsx/constants/pseudos.js +17 -0
  99. package/dist/jsx/constants/rnw.js +21 -0
  100. package/dist/jsx/createComponent.js +458 -0
  101. package/dist/jsx/createFont.js +27 -0
  102. package/dist/jsx/createShorthands.js +9 -0
  103. package/dist/jsx/createTamagui.js +167 -0
  104. package/dist/jsx/createTheme.js +19 -0
  105. package/dist/jsx/createTokens.js +32 -0
  106. package/dist/jsx/createVariable.js +24 -0
  107. package/dist/jsx/helpers/addStylesUsingClassname.js +56 -0
  108. package/dist/jsx/helpers/createMediaStyle.js +33 -0
  109. package/dist/jsx/helpers/createPropMapper.js +159 -0
  110. package/dist/jsx/helpers/createTamaguiProvider.js +19 -0
  111. package/dist/jsx/helpers/extendStaticConfig.js +58 -0
  112. package/dist/jsx/helpers/fixNativeShadow.js +7 -0
  113. package/dist/jsx/helpers/fixNativeShadow.native.js +29 -0
  114. package/dist/jsx/helpers/getSplitStyles.js +149 -0
  115. package/dist/jsx/helpers/getStylesAtomic.js +82 -0
  116. package/dist/jsx/helpers/getStylesAtomic.native.js +9 -0
  117. package/dist/jsx/helpers/insertStyleRule.js +23 -0
  118. package/dist/jsx/helpers/isObj.js +6 -0
  119. package/dist/jsx/helpers/isTamaguiElement.js +9 -0
  120. package/dist/jsx/helpers/matchMedia.js +17 -0
  121. package/dist/jsx/helpers/matchMedia.native.js +8 -0
  122. package/dist/jsx/helpers/themeable.js +23 -0
  123. package/dist/jsx/helpers/validate.js +59 -0
  124. package/dist/jsx/hooks/useConstant.js +14 -0
  125. package/dist/jsx/hooks/useFeatures.js +57 -0
  126. package/dist/jsx/hooks/useMedia.js +172 -0
  127. package/dist/jsx/hooks/usePressable.js +12 -0
  128. package/dist/jsx/hooks/useTheme.js +88 -0
  129. package/dist/jsx/index.js +31 -0
  130. package/dist/jsx/static/postProcessStyles.js +17 -0
  131. package/dist/jsx/static.js +14 -0
  132. package/dist/jsx/styled.js +20 -0
  133. package/dist/jsx/types.js +0 -0
  134. package/dist/jsx/views/Animated.js +74 -0
  135. package/dist/jsx/views/Stack.js +11 -0
  136. package/dist/jsx/views/Text.js +59 -0
  137. package/dist/jsx/views/TextAncestorContext.js +14 -0
  138. package/dist/jsx/views/Theme.js +62 -0
  139. package/dist/jsx/views/ThemeContext.js +5 -0
  140. package/dist/jsx/views/ThemeInverse.js +22 -0
  141. package/dist/jsx/views/ThemeManagerContext.js +60 -0
  142. package/dist/jsx/views/ThemeProvider.js +39 -0
  143. package/package.json +10 -11
  144. package/src/createComponent.tsx +1 -1
  145. package/src/types.tsx +6 -6
  146. package/src/views/Text.tsx +2 -1
  147. package/types/constants/constants.d.ts +8 -0
  148. package/types/constants/constants.d.ts.map +1 -0
  149. package/types/constants/platform.d.ts +9 -0
  150. package/types/constants/platform.d.ts.map +1 -0
  151. package/types/constants/pseudos.d.ts +15 -0
  152. package/types/constants/pseudos.d.ts.map +1 -0
  153. package/types/constants/rnw.d.ts +2 -0
  154. package/types/constants/rnw.d.ts.map +1 -0
  155. package/types/createComponent.d.ts +17 -0
  156. package/types/createComponent.d.ts.map +1 -0
  157. package/types/createFont.d.ts +3 -0
  158. package/types/createFont.d.ts.map +1 -0
  159. package/types/createShorthands.d.ts +2 -0
  160. package/types/createShorthands.d.ts.map +1 -0
  161. package/types/createTamagui.d.ts +38 -0
  162. package/types/createTamagui.d.ts.map +1 -0
  163. package/types/createTheme.d.ts +5 -0
  164. package/types/createTheme.d.ts.map +1 -0
  165. package/types/createTokens.d.ts +55 -0
  166. package/types/createTokens.d.ts.map +1 -0
  167. package/types/createVariable.d.ts +15 -0
  168. package/types/createVariable.d.ts.map +1 -0
  169. package/types/helpers/addStylesUsingClassname.d.ts +3 -0
  170. package/types/helpers/addStylesUsingClassname.d.ts.map +1 -0
  171. package/types/helpers/createMediaStyle.d.ts +8 -0
  172. package/types/helpers/createMediaStyle.d.ts.map +1 -0
  173. package/types/helpers/createPropMapper.d.ts +3 -0
  174. package/types/helpers/createPropMapper.d.ts.map +1 -0
  175. package/types/helpers/createTamaguiProvider.d.ts +5 -0
  176. package/types/helpers/createTamaguiProvider.d.ts.map +1 -0
  177. package/types/helpers/extendStaticConfig.d.ts +5 -0
  178. package/types/helpers/extendStaticConfig.d.ts.map +1 -0
  179. package/types/helpers/fixNativeShadow.d.ts +2 -0
  180. package/types/helpers/fixNativeShadow.d.ts.map +1 -0
  181. package/types/helpers/fixNativeShadow.native.d.ts +2 -0
  182. package/types/helpers/fixNativeShadow.native.d.ts.map +1 -0
  183. package/types/helpers/getSplitStyles.d.ts +15 -0
  184. package/types/helpers/getSplitStyles.d.ts.map +1 -0
  185. package/types/helpers/getStylesAtomic.d.ts +3 -0
  186. package/types/helpers/getStylesAtomic.d.ts.map +1 -0
  187. package/types/helpers/getStylesAtomic.native.d.ts +2 -0
  188. package/types/helpers/getStylesAtomic.native.d.ts.map +1 -0
  189. package/types/helpers/insertStyleRule.d.ts +2 -0
  190. package/types/helpers/insertStyleRule.d.ts.map +1 -0
  191. package/types/helpers/isObj.d.ts +2 -0
  192. package/types/helpers/isObj.d.ts.map +1 -0
  193. package/types/helpers/isTamaguiElement.d.ts +3 -0
  194. package/types/helpers/isTamaguiElement.d.ts.map +1 -0
  195. package/types/helpers/matchMedia.d.ts +2 -0
  196. package/types/helpers/matchMedia.d.ts.map +1 -0
  197. package/types/helpers/matchMedia.native.d.ts +3 -0
  198. package/types/helpers/matchMedia.native.d.ts.map +1 -0
  199. package/types/helpers/themeable.d.ts +10 -0
  200. package/types/helpers/themeable.d.ts.map +1 -0
  201. package/types/helpers/validate.d.ts +4 -0
  202. package/types/helpers/validate.d.ts.map +1 -0
  203. package/types/hooks/useConstant.d.ts +2 -0
  204. package/types/hooks/useConstant.d.ts.map +1 -0
  205. package/types/hooks/useFeatures.d.ts +5 -0
  206. package/types/hooks/useFeatures.d.ts.map +1 -0
  207. package/types/hooks/useMedia.d.ts +16 -0
  208. package/types/hooks/useMedia.d.ts.map +1 -0
  209. package/types/hooks/usePressable.d.ts +3 -0
  210. package/types/hooks/usePressable.d.ts.map +1 -0
  211. package/types/hooks/useTheme.d.ts +20 -0
  212. package/types/hooks/useTheme.d.ts.map +1 -0
  213. package/types/index.d.ts +29 -0
  214. package/types/index.d.ts.map +1 -0
  215. package/types/static/postProcessStyles.d.ts +7 -0
  216. package/types/static/postProcessStyles.d.ts.map +1 -0
  217. package/types/static.d.ts +15 -0
  218. package/types/static.d.ts.map +1 -0
  219. package/types/styled.d.ts +21 -0
  220. package/types/styled.d.ts.map +1 -0
  221. package/types/types.d.ts +306 -0
  222. package/types/types.d.ts.map +1 -0
  223. package/types/views/Animated.d.ts +15 -0
  224. package/types/views/Animated.d.ts.map +1 -0
  225. package/types/views/Stack.d.ts +3 -0
  226. package/types/views/Stack.d.ts.map +1 -0
  227. package/types/views/Text.d.ts +3 -0
  228. package/types/views/Text.d.ts.map +1 -0
  229. package/types/views/TextAncestorContext.d.ts +3 -0
  230. package/types/views/TextAncestorContext.d.ts.map +1 -0
  231. package/types/views/Theme.d.ts +8 -0
  232. package/types/views/Theme.d.ts.map +1 -0
  233. package/types/views/ThemeContext.d.ts +18 -0
  234. package/types/views/ThemeContext.d.ts.map +1 -0
  235. package/types/views/ThemeInverse.d.ts +10 -0
  236. package/types/views/ThemeInverse.d.ts.map +1 -0
  237. package/types/views/ThemeManagerContext.d.ts +22 -0
  238. package/types/views/ThemeManagerContext.d.ts.map +1 -0
  239. package/types/views/ThemeProvider.d.ts +10 -0
  240. package/types/views/ThemeProvider.d.ts.map +1 -0
  241. package/types.d.ts +0 -559
@@ -0,0 +1,88 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { useForceUpdate } from "@tamagui/use-force-update";
4
+ import { useContext, useEffect, useMemo, useRef, useState } from "react";
5
+ import { useIsomorphicLayoutEffect } from "../constants/platform";
6
+ import { Variable } from "../createVariable";
7
+ import { ThemeContext } from "../views/ThemeContext";
8
+ import { ThemeManagerContext } from "../views/ThemeManagerContext";
9
+ import { GET_DEFAULT_THEME } from "../views/ThemeProvider";
10
+ const areEqualSets = /* @__PURE__ */ __name((a, b) => {
11
+ if (a.size !== b.size)
12
+ return false;
13
+ for (const val in a) {
14
+ if (!b.has(val)) {
15
+ return false;
16
+ }
17
+ }
18
+ return true;
19
+ }, "areEqualSets");
20
+ const useThemeName = /* @__PURE__ */ __name((opts) => {
21
+ const parent = useContext(ThemeManagerContext);
22
+ const [name, setName] = useState(parent.name);
23
+ useIsomorphicLayoutEffect(() => {
24
+ return parent.onChangeTheme((next, manager) => {
25
+ setName(opts?.parent ? manager.parentName : next);
26
+ });
27
+ }, [parent]);
28
+ return name || "light";
29
+ }, "useThemeName");
30
+ const useDefaultThemeName = /* @__PURE__ */ __name(() => {
31
+ return useContext(ThemeContext)[GET_DEFAULT_THEME];
32
+ }, "useDefaultThemeName");
33
+ const useTheme = /* @__PURE__ */ __name(() => {
34
+ const forceUpdate = useForceUpdate();
35
+ const manager = useContext(ThemeManagerContext);
36
+ const themes = useContext(ThemeContext);
37
+ const state = useRef();
38
+ if (!state.current) {
39
+ state.current = {
40
+ uuid: {},
41
+ keys: new Set(),
42
+ isRendering: true
43
+ };
44
+ }
45
+ state.current.isRendering = true;
46
+ useIsomorphicLayoutEffect(() => {
47
+ const st = state.current;
48
+ st.isRendering = false;
49
+ const cur = manager.keys.get(st.uuid);
50
+ if (!cur || !areEqualSets(st.keys, cur)) {
51
+ manager.track(st.uuid, st.keys);
52
+ }
53
+ });
54
+ useEffect(() => {
55
+ return manager.onUpdate(state.current.uuid, forceUpdate);
56
+ }, []);
57
+ const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light;
58
+ return useMemo(() => {
59
+ return new Proxy(theme, {
60
+ get(_, key) {
61
+ const name = manager.name;
62
+ if (!name) {
63
+ return Reflect.get(_, key);
64
+ }
65
+ let activeTheme = themes[name];
66
+ if (!activeTheme) {
67
+ console.error("No theme by name", name, "only:", themes, "keeping current theme");
68
+ activeTheme = theme;
69
+ }
70
+ const val = activeTheme[key];
71
+ if (process.env.NODE_ENV === "development") {
72
+ if (typeof val === "undefined") {
73
+ throw new Error(`No theme value "${String(key)}" in: ${Object.keys(activeTheme)}`);
74
+ }
75
+ }
76
+ if (state.current.isRendering) {
77
+ state.current.keys.add(key);
78
+ }
79
+ return new Variable({ val: val.val, name: key });
80
+ }
81
+ });
82
+ }, []);
83
+ }, "useTheme");
84
+ export {
85
+ useDefaultThemeName,
86
+ useTheme,
87
+ useThemeName
88
+ };
@@ -0,0 +1,31 @@
1
+ export * from "./createComponent";
2
+ export * from "./createShorthands";
3
+ export * from "./createTheme";
4
+ export * from "./createTamagui";
5
+ export * from "./createFont";
6
+ import { createTokens } from "./createTokens";
7
+ export * from "./createVariable";
8
+ export * from "./styled";
9
+ export * from "./types";
10
+ export * from "./constants/pseudos";
11
+ export * from "./constants/constants";
12
+ export * from "./constants/platform";
13
+ export * from "./constants/rnw";
14
+ export * from "./helpers/isObj";
15
+ export * from "./helpers/getStylesAtomic";
16
+ export * from "./helpers/matchMedia";
17
+ export * from "./helpers/themeable";
18
+ export * from "./helpers/isTamaguiElement";
19
+ export * from "./hooks/useConstant";
20
+ export * from "./hooks/useMedia";
21
+ export * from "./hooks/useTheme";
22
+ export * from "./views/Animated";
23
+ export * from "./views/Stack";
24
+ export * from "./views/Text";
25
+ export * from "./views/Theme";
26
+ export * from "./views/ThemeInverse";
27
+ export * from "./views/ThemeProvider";
28
+ export * from "./views/TextAncestorContext";
29
+ export {
30
+ createTokens
31
+ };
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { getSplitStyles } from "../helpers/getSplitStyles";
4
+ const postProcessStyles = /* @__PURE__ */ __name((inStyles, staticConfig, theme) => {
5
+ const { style, viewProps, pseudos, classNames } = getSplitStyles(inStyles, staticConfig, theme);
6
+ const next = {};
7
+ for (const s of style) {
8
+ if (!s)
9
+ continue;
10
+ Object.assign(next, s);
11
+ }
12
+ Object.assign(next, pseudos);
13
+ return { style: next, viewProps, classNames };
14
+ }, "postProcessStyles");
15
+ export {
16
+ postProcessStyles
17
+ };
@@ -0,0 +1,14 @@
1
+ export * from "./styled";
2
+ export * from "./createComponent";
3
+ export * from "./createFont";
4
+ export * from "./createTokens";
5
+ export * from "./createTamagui";
6
+ export * from "./constants/constants";
7
+ export * from "./hooks/useMedia";
8
+ export * from "./hooks/useTheme";
9
+ export * from "./helpers/isObj";
10
+ export * from "./helpers/getStylesAtomic";
11
+ export * from "./helpers/getSplitStyles";
12
+ export * from "@tamagui/helpers";
13
+ export * from "./constants/pseudos";
14
+ export * from "./static/postProcessStyles";
@@ -0,0 +1,20 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { createComponent } from "./createComponent";
4
+ import { extendStaticConfig } from "./helpers/extendStaticConfig";
5
+ function styled(Component, options, staticExtractionOptions) {
6
+ const staticConfigProps = (() => {
7
+ if (options) {
8
+ const { variants, ...defaultProps } = options;
9
+ return { ...staticExtractionOptions, variants, defaultProps };
10
+ }
11
+ return {};
12
+ })();
13
+ const config = extendStaticConfig(Component, staticConfigProps);
14
+ const component = createComponent(config);
15
+ return component;
16
+ }
17
+ __name(styled, "styled");
18
+ export {
19
+ styled
20
+ };
File without changes
@@ -0,0 +1,74 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { useMemo } from "react";
4
+ import {
5
+ Animated
6
+ } from "react-native";
7
+ import { useIsomorphicLayoutEffect } from "../constants/platform";
8
+ import { useConstant } from "../hooks/useConstant";
9
+ import { Stack } from "./Stack";
10
+ const defaultAnimation = {
11
+ from: {
12
+ opacity: 0,
13
+ translateY: 12
14
+ },
15
+ to: {
16
+ opacity: 1,
17
+ translateY: 0
18
+ }
19
+ };
20
+ const styleKeys = {
21
+ opacity: true,
22
+ backgroundColor: true,
23
+ borderColor: true
24
+ };
25
+ const AnimatedStack = /* @__PURE__ */ __name(({
26
+ animateState = "in",
27
+ animation = defaultAnimation,
28
+ velocity = 6,
29
+ children,
30
+ animated,
31
+ ...props
32
+ }) => {
33
+ const driver = useConstant(() => {
34
+ return new Animated.Value(0);
35
+ });
36
+ const animatedProps = useMemo(() => {
37
+ if (!animated) {
38
+ return null;
39
+ }
40
+ const styleProps = {};
41
+ const transform = [];
42
+ for (const key in animation.from) {
43
+ const fromVal = animation.from[key];
44
+ const toVal = animation.to[key];
45
+ const interpolatedVal = driver.interpolate({
46
+ inputRange: [0, 1],
47
+ outputRange: [fromVal, toVal]
48
+ });
49
+ if (styleKeys[key]) {
50
+ styleProps[key] = interpolatedVal;
51
+ } else {
52
+ transform.push({
53
+ [key]: interpolatedVal
54
+ });
55
+ }
56
+ }
57
+ return { transform, ...styleProps };
58
+ }, [animated, animateState]);
59
+ useIsomorphicLayoutEffect(() => {
60
+ if (!animated) {
61
+ return;
62
+ }
63
+ Animated.spring(driver, {
64
+ useNativeDriver: true,
65
+ velocity,
66
+ toValue: animateState === "in" ? 1 : 0
67
+ }).start();
68
+ }, [animated, animateState]);
69
+ const childrenMemo = useMemo(() => children, [children]);
70
+ return <Stack animated={animated} {...props} {...animatedProps}>{childrenMemo}</Stack>;
71
+ }, "AnimatedStack");
72
+ export {
73
+ AnimatedStack
74
+ };
@@ -0,0 +1,11 @@
1
+ import { stackDefaultStyles } from "../constants/constants";
2
+ import { createComponent } from "../createComponent";
3
+ const Stack = createComponent({
4
+ defaultProps: {
5
+ ...stackDefaultStyles,
6
+ flexDirection: "column"
7
+ }
8
+ });
9
+ export {
10
+ Stack
11
+ };
@@ -0,0 +1,59 @@
1
+ import { isWeb } from "../constants/platform";
2
+ import { createComponent } from "../createComponent";
3
+ import { stylePropsTextOnly, validStyles } from "../static";
4
+ const ellipseStyle = {
5
+ maxWidth: "100%",
6
+ overflow: "hidden",
7
+ textOverflow: "ellipsis",
8
+ whiteSpace: "nowrap"
9
+ };
10
+ const Text = createComponent({
11
+ isText: true,
12
+ defaultProps: {
13
+ display: isWeb ? "inline" : "inline-flex",
14
+ boxSizing: "border-box",
15
+ fontFamily: "System",
16
+ wordWrap: "break-word"
17
+ },
18
+ variants: {
19
+ numberOfLines: {
20
+ 1: ellipseStyle,
21
+ "[number]": (lines) => lines > 1 ? { WebkitLineClamp: 1 } : null
22
+ },
23
+ selectable: {
24
+ true: {
25
+ userSelect: "text"
26
+ },
27
+ false: {
28
+ userSelect: "none"
29
+ }
30
+ },
31
+ pressable: {
32
+ true: {
33
+ cursor: "pointer"
34
+ }
35
+ },
36
+ ellipse: {
37
+ true: isWeb ? ellipseStyle : {
38
+ numberOfLines: 1,
39
+ lineBreakMode: "clip"
40
+ }
41
+ }
42
+ },
43
+ deoptProps: new Set(isWeb ? [] : ["ellipse"]),
44
+ validStyles: {
45
+ ...validStyles,
46
+ ...stylePropsTextOnly,
47
+ ...isWeb && {
48
+ userSelect: true,
49
+ textOverflow: true,
50
+ whiteSpace: true,
51
+ wordWrap: true,
52
+ selectable: true,
53
+ cursor: true
54
+ }
55
+ }
56
+ });
57
+ export {
58
+ Text
59
+ };
@@ -0,0 +1,14 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { rnw } from "../constants/rnw";
4
+ const TextAncestorContext = rnw?.TextAncestorContext;
5
+ const TextAncestorProvider = /* @__PURE__ */ __name((props) => {
6
+ if (TextAncestorContext) {
7
+ return <TextAncestorContext.Provider value={false}>{props.children}</TextAncestorContext.Provider>;
8
+ }
9
+ return props.children;
10
+ }, "TextAncestorProvider");
11
+ export {
12
+ TextAncestorContext,
13
+ TextAncestorProvider
14
+ };
@@ -0,0 +1,62 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { useContext, useState } from "react";
4
+ import { isWeb, useIsomorphicLayoutEffect } from "../constants/platform";
5
+ import { getThemeParentClassName } from "../createTamagui";
6
+ import { useConstant } from "../hooks/useConstant";
7
+ import { ThemeContext } from "./ThemeContext";
8
+ import { ThemeManager, ThemeManagerContext } from "./ThemeManagerContext";
9
+ const Theme = /* @__PURE__ */ __name((props) => {
10
+ const parent = useContext(ThemeManagerContext);
11
+ const themes = useContext(ThemeContext);
12
+ const [parentName, setParentName] = useState(parent.name || "light");
13
+ if (!themes) {
14
+ console.warn("Error, no themes in context", props);
15
+ return props.children;
16
+ }
17
+ const nextNameParent = `${props.name}-${parentName}`;
18
+ const nextNameParentParent = `${props.name}-${parent.parentName}`;
19
+ const name = !props.name ? null : props.name in themes ? props.name : nextNameParent in themes ? nextNameParent : nextNameParentParent in themes ? nextNameParentParent : null;
20
+ const theme = name ? themes[name] : null;
21
+ const themeManager = useConstant(() => {
22
+ if (!theme) {
23
+ return null;
24
+ }
25
+ const manager = new ThemeManager();
26
+ if (name) {
27
+ manager.setActiveTheme({ name, theme: themes[name], parentName });
28
+ }
29
+ return manager;
30
+ });
31
+ useIsomorphicLayoutEffect(() => {
32
+ if (!themeManager) {
33
+ return;
34
+ }
35
+ if (name) {
36
+ themeManager.setActiveTheme({ name, theme, parentName });
37
+ }
38
+ return parent.onChangeTheme((next) => {
39
+ if (next) {
40
+ themeManager.setActiveTheme({ name: next, theme: themes[next], parentName });
41
+ setParentName(next);
42
+ }
43
+ });
44
+ }, [themes, name, parentName]);
45
+ if (!name || !theme) {
46
+ return props.children;
47
+ }
48
+ const contents = themeManager ? <ThemeManagerContext.Provider value={themeManager}>{props.children}</ThemeManagerContext.Provider> : props.children;
49
+ if (isWeb) {
50
+ if (props.disableThemeClass) {
51
+ return contents;
52
+ }
53
+ if (name) {
54
+ const color = themes[name]?.["color"]?.["variable"];
55
+ return <div className={getThemeParentClassName(props.name)} style={{ display: "contents", color }}>{contents}</div>;
56
+ }
57
+ }
58
+ return contents;
59
+ }, "Theme");
60
+ export {
61
+ Theme
62
+ };
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+ const ThemeContext = createContext(null);
3
+ export {
4
+ ThemeContext
5
+ };
@@ -0,0 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { useDefaultThemeName, useThemeName } from "../hooks/useTheme";
4
+ import { Theme } from "./Theme";
5
+ let inversions = {
6
+ light: "dark",
7
+ dark: "light"
8
+ };
9
+ function setThemeInversions(next) {
10
+ inversions = next;
11
+ }
12
+ __name(setThemeInversions, "setThemeInversions");
13
+ const ThemeInverse = /* @__PURE__ */ __name((props) => {
14
+ const themeName = useThemeName();
15
+ const defaultTheme = useDefaultThemeName();
16
+ const name = inversions[themeName] || inversions[defaultTheme] || null;
17
+ return <Theme name={name}>{props.children}</Theme>;
18
+ }, "ThemeInverse");
19
+ export {
20
+ ThemeInverse,
21
+ setThemeInversions
22
+ };
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { createContext } from "react";
4
+ class ThemeManager {
5
+ constructor() {
6
+ this.name = "light";
7
+ this.parentName = null;
8
+ this.keys = new Map();
9
+ this.listeners = new Map();
10
+ this.themeListeners = new Set();
11
+ this.theme = null;
12
+ }
13
+ setActiveTheme({
14
+ name,
15
+ theme,
16
+ parentName
17
+ }) {
18
+ if (name === this.name)
19
+ return;
20
+ this.name = name;
21
+ this.theme = theme;
22
+ this.parentName = parentName || null;
23
+ this.update();
24
+ }
25
+ track(uuid, keys) {
26
+ if (!this.name)
27
+ return;
28
+ this.keys.set(uuid, keys);
29
+ }
30
+ update() {
31
+ if (!this.name) {
32
+ this.keys.clear();
33
+ }
34
+ for (const [uuid, keys] of this.keys.entries()) {
35
+ if (keys.size) {
36
+ this.listeners.get(uuid)?.();
37
+ }
38
+ }
39
+ this.themeListeners.forEach((cb) => cb(this.name, this));
40
+ }
41
+ onChangeTheme(cb) {
42
+ this.themeListeners.add(cb);
43
+ return () => {
44
+ this.themeListeners.delete(cb);
45
+ };
46
+ }
47
+ onUpdate(uuid, cb) {
48
+ this.listeners.set(uuid, cb);
49
+ return () => {
50
+ this.listeners.delete(uuid);
51
+ this.keys.delete(uuid);
52
+ };
53
+ }
54
+ }
55
+ __name(ThemeManager, "ThemeManager");
56
+ const ThemeManagerContext = createContext(new ThemeManager());
57
+ export {
58
+ ThemeManager,
59
+ ThemeManagerContext
60
+ };
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { useMemo } from "react";
4
+ import { useIsomorphicLayoutEffect } from "../constants/platform";
5
+ import { getHasConfigured, getThemeParentClassName } from "../createTamagui";
6
+ import { Theme } from "./Theme";
7
+ import { ThemeContext } from "./ThemeContext";
8
+ const GET_DEFAULT_THEME = "___TGUI";
9
+ const ThemeProvider = /* @__PURE__ */ __name((props) => {
10
+ if (!getHasConfigured()) {
11
+ throw new Error(`Missing configureThemes() call, add to your root file`);
12
+ }
13
+ useIsomorphicLayoutEffect(() => {
14
+ if (props.disableRootThemeClass) {
15
+ return;
16
+ }
17
+ if (typeof document !== "undefined") {
18
+ const cns = getThemeParentClassName(`${props.defaultTheme}`).split(" ");
19
+ cns.forEach((cn) => document.body.classList.add(cn));
20
+ return () => {
21
+ cns.forEach((cn) => document.body.classList.remove(cn));
22
+ };
23
+ }
24
+ }, []);
25
+ const themeContext = useMemo(() => {
26
+ return new Proxy(props.themes, {
27
+ get(target, key) {
28
+ if (key === GET_DEFAULT_THEME)
29
+ return props.defaultTheme;
30
+ return Reflect.get(target, key);
31
+ }
32
+ });
33
+ }, [props.themes]);
34
+ return <ThemeContext.Provider value={themeContext}><Theme name={props.defaultTheme} disableThemeClass={props.disableRootThemeClass}>{props.children}</Theme></ThemeContext.Provider>;
35
+ }, "ThemeProvider");
36
+ export {
37
+ GET_DEFAULT_THEME,
38
+ ThemeProvider
39
+ };
package/package.json CHANGED
@@ -1,25 +1,24 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.12",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist",
7
- "typings": "types.d.ts",
7
+ "typings": "types",
8
8
  "scripts": {
9
- "build": "tamagui-build --separate",
10
- "watch": "tamagui-build --separate --watch"
9
+ "build": "tamagui-build",
10
+ "watch": "tamagui-build --watch"
11
11
  },
12
12
  "files": [
13
- "_",
14
- "types.d.ts",
13
+ "types",
15
14
  "dist",
16
15
  "src"
17
16
  ],
18
17
  "dependencies": {
19
- "@tamagui/helpers": "^1.0.0-alpha.8",
18
+ "@tamagui/helpers": "^1.0.0-alpha.12",
20
19
  "@tamagui/ow": "^0.28.1",
21
- "@tamagui/use-debounce": "^1.0.0-alpha.8",
22
- "@tamagui/use-force-update": "^1.0.0-alpha.8",
20
+ "@tamagui/use-debounce": "^1.0.0-alpha.12",
21
+ "@tamagui/use-force-update": "^1.0.0-alpha.12",
23
22
  "react": "*",
24
23
  "react-dom": "*"
25
24
  },
@@ -27,7 +26,7 @@
27
26
  "react-native-web": "*"
28
27
  },
29
28
  "devDependencies": {
30
- "@tamagui/build": "^1.0.0-alpha.8",
29
+ "@tamagui/build": "^1.0.0-alpha.12",
31
30
  "@types/react": "^17.0.35",
32
31
  "esbuild": "^0.11.20",
33
32
  "typescript": "^4.4.4"
@@ -38,5 +37,5 @@
38
37
  "engines": {
39
38
  "node": ">=16"
40
39
  },
41
- "gitHead": "23209099ee7f37baf2597a9dcded9345ba294fe4"
40
+ "gitHead": "d50261a4e08d2212395af4f2d8f49555fc780c3e"
42
41
  }
@@ -241,7 +241,7 @@ export function createComponent<A extends Object = DefaultProps>(
241
241
  ]
242
242
  : [defaultsClassName, props.className, classNames, stylesClassNames]
243
243
 
244
- // @ts-expect-error
244
+ // @ts-ignore we are optimizing using arguments
245
245
  const className = concatClassName(...classList)
246
246
  if (process.env.NODE_ENV === 'development') {
247
247
  if (props['debug']) {
package/src/types.tsx CHANGED
@@ -225,7 +225,7 @@ export type WithThemeValues<T extends object> = {
225
225
  type WithShorthands<StyleProps> = {
226
226
  [Key in keyof Shorthands]?: Shorthands[Key] extends keyof StyleProps
227
227
  ? StyleProps[Shorthands[Key]] | null
228
- : {}
228
+ : undefined
229
229
  }
230
230
 
231
231
  //
@@ -263,11 +263,11 @@ type WebOnlyStyleProps = {
263
263
  pointerEvents?: ViewProps['pointerEvents']
264
264
  }
265
265
 
266
- type StackStyleProps = WithThemeShorthandsPseudosAndMedia<
267
- Omit<ViewStyle, 'display' | 'backfaceVisibility' | 'elevation'> &
268
- TransformStyleProps &
269
- WebOnlyStyleProps
270
- >
266
+ export type StackStylePropsBase = Omit<ViewStyle, 'display' | 'backfaceVisibility' | 'elevation'> &
267
+ TransformStyleProps &
268
+ WebOnlyStyleProps
269
+
270
+ export type StackStyleProps = WithThemeShorthandsPseudosAndMedia<StackStylePropsBase>
271
271
 
272
272
  export type StackProps = Omit<RNWInternalProps, 'children'> &
273
273
  Omit<ViewProps, 'display' | 'children'> &
@@ -1,6 +1,7 @@
1
+ import { stylePropsTextOnly, validStyles } from '@tamagui/helpers'
2
+
1
3
  import { isWeb } from '../constants/platform'
2
4
  import { createComponent } from '../createComponent'
3
- import { stylePropsTextOnly, validStyles } from '../static'
4
5
  import { TextProps } from '../types'
5
6
 
6
7
  const ellipseStyle = {
@@ -0,0 +1,8 @@
1
+ export declare const stackDefaultStyles: {
2
+ display?: string | undefined;
3
+ flexBasis?: string | undefined;
4
+ boxSizing?: string | undefined;
5
+ alignItems: string;
6
+ flexShrink: number;
7
+ };
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB;;;;;;CAS9B,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { useEffect } from 'react';
2
+ export declare const isWeb: boolean;
3
+ export declare const isSSR: boolean;
4
+ export declare const useIsomorphicLayoutEffect: typeof useEffect;
5
+ export declare const isChrome: boolean;
6
+ export declare const supportsTouchWeb: boolean;
7
+ export declare const isTouchDevice: boolean;
8
+ export declare const isWebIOS: boolean;
9
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/constants/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,OAAO,CAAA;AAGlD,eAAO,MAAM,KAAK,SAAuE,CAAA;AACzF,eAAO,MAAM,KAAK,SAAyC,CAAA;AAC3D,eAAO,MAAM,yBAAyB,kBAAsC,CAAA;AAC5E,eAAO,MAAM,QAAQ,SAA+E,CAAA;AACpG,eAAO,MAAM,gBAAgB,SAA4D,CAAA;AACzF,eAAO,MAAM,aAAa,SAA6B,CAAA;AACvD,eAAO,MAAM,QAAQ,SAKA,CAAA"}
@@ -0,0 +1,15 @@
1
+ export declare const pseudos: {
2
+ focusStyle: {
3
+ name: string;
4
+ priority: number;
5
+ };
6
+ pressStyle: {
7
+ name: string;
8
+ priority: number;
9
+ };
10
+ hoverStyle: {
11
+ name: string;
12
+ priority: number;
13
+ };
14
+ };
15
+ //# sourceMappingURL=pseudos.d.ts.map