@tamagui/web 1.88.13 → 1.89.0-1706308641099
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.
- package/LICENSE +21 -0
- package/dist/cjs/createComponent.js +1 -1
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +1 -1
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.native.js +1 -1
- package/dist/cjs/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/esm/Tamagui.mjs +43 -0
- package/dist/esm/config.mjs +51 -0
- package/dist/esm/constants/accessibilityDirectMap.mjs +50 -0
- package/dist/esm/constants/constants.mjs +16 -0
- package/dist/esm/constants/isDevTools.mjs +7 -0
- package/dist/esm/contexts/ComponentContext.mjs +13 -0
- package/dist/esm/createComponent.js +1 -1
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createComponent.mjs +771 -0
- package/dist/esm/createFont.mjs +18 -0
- package/dist/esm/createShorthands.mjs +4 -0
- package/dist/esm/createTamagui.mjs +206 -0
- package/dist/esm/createTheme.mjs +2 -0
- package/dist/esm/createTokens.mjs +5 -0
- package/dist/esm/createVariable.mjs +48 -0
- package/dist/esm/createVariables.mjs +35 -0
- package/dist/esm/defaultComponentState.mjs +16 -0
- package/dist/esm/helpers/ThemeManager.mjs +156 -0
- package/dist/esm/helpers/ThemeManagerContext.mjs +3 -0
- package/dist/esm/helpers/createMediaStyle.mjs +71 -0
- package/dist/esm/helpers/createShallowSetState.mjs +17 -0
- package/dist/esm/helpers/createStyledContext.mjs +35 -0
- package/dist/esm/helpers/defaultOffset.mjs +5 -0
- package/dist/esm/helpers/expandStyle.mjs +38 -0
- package/dist/esm/helpers/expandStyles.mjs +15 -0
- package/dist/esm/helpers/getExpandedShorthands.mjs +9 -0
- package/dist/esm/helpers/getFontLanguage.mjs +2 -0
- package/dist/esm/helpers/getGroupPropParts.mjs +13 -0
- package/dist/esm/helpers/getSplitStyles.js +1 -1
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.mjs +643 -0
- package/dist/esm/helpers/getSplitStyles.native.js +1 -1
- package/dist/esm/helpers/getSplitStyles.native.js.map +1 -1
- package/dist/esm/helpers/getStylesAtomic.mjs +150 -0
- package/dist/esm/helpers/getThemeCSSRules.mjs +87 -0
- package/dist/esm/helpers/getVariantExtras.mjs +43 -0
- package/dist/esm/helpers/insertStyleRule.mjs +177 -0
- package/dist/esm/helpers/isObj.mjs +2 -0
- package/dist/esm/helpers/isTamaguiComponent.mjs +5 -0
- package/dist/esm/helpers/isTamaguiElement.mjs +4 -0
- package/dist/esm/helpers/log.mjs +4 -0
- package/dist/esm/helpers/matchMedia.mjs +11 -0
- package/dist/esm/helpers/mergeProps.mjs +21 -0
- package/dist/esm/helpers/mergeVariants.mjs +16 -0
- package/dist/esm/helpers/normalizeColor.mjs +17 -0
- package/dist/esm/helpers/normalizeShadow.mjs +23 -0
- package/dist/esm/helpers/normalizeStyle.mjs +23 -0
- package/dist/esm/helpers/normalizeStylePropKeys.mjs +2 -0
- package/dist/esm/helpers/normalizeValueWithProperty.mjs +32 -0
- package/dist/esm/helpers/objectIdentityKey.mjs +15 -0
- package/dist/esm/helpers/propMapper.mjs +239 -0
- package/dist/esm/helpers/proxyThemeToParents.mjs +36 -0
- package/dist/esm/helpers/proxyThemeVariables.mjs +12 -0
- package/dist/esm/helpers/pseudoDescriptors.mjs +34 -0
- package/dist/esm/helpers/registerCSSVariable.mjs +7 -0
- package/dist/esm/helpers/themeable.mjs +33 -0
- package/dist/esm/helpers/themes.mjs +14 -0
- package/dist/esm/helpers/timer.mjs +8 -0
- package/dist/esm/hooks/useConfiguration.mjs +20 -0
- package/dist/esm/hooks/useDisableSSR.mjs +5 -0
- package/dist/esm/hooks/useIsTouchDevice.mjs +4 -0
- package/dist/esm/hooks/useMedia.mjs +146 -0
- package/dist/esm/hooks/useProps.mjs +40 -0
- package/dist/esm/hooks/useTheme.mjs +222 -0
- package/dist/esm/hooks/useThemeName.mjs +15 -0
- package/dist/esm/index.mjs +61 -0
- package/dist/esm/inject-styles.mjs +13 -0
- package/dist/esm/insertFont.mjs +44 -0
- package/dist/esm/interfaces/CSSColorNames.mjs +0 -0
- package/dist/esm/interfaces/GetRef.mjs +0 -0
- package/dist/esm/interfaces/KeyTypes.mjs +0 -0
- package/dist/esm/interfaces/RNExclusiveTypes.mjs +0 -0
- package/dist/esm/interfaces/Role.mjs +0 -0
- package/dist/esm/interfaces/TamaguiComponentEvents.mjs +0 -0
- package/dist/esm/interfaces/TamaguiComponentPropsBaseBase.mjs +0 -0
- package/dist/esm/interfaces/TamaguiComponentState.mjs +0 -0
- package/dist/esm/interfaces/WebOnlyPressEvents.mjs +0 -0
- package/dist/esm/internalWithTheme.mjs +14 -0
- package/dist/esm/setupHooks.mjs +5 -0
- package/dist/esm/setupReactNative.mjs +24 -0
- package/dist/esm/styled.mjs +56 -0
- package/dist/esm/type-utils.mjs +0 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/views/Configuration.mjs +12 -0
- package/dist/esm/views/FontLanguage.mjs +13 -0
- package/dist/esm/views/FontLanguage.types.mjs +0 -0
- package/dist/esm/views/Slot.mjs +53 -0
- package/dist/esm/views/Stack.mjs +10 -0
- package/dist/esm/views/TamaguiProvider.mjs +32 -0
- package/dist/esm/views/Text.mjs +64 -0
- package/dist/esm/views/Theme.mjs +104 -0
- package/dist/esm/views/ThemeDebug.mjs +57 -0
- package/dist/esm/views/ThemeProvider.mjs +20 -0
- package/dist/esm/views/View.mjs +9 -0
- package/package.json +10 -10
- package/src/createComponent.tsx +1 -1
- package/src/helpers/getSplitStyles.tsx +5 -0
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ComponentContext } from "../contexts/ComponentContext.mjs";
|
|
3
|
+
import { defaultComponentStateMounted } from "../defaultComponentState.mjs";
|
|
4
|
+
import { useSplitStyles } from "../helpers/getSplitStyles.mjs";
|
|
5
|
+
import { Stack } from "../views/Stack.mjs";
|
|
6
|
+
import { useMedia } from "./useMedia.mjs";
|
|
7
|
+
import { useThemeWithState } from "./useTheme.mjs";
|
|
8
|
+
function useProps(props, opts) {
|
|
9
|
+
const [propsOut, styleOut] = usePropsAndStyle(props, {
|
|
10
|
+
...opts,
|
|
11
|
+
noExpand: !0,
|
|
12
|
+
noNormalize: !0,
|
|
13
|
+
resolveValues: "none"
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
...propsOut,
|
|
17
|
+
...styleOut
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function useStyle(props, opts) {
|
|
21
|
+
return usePropsAndStyle(props, opts)[1];
|
|
22
|
+
}
|
|
23
|
+
function usePropsAndStyle(props, opts) {
|
|
24
|
+
const staticConfig = opts?.forComponent?.staticConfig ?? Stack.staticConfig,
|
|
25
|
+
[themeState, theme] = useThemeWithState({
|
|
26
|
+
componentName: staticConfig.componentName
|
|
27
|
+
}),
|
|
28
|
+
componentContext = useContext(ComponentContext),
|
|
29
|
+
media = useMedia(),
|
|
30
|
+
splitStyles = useSplitStyles(props, staticConfig, theme, themeState.state?.name || "", defaultComponentStateMounted, {
|
|
31
|
+
isAnimated: !1,
|
|
32
|
+
mediaState: media,
|
|
33
|
+
noSkip: !0,
|
|
34
|
+
noClassNames: !0,
|
|
35
|
+
resolveValues: "auto",
|
|
36
|
+
...opts
|
|
37
|
+
}, null, componentContext);
|
|
38
|
+
return [splitStyles.viewProps, splitStyles.style, theme, media];
|
|
39
|
+
}
|
|
40
|
+
export { useProps, usePropsAndStyle, useStyle };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { isClient, isServer } from "@tamagui/constants";
|
|
2
|
+
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { getConfig } from "../config.mjs";
|
|
4
|
+
import { getVariable } from "../createVariable.mjs";
|
|
5
|
+
import { isEqualShallow } from "../helpers/createShallowSetState.mjs";
|
|
6
|
+
import { ThemeManager, getHasThemeUpdatingProps } from "../helpers/ThemeManager.mjs";
|
|
7
|
+
import { ThemeManagerIDContext } from "../helpers/ThemeManagerContext.mjs";
|
|
8
|
+
const emptyProps = {
|
|
9
|
+
name: null
|
|
10
|
+
};
|
|
11
|
+
let cached;
|
|
12
|
+
function getDefaultThemeProxied() {
|
|
13
|
+
if (cached) return cached;
|
|
14
|
+
const config = getConfig(),
|
|
15
|
+
name = config.themes.light ? "light" : Object.keys(config.themes)[0],
|
|
16
|
+
defaultTheme = config.themes[name];
|
|
17
|
+
return cached = getThemeProxied({
|
|
18
|
+
theme: defaultTheme,
|
|
19
|
+
name
|
|
20
|
+
}), cached;
|
|
21
|
+
}
|
|
22
|
+
const useTheme = (props = emptyProps) => {
|
|
23
|
+
const [_, theme] = useThemeWithState(props);
|
|
24
|
+
return theme || getDefaultThemeProxied();
|
|
25
|
+
},
|
|
26
|
+
useThemeWithState = props => {
|
|
27
|
+
const keys = useRef([]),
|
|
28
|
+
changedThemeState = useChangeThemeEffect(props, !1, keys.current, isServer ? void 0 : () => {
|
|
29
|
+
const next = props.shouldUpdate?.() ?? (keys.current.length > 0 ? !0 : void 0);
|
|
30
|
+
return process.env.NODE_ENV === "development" && typeof props.debug == "string" && props.debug !== "profile" && console.info(" \u{1F3A8} useTheme() shouldUpdate?", next, {
|
|
31
|
+
shouldUpdateProp: props.shouldUpdate?.(),
|
|
32
|
+
keys: [...keys.current]
|
|
33
|
+
}), next;
|
|
34
|
+
}),
|
|
35
|
+
{
|
|
36
|
+
themeManager,
|
|
37
|
+
state
|
|
38
|
+
} = changedThemeState;
|
|
39
|
+
process.env.NODE_ENV === "development" && (state?.theme || process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1" && console.warn(`[tamagui] No theme found, this could be due to an invalid theme name (given theme props ${JSON.stringify(props)}).
|
|
40
|
+
|
|
41
|
+
If this is intended and you are using Tamagui without any themes, you can disable this warning by setting the environment variable TAMAGUI_DISABLE_NO_THEME_WARNING=1`));
|
|
42
|
+
const themeProxied = useMemo(() => !themeManager || !state?.theme ? {} : getThemeProxied(state, props.deopt, themeManager, keys.current, props.debug), [state?.theme, themeManager, props.deopt, props.debug]);
|
|
43
|
+
return process.env.NODE_ENV === "development" && props.debug === "verbose" && (console.groupCollapsed(" \u{1F539} useTheme =>", state?.name), console.info("returning state", changedThemeState, "from props", props), console.groupEnd()), [changedThemeState, themeProxied];
|
|
44
|
+
};
|
|
45
|
+
function getThemeProxied({
|
|
46
|
+
theme,
|
|
47
|
+
name,
|
|
48
|
+
scheme
|
|
49
|
+
}, deopt = !1, themeManager, keys, debug) {
|
|
50
|
+
if (!theme) return {};
|
|
51
|
+
const config = getConfig();
|
|
52
|
+
function track(key) {
|
|
53
|
+
keys && !keys.includes(key) && (keys.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
|
|
54
|
+
}
|
|
55
|
+
return new Proxy(theme, {
|
|
56
|
+
has(_, key) {
|
|
57
|
+
if (Reflect.has(theme, key)) return !0;
|
|
58
|
+
if (typeof key == "string") return key[0] === "$" && (key = key.slice(1)), themeManager?.allKeys.has(key);
|
|
59
|
+
},
|
|
60
|
+
get(_, key) {
|
|
61
|
+
if (
|
|
62
|
+
// dont ask me, idk why but on hermes you can see that useTheme()[undefined] passes in STRING undefined to proxy
|
|
63
|
+
// if someone is crazy enough to use "undefined" as a theme key then this not working is on them
|
|
64
|
+
key !== "undefined" && typeof key == "string") {
|
|
65
|
+
const keyString = key[0] === "$" ? key.slice(1) : key,
|
|
66
|
+
val = theme[keyString];
|
|
67
|
+
if (val && typeof val == "object") return new Proxy(val, {
|
|
68
|
+
// when they touch the actual value we only track it
|
|
69
|
+
// if its a variable (web), its ignored!
|
|
70
|
+
get(_2, subkey) {
|
|
71
|
+
if (subkey === "val") track(keyString);else if (subkey === "get") return platform => getVariable(val);
|
|
72
|
+
return Reflect.get(val, subkey);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (process.env.NODE_ENV === "development" && process.env.TAMAGUI_FEAT_THROW_ON_MISSING_THEME_VALUE === "1") throw new Error(`[tamagui] No theme key "${key}" found in theme ${name}.
|
|
76
|
+
Keys in theme: ${Object.keys(theme).join(", ")}`);
|
|
77
|
+
}
|
|
78
|
+
return Reflect.get(_, key);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const activeThemeManagers = /* @__PURE__ */new Set(),
|
|
83
|
+
_uidToManager = /* @__PURE__ */new WeakMap(),
|
|
84
|
+
_idToUID = {},
|
|
85
|
+
getId = id => _idToUID[id],
|
|
86
|
+
getThemeManager = id => _uidToManager.get(getId(id)),
|
|
87
|
+
registerThemeManager = t => {
|
|
88
|
+
if (!_idToUID[t.id]) {
|
|
89
|
+
const id = _idToUID[t.id] = {};
|
|
90
|
+
_uidToManager.set(id, t);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
useChangeThemeEffect = (props, isRoot = !1, keys, shouldUpdate) => {
|
|
94
|
+
const {
|
|
95
|
+
disable
|
|
96
|
+
} = props,
|
|
97
|
+
parentManagerId = useContext(ThemeManagerIDContext),
|
|
98
|
+
parentManager = getThemeManager(parentManagerId);
|
|
99
|
+
if (!isRoot && !parentManager || disable) return {
|
|
100
|
+
isNewTheme: !1,
|
|
101
|
+
state: parentManager?.state,
|
|
102
|
+
themeManager: parentManager
|
|
103
|
+
};
|
|
104
|
+
const [themeState, setThemeState] = useState(createState),
|
|
105
|
+
{
|
|
106
|
+
state,
|
|
107
|
+
mounted,
|
|
108
|
+
isNewTheme,
|
|
109
|
+
themeManager,
|
|
110
|
+
inversed
|
|
111
|
+
} = themeState,
|
|
112
|
+
isInversingOnMount = !!(!themeState.mounted && props.inverse);
|
|
113
|
+
function getShouldUpdateTheme(manager = themeManager, nextState, prevState = state, forceShouldChange = !1) {
|
|
114
|
+
const forceUpdate = shouldUpdate?.();
|
|
115
|
+
if (!manager || !forceShouldChange && forceUpdate === !1) return;
|
|
116
|
+
const next = nextState || manager.getState(props, parentManager);
|
|
117
|
+
if (forceShouldChange) return next;
|
|
118
|
+
if (next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState))) return next;
|
|
119
|
+
}
|
|
120
|
+
if (isServer || (useEffect(() => {
|
|
121
|
+
if (!themeManager) return;
|
|
122
|
+
if (props.inverse && !mounted) {
|
|
123
|
+
setThemeState(prev => createState({
|
|
124
|
+
...prev,
|
|
125
|
+
mounted: !0
|
|
126
|
+
}));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
(isNewTheme || getShouldUpdateTheme(themeManager)) && (activeThemeManagers.add(themeManager), setThemeState(createState));
|
|
130
|
+
const selfListenerDispose = themeManager.onChangeTheme((_a, _b, forced) => {
|
|
131
|
+
forced && setThemeState(prev => createState(prev, !0));
|
|
132
|
+
}),
|
|
133
|
+
disposeChangeListener = parentManager?.onChangeTheme((name, manager, forced) => {
|
|
134
|
+
const force = forced || shouldUpdate?.() || props.deopt || void 0,
|
|
135
|
+
shouldTryUpdate = force ?? !!(keys?.length || isNewTheme);
|
|
136
|
+
process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F538} onChange", themeManager.id, {
|
|
137
|
+
force,
|
|
138
|
+
shouldTryUpdate,
|
|
139
|
+
props,
|
|
140
|
+
name,
|
|
141
|
+
manager,
|
|
142
|
+
keys
|
|
143
|
+
}), shouldTryUpdate && setThemeState(prev => createState(prev, force));
|
|
144
|
+
}, themeManager.id);
|
|
145
|
+
return () => {
|
|
146
|
+
selfListenerDispose(), disposeChangeListener?.(), isNewTheme && activeThemeManagers.delete(themeManager);
|
|
147
|
+
};
|
|
148
|
+
}, [themeManager, parentManager, isNewTheme, props.componentName, props.inverse, props.name, props.reset, mounted]), process.env.NODE_ENV === "development" && props.debug !== "profile" && useEffect(() => (globalThis.TamaguiThemeManagers ??= /* @__PURE__ */new Set(), globalThis.TamaguiThemeManagers.add(themeManager), () => {
|
|
149
|
+
globalThis.TamaguiThemeManagers.delete(themeManager);
|
|
150
|
+
}), [themeManager])), isInversingOnMount) return {
|
|
151
|
+
isNewTheme: !1,
|
|
152
|
+
inversed: !1,
|
|
153
|
+
themeManager: parentManager,
|
|
154
|
+
state: {
|
|
155
|
+
name: "",
|
|
156
|
+
...parentManager?.state,
|
|
157
|
+
className: ""
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
state,
|
|
162
|
+
isNewTheme,
|
|
163
|
+
inversed,
|
|
164
|
+
themeManager
|
|
165
|
+
};
|
|
166
|
+
function createState(prev, force = !1) {
|
|
167
|
+
if (prev && shouldUpdate?.() === !1 && !force) return prev;
|
|
168
|
+
let themeManager2 = parentManager,
|
|
169
|
+
state2;
|
|
170
|
+
if (getHasThemeUpdatingProps(props)) {
|
|
171
|
+
const getNewThemeManager = () => new ThemeManager(props, isRoot ? "root" : parentManager);
|
|
172
|
+
if (prev?.themeManager) {
|
|
173
|
+
themeManager2 = prev.themeManager;
|
|
174
|
+
const forceChange = force || !!keys?.length,
|
|
175
|
+
next = themeManager2.getState(props, parentManager),
|
|
176
|
+
nextState = getShouldUpdateTheme(themeManager2, next, prev.state, forceChange);
|
|
177
|
+
nextState ? (state2 = nextState, prev.isNewTheme ? themeManager2.updateState(nextState) : themeManager2 = getNewThemeManager()) : prev.isNewTheme && parentManager && !next && (themeManager2 = parentManager);
|
|
178
|
+
} else themeManager2 = getNewThemeManager(), state2 = {
|
|
179
|
+
...themeManager2.state
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const isNewTheme2 = !!(themeManager2 !== parentManager || props.inverse);
|
|
183
|
+
isNewTheme2 && registerThemeManager(themeManager2);
|
|
184
|
+
const mounted2 = props.inverse ? isRoot || prev?.mounted : !0;
|
|
185
|
+
state2 || (isNewTheme2 ? state2 = themeManager2.state : (state2 = parentManager.state, themeManager2 = parentManager));
|
|
186
|
+
const wasInversed = prev?.inversed,
|
|
187
|
+
inversed2 = isNewTheme2 && state2.scheme !== parentManager?.state.scheme ? !0 : wasInversed != null ? !1 : null,
|
|
188
|
+
response = {
|
|
189
|
+
themeManager: themeManager2,
|
|
190
|
+
isNewTheme: isNewTheme2,
|
|
191
|
+
mounted: mounted2,
|
|
192
|
+
inversed: inversed2
|
|
193
|
+
},
|
|
194
|
+
shouldReturnPrev = prev && !force &&
|
|
195
|
+
// isEqualShallow uses the second arg as the keys so this should compare without state first...
|
|
196
|
+
isEqualShallow(prev, response) &&
|
|
197
|
+
// ... and then compare just the state, because we make a new state obj but is likely the same
|
|
198
|
+
isEqualShallow(prev.state, state2);
|
|
199
|
+
if (prev && shouldReturnPrev) return prev;
|
|
200
|
+
if (response.state = state2, process.env.NODE_ENV === "development" && props.debug && isClient) {
|
|
201
|
+
console.groupCollapsed(` \u{1F537} ${themeManager2.id} useChangeThemeEffect createState`);
|
|
202
|
+
const parentState = {
|
|
203
|
+
...parentManager?.state
|
|
204
|
+
},
|
|
205
|
+
parentId = parentManager?.id,
|
|
206
|
+
themeManagerState = {
|
|
207
|
+
...themeManager2.state
|
|
208
|
+
};
|
|
209
|
+
console.info({
|
|
210
|
+
props,
|
|
211
|
+
parentState,
|
|
212
|
+
parentId,
|
|
213
|
+
themeManager: themeManager2,
|
|
214
|
+
prev,
|
|
215
|
+
response,
|
|
216
|
+
themeManagerState
|
|
217
|
+
}), console.groupEnd();
|
|
218
|
+
}
|
|
219
|
+
return response;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
export { activeThemeManagers, getThemeManager, getThemeProxied, useChangeThemeEffect, useTheme, useThemeWithState };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import { useContext, useState } from "react";
|
|
3
|
+
import { ThemeManagerIDContext } from "../helpers/ThemeManagerContext.mjs";
|
|
4
|
+
import { getThemeManager } from "./useTheme.mjs";
|
|
5
|
+
function useThemeName(opts) {
|
|
6
|
+
const manager = getThemeManager(useContext(ThemeManagerIDContext)),
|
|
7
|
+
[name, setName] = useState(manager?.state.name || "");
|
|
8
|
+
return useIsomorphicLayoutEffect(() => {
|
|
9
|
+
if (manager) return setName(manager.state.name), manager.onChangeTheme((next, manager2) => {
|
|
10
|
+
const name2 = opts?.parent && manager2.state.parentName || next;
|
|
11
|
+
name2 && setName(name2);
|
|
12
|
+
});
|
|
13
|
+
}, [manager?.state.name]), name;
|
|
14
|
+
}
|
|
15
|
+
export { useThemeName };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export * from "./Tamagui.mjs";
|
|
2
|
+
export * from "./createComponent.mjs";
|
|
3
|
+
export * from "./createShorthands.mjs";
|
|
4
|
+
export * from "./createTheme.mjs";
|
|
5
|
+
export * from "./createTamagui.mjs";
|
|
6
|
+
export * from "./createFont.mjs";
|
|
7
|
+
export * from "./createTokens.mjs";
|
|
8
|
+
export * from "./createVariable.mjs";
|
|
9
|
+
export * from "./createVariables.mjs";
|
|
10
|
+
export * from "./insertFont.mjs";
|
|
11
|
+
export * from "./styled.mjs";
|
|
12
|
+
export * from "./setupReactNative.mjs";
|
|
13
|
+
export * from "./interfaces/GetRef.mjs";
|
|
14
|
+
import { setupDev, getConfig, getThemes, getTokens, updateConfig, getToken, getTokenValue } from "./config.mjs";
|
|
15
|
+
export * from "./constants/constants.mjs";
|
|
16
|
+
export * from "./contexts/ComponentContext.mjs";
|
|
17
|
+
export * from "./helpers/createStyledContext.mjs";
|
|
18
|
+
export * from "./helpers/expandStyles.mjs";
|
|
19
|
+
export * from "./helpers/createMediaStyle.mjs";
|
|
20
|
+
export * from "./helpers/normalizeStyle.mjs";
|
|
21
|
+
export * from "./helpers/propMapper.mjs";
|
|
22
|
+
export * from "./helpers/getExpandedShorthands.mjs";
|
|
23
|
+
export * from "./helpers/getSplitStyles.mjs";
|
|
24
|
+
export * from "./helpers/getStylesAtomic.mjs";
|
|
25
|
+
export * from "./helpers/getThemeCSSRules.mjs";
|
|
26
|
+
export * from "./helpers/getVariantExtras.mjs";
|
|
27
|
+
export * from "./helpers/isTamaguiComponent.mjs";
|
|
28
|
+
export * from "./helpers/isTamaguiElement.mjs";
|
|
29
|
+
export * from "./helpers/matchMedia.mjs";
|
|
30
|
+
export * from "./helpers/mergeProps.mjs";
|
|
31
|
+
export * from "./helpers/normalizeColor.mjs";
|
|
32
|
+
export * from "./helpers/proxyThemeVariables.mjs";
|
|
33
|
+
export * from "./helpers/proxyThemeToParents.mjs";
|
|
34
|
+
export * from "./helpers/pseudoDescriptors.mjs";
|
|
35
|
+
export * from "./helpers/themeable.mjs";
|
|
36
|
+
export * from "./helpers/themes.mjs";
|
|
37
|
+
export * from "./helpers/createShallowSetState.mjs";
|
|
38
|
+
export * from "./internalWithTheme.mjs";
|
|
39
|
+
import { configureMedia, mediaState, useMedia, getMedia, mediaObjectToString, mediaQueryConfig } from "./hooks/useMedia.mjs";
|
|
40
|
+
export * from "./hooks/useTheme.mjs";
|
|
41
|
+
export * from "./hooks/useThemeName.mjs";
|
|
42
|
+
export * from "./hooks/useConfiguration.mjs";
|
|
43
|
+
export * from "./hooks/useIsTouchDevice.mjs";
|
|
44
|
+
export * from "./hooks/useProps.mjs";
|
|
45
|
+
export * from "./hooks/useConfiguration.mjs";
|
|
46
|
+
export * from "./views/Slot.mjs";
|
|
47
|
+
export * from "./views/Stack.mjs";
|
|
48
|
+
export * from "./views/View.mjs";
|
|
49
|
+
export * from "./views/Text.mjs";
|
|
50
|
+
export * from "./views/Theme.mjs";
|
|
51
|
+
export * from "./views/ThemeProvider.mjs";
|
|
52
|
+
export * from "./views/FontLanguage.mjs";
|
|
53
|
+
export * from "./views/TamaguiProvider.mjs";
|
|
54
|
+
export * from "./views/Configuration.mjs";
|
|
55
|
+
export * from "@tamagui/use-did-finish-ssr";
|
|
56
|
+
export * from "@tamagui/use-event";
|
|
57
|
+
export * from "@tamagui/compose-refs";
|
|
58
|
+
export * from "@tamagui/helpers";
|
|
59
|
+
export * from "@tamagui/constants";
|
|
60
|
+
export * from "./setupHooks.mjs";
|
|
61
|
+
export { configureMedia, getConfig, getMedia, getThemes, getToken, getTokenValue, getTokens, mediaObjectToString, mediaQueryConfig, mediaState, setupDev, updateConfig, useMedia };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const stylesheets = {},
|
|
2
|
+
injectStyles = ({
|
|
3
|
+
filePath,
|
|
4
|
+
css
|
|
5
|
+
}) => {
|
|
6
|
+
let stylesheet = stylesheets[filePath];
|
|
7
|
+
if (!stylesheet) {
|
|
8
|
+
const styleEl = document.createElement("style");
|
|
9
|
+
styleEl.setAttribute("data-file", filePath), styleEl.setAttribute("type", "text/css"), stylesheet = stylesheets[filePath] = styleEl, document.head.appendChild(styleEl);
|
|
10
|
+
}
|
|
11
|
+
stylesheet.innerHTML = css;
|
|
12
|
+
};
|
|
13
|
+
export { injectStyles };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { setConfigFont } from "./config.mjs";
|
|
2
|
+
import { createFont } from "./createFont.mjs";
|
|
3
|
+
import { createVariables } from "./createVariables.mjs";
|
|
4
|
+
import { registerCSSVariable, variableToCSS } from "./helpers/registerCSSVariable.mjs";
|
|
5
|
+
function insertFont(name, fontIn) {
|
|
6
|
+
const font = createFont(fontIn),
|
|
7
|
+
tokened = createVariables(font, name),
|
|
8
|
+
parsed = parseFont(tokened);
|
|
9
|
+
if (typeof document < "u") {
|
|
10
|
+
const fontVars = registerFontVariables(parsed),
|
|
11
|
+
style = document.createElement("style");
|
|
12
|
+
style.innerText = `:root .font_${name} {${fontVars.join(";")}}`, style.setAttribute("data-tamagui-font", name), document.head.appendChild(style);
|
|
13
|
+
}
|
|
14
|
+
return setConfigFont(name, tokened, parsed), parsed;
|
|
15
|
+
}
|
|
16
|
+
const updateFont = insertFont;
|
|
17
|
+
function parseFont(definition) {
|
|
18
|
+
const parsed = {};
|
|
19
|
+
for (const attrKey in definition) {
|
|
20
|
+
const attr = definition[attrKey];
|
|
21
|
+
if (attrKey === "family" || attrKey === "face") parsed[attrKey] = attr;else {
|
|
22
|
+
parsed[attrKey] = {};
|
|
23
|
+
for (const key in attr) {
|
|
24
|
+
let val = attr[key];
|
|
25
|
+
val.val?.[0] === "$" && (val = val.val), parsed[attrKey][`$${key}`] = val;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
function registerFontVariables(parsedFont) {
|
|
32
|
+
const response = [];
|
|
33
|
+
for (const fkey in parsedFont) if (fkey !== "face") {
|
|
34
|
+
if (fkey === "family") {
|
|
35
|
+
const val = parsedFont[fkey];
|
|
36
|
+
registerCSSVariable(val), response.push(variableToCSS(val));
|
|
37
|
+
} else for (const fskey in parsedFont[fkey]) if (typeof parsedFont[fkey][fskey] != "string") {
|
|
38
|
+
const val = parsedFont[fkey][fskey];
|
|
39
|
+
registerCSSVariable(val), response.push(variableToCSS(val));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
export { insertFont, parseFont, registerFontVariables, updateFont };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useTheme } from "./hooks/useTheme.mjs";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
const internalWithTheme = (Component, styleProvider) => props => {
|
|
4
|
+
const {
|
|
5
|
+
expressions,
|
|
6
|
+
...rest
|
|
7
|
+
} = props,
|
|
8
|
+
theme = useTheme();
|
|
9
|
+
return /* @__PURE__ */jsx(Component, {
|
|
10
|
+
style: styleProvider(theme, expressions),
|
|
11
|
+
...rest
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export { internalWithTheme };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const ReactNativeStaticConfigs = /* @__PURE__ */new WeakMap();
|
|
2
|
+
function getReactNativeConfig(Component) {
|
|
3
|
+
if (Component) return Component.getSize && Component.prefetch ? RNConfigs.Image : Component.displayName === "Text" && Component.render ? RNConfigs.Text : Component.render && (Component.displayName === "ScrollView" || Component.displayName === "View") ? RNConfigs.default : Component.State?.blurTextInput ? RNConfigs.TextInput : ReactNativeStaticConfigs.get(Component);
|
|
4
|
+
}
|
|
5
|
+
const RNConfigs = {
|
|
6
|
+
Image: {
|
|
7
|
+
isReactNative: !0,
|
|
8
|
+
inlineProps: /* @__PURE__ */new Set(["src", "width", "height"])
|
|
9
|
+
},
|
|
10
|
+
Text: {
|
|
11
|
+
isReactNative: !0,
|
|
12
|
+
isText: !0
|
|
13
|
+
},
|
|
14
|
+
TextInput: {
|
|
15
|
+
isReactNative: !0,
|
|
16
|
+
isInput: !0,
|
|
17
|
+
isText: !0
|
|
18
|
+
},
|
|
19
|
+
default: {
|
|
20
|
+
isReactNative: !0
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function setupReactNative(rnExports) {}
|
|
24
|
+
export { getReactNativeConfig, setupReactNative };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createComponent } from "./createComponent.mjs";
|
|
2
|
+
import { mergeVariants } from "./helpers/mergeVariants.mjs";
|
|
3
|
+
import { getReactNativeConfig } from "./setupReactNative.mjs";
|
|
4
|
+
function styled(ComponentIn, options, staticExtractionOptions) {
|
|
5
|
+
if (process.env.NODE_ENV !== "production" && !ComponentIn) throw new Error("No component given to styled()");
|
|
6
|
+
const parentStaticConfig = ComponentIn.staticConfig,
|
|
7
|
+
isPlainStyledComponent = !!parentStaticConfig && !(parentStaticConfig.isReactNative || parentStaticConfig.isHOC);
|
|
8
|
+
let Component = parentStaticConfig?.isHOC && !parentStaticConfig?.isStyledHOC || isPlainStyledComponent ? ComponentIn : parentStaticConfig?.Component || ComponentIn;
|
|
9
|
+
const reactNativeConfig = parentStaticConfig ? void 0 : getReactNativeConfig(Component),
|
|
10
|
+
isReactNative = !!(reactNativeConfig || staticExtractionOptions?.isReactNative || parentStaticConfig?.isReactNative),
|
|
11
|
+
staticConfigProps = (() => {
|
|
12
|
+
if (options) {
|
|
13
|
+
let {
|
|
14
|
+
variants,
|
|
15
|
+
name,
|
|
16
|
+
defaultVariants,
|
|
17
|
+
acceptsClassName: acceptsClassNameProp,
|
|
18
|
+
context,
|
|
19
|
+
...defaultProps
|
|
20
|
+
} = options;
|
|
21
|
+
defaultVariants && (defaultProps = {
|
|
22
|
+
...defaultVariants,
|
|
23
|
+
...defaultProps
|
|
24
|
+
}), parentStaticConfig && (parentStaticConfig.isHOC && !parentStaticConfig.isStyledHOC || (defaultProps = {
|
|
25
|
+
...parentStaticConfig.defaultProps,
|
|
26
|
+
...defaultProps
|
|
27
|
+
}, parentStaticConfig.variants && (variants = mergeVariants(parentStaticConfig.variants, variants)))), parentStaticConfig?.isHOC && name && (defaultProps.componentName = name);
|
|
28
|
+
const isText = !!(staticExtractionOptions?.isText || parentStaticConfig?.isText),
|
|
29
|
+
acceptsClassName = acceptsClassNameProp ?? (isPlainStyledComponent || isReactNative || parentStaticConfig?.isHOC && parentStaticConfig?.acceptsClassName),
|
|
30
|
+
conf = {
|
|
31
|
+
...parentStaticConfig,
|
|
32
|
+
...staticExtractionOptions,
|
|
33
|
+
...(!isPlainStyledComponent && {
|
|
34
|
+
Component
|
|
35
|
+
}),
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
variants,
|
|
38
|
+
defaultProps,
|
|
39
|
+
defaultVariants,
|
|
40
|
+
componentName: name || parentStaticConfig?.componentName,
|
|
41
|
+
isReactNative,
|
|
42
|
+
isText,
|
|
43
|
+
acceptsClassName,
|
|
44
|
+
context,
|
|
45
|
+
...reactNativeConfig,
|
|
46
|
+
isStyledHOC: !!parentStaticConfig?.isHOC,
|
|
47
|
+
parentStaticConfig
|
|
48
|
+
};
|
|
49
|
+
return (defaultProps.children || !acceptsClassName || context) && (conf.neverFlatten = !0), conf;
|
|
50
|
+
}
|
|
51
|
+
})(),
|
|
52
|
+
component = createComponent(staticConfigProps || {});
|
|
53
|
+
for (const key in ComponentIn) key in component || (component[key] = ComponentIn[key]);
|
|
54
|
+
return component;
|
|
55
|
+
}
|
|
56
|
+
export { styled };
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ComponentContext } from "../contexts/ComponentContext.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
const Configuration = props => {
|
|
5
|
+
const current = useContext(ComponentContext);
|
|
6
|
+
return /* @__PURE__ */jsx(ComponentContext.Provider, {
|
|
7
|
+
...current,
|
|
8
|
+
...props
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Configuration.displayName = "Configuration";
|
|
12
|
+
export { Configuration };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
const FontLanguage = ({
|
|
3
|
+
children,
|
|
4
|
+
...props
|
|
5
|
+
}) => /* @__PURE__ */jsx("div", {
|
|
6
|
+
style: {
|
|
7
|
+
display: "contents"
|
|
8
|
+
},
|
|
9
|
+
className: Object.entries(props).map(([name, language]) => `t_lang-${name}-${language}`).join(" "),
|
|
10
|
+
children
|
|
11
|
+
});
|
|
12
|
+
FontLanguage.displayName = "FontLanguage";
|
|
13
|
+
export { FontLanguage };
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { composeRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb } from "@tamagui/constants";
|
|
3
|
+
import { composeEventHandlers } from "@tamagui/helpers";
|
|
4
|
+
import { Children, cloneElement, forwardRef, isValidElement } from "react";
|
|
5
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
|
+
const Slot = forwardRef(function (props, forwardedRef) {
|
|
7
|
+
const {
|
|
8
|
+
children,
|
|
9
|
+
...slotProps
|
|
10
|
+
} = props;
|
|
11
|
+
if (isValidElement(children)) {
|
|
12
|
+
const mergedProps = mergeSlotProps(children, slotProps);
|
|
13
|
+
return cloneElement(children, children.type.avoidForwardRef ? mergedProps : {
|
|
14
|
+
...mergedProps,
|
|
15
|
+
ref: composeRefs(forwardedRef, children.ref)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return Children.count(children) > 1 ? Children.only(null) : null;
|
|
19
|
+
});
|
|
20
|
+
Slot.displayName = "Slot";
|
|
21
|
+
const Slottable = ({
|
|
22
|
+
children
|
|
23
|
+
}) => /* @__PURE__ */jsx(Fragment, {
|
|
24
|
+
children
|
|
25
|
+
});
|
|
26
|
+
Slottable.displayName = "Slottable";
|
|
27
|
+
const pressMap = isWeb ? {
|
|
28
|
+
onPress: "onClick",
|
|
29
|
+
onPressOut: "onMouseUp",
|
|
30
|
+
onPressIn: "onMouseDown"
|
|
31
|
+
} : {};
|
|
32
|
+
function mergeSlotProps(child, slotProps) {
|
|
33
|
+
const childProps = child.props,
|
|
34
|
+
overrideProps = {
|
|
35
|
+
...childProps
|
|
36
|
+
},
|
|
37
|
+
isHTMLChild = typeof child.type == "string";
|
|
38
|
+
if (isHTMLChild) for (const key in pressMap) key in slotProps && (slotProps[pressMap[key]] = slotProps[key], delete slotProps[key]);
|
|
39
|
+
for (let propName in childProps) {
|
|
40
|
+
const slotPropValue = slotProps[propName],
|
|
41
|
+
childPropValue = childProps[propName];
|
|
42
|
+
isHTMLChild && propName in pressMap && (propName = pressMap[propName], delete overrideProps[propName]), handleRegex.test(propName) ? overrideProps[propName] = composeEventHandlers(childPropValue, slotPropValue) : propName === "style" ? overrideProps[propName] = {
|
|
43
|
+
...slotPropValue,
|
|
44
|
+
...childPropValue
|
|
45
|
+
} : propName === "className" && (overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" "));
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
...slotProps,
|
|
49
|
+
...overrideProps
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const handleRegex = /^on[A-Z]/;
|
|
53
|
+
export { Slot, Slottable };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { validStyles } from "@tamagui/helpers";
|
|
2
|
+
import { stackDefaultStyles } from "../constants/constants.mjs";
|
|
3
|
+
import { createComponent } from "../createComponent.mjs";
|
|
4
|
+
const Stack = createComponent({
|
|
5
|
+
acceptsClassName: !0,
|
|
6
|
+
defaultProps: stackDefaultStyles,
|
|
7
|
+
validStyles
|
|
8
|
+
});
|
|
9
|
+
Stack.displayName = "Stack";
|
|
10
|
+
export { Stack };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isClient } from "@tamagui/constants";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { ComponentContext } from "../contexts/ComponentContext.mjs";
|
|
4
|
+
import { setupMediaListeners } from "../hooks/useMedia.mjs";
|
|
5
|
+
import { ThemeProvider } from "./ThemeProvider.mjs";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function TamaguiProvider({
|
|
8
|
+
children,
|
|
9
|
+
disableInjectCSS,
|
|
10
|
+
config,
|
|
11
|
+
...themePropsProvider
|
|
12
|
+
}) {
|
|
13
|
+
return setupMediaListeners(), isClient && React.useLayoutEffect(() => {
|
|
14
|
+
if (config.disableSSR || document.documentElement.classList.contains("t_unmounted") && document.documentElement.classList.remove("t_unmounted"), !disableInjectCSS) {
|
|
15
|
+
const style = document.createElement("style");
|
|
16
|
+
return style.appendChild(document.createTextNode(config.getCSS())), document.head.appendChild(style), () => {
|
|
17
|
+
document.head.removeChild(style);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}, [config, disableInjectCSS]), /* @__PURE__ */jsx(ComponentContext.Provider, {
|
|
21
|
+
animationDriver: config.animations,
|
|
22
|
+
children: /* @__PURE__ */jsx(ThemeProvider, {
|
|
23
|
+
themeClassNameOnRoot: config.themeClassNameOnRoot,
|
|
24
|
+
disableRootThemeClass: config.disableRootThemeClass,
|
|
25
|
+
...themePropsProvider,
|
|
26
|
+
defaultTheme: themePropsProvider.defaultTheme ?? Object.keys(config.themes)[0],
|
|
27
|
+
children
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
TamaguiProvider.displayName = "TamaguiProvider";
|
|
32
|
+
export { TamaguiProvider };
|