@tamagui/web 1.123.17 → 1.124.0
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/dist/cjs/Tamagui.cjs +1 -6
- package/dist/cjs/Tamagui.js +1 -5
- package/dist/cjs/Tamagui.js.map +1 -1
- package/dist/cjs/Tamagui.native.js +2 -8
- package/dist/cjs/Tamagui.native.js.map +2 -2
- package/dist/cjs/createComponent.cjs +9 -13
- package/dist/cjs/createComponent.js +10 -8
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createComponent.native.js +17 -19
- package/dist/cjs/createComponent.native.js.map +2 -2
- package/dist/cjs/helpers/createShallowSetState.cjs +7 -4
- package/dist/cjs/helpers/createShallowSetState.js +12 -6
- package/dist/cjs/helpers/createShallowSetState.js.map +1 -1
- package/dist/cjs/helpers/createShallowSetState.native.js +10 -4
- package/dist/cjs/helpers/createShallowSetState.native.js.map +2 -2
- package/dist/cjs/hooks/{shouldDeoptDueToParentScheme.cjs → doesRootSchemeMatchSystem.cjs} +5 -5
- package/dist/cjs/hooks/{shouldDeoptDueToParentScheme.js → doesRootSchemeMatchSystem.js} +6 -6
- package/dist/cjs/hooks/doesRootSchemeMatchSystem.js.map +6 -0
- package/dist/cjs/hooks/doesRootSchemeMatchSystem.native.js +30 -0
- package/dist/cjs/hooks/doesRootSchemeMatchSystem.native.js.map +6 -0
- package/dist/cjs/hooks/getThemeProxied.cjs +58 -0
- package/dist/cjs/hooks/getThemeProxied.js +53 -0
- package/dist/cjs/hooks/getThemeProxied.js.map +6 -0
- package/dist/cjs/hooks/getThemeProxied.native.js +76 -0
- package/dist/cjs/hooks/getThemeProxied.native.js.map +6 -0
- package/dist/cjs/hooks/useComponentState.cjs +16 -16
- package/dist/cjs/hooks/useComponentState.js +22 -15
- package/dist/cjs/hooks/useComponentState.js.map +1 -1
- package/dist/cjs/hooks/useComponentState.native.js +15 -15
- package/dist/cjs/hooks/useComponentState.native.js.map +2 -2
- package/dist/cjs/hooks/useProps.cjs +2 -2
- package/dist/cjs/hooks/useProps.js +2 -2
- package/dist/cjs/hooks/useProps.js.map +1 -1
- package/dist/cjs/hooks/useProps.native.js +2 -2
- package/dist/cjs/hooks/useProps.native.js.map +2 -2
- package/dist/cjs/hooks/useTheme.cjs +10 -208
- package/dist/cjs/hooks/useTheme.js +7 -207
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/hooks/useTheme.native.js +8 -252
- package/dist/cjs/hooks/useTheme.native.js.map +2 -2
- package/dist/cjs/hooks/useThemeName.cjs +15 -27
- package/dist/cjs/hooks/useThemeName.js +6 -20
- package/dist/cjs/hooks/useThemeName.js.map +2 -2
- package/dist/cjs/hooks/useThemeName.native.js +16 -22
- package/dist/cjs/hooks/useThemeName.native.js.map +2 -2
- package/dist/cjs/hooks/useThemeState.cjs +187 -0
- package/dist/cjs/hooks/useThemeState.js +159 -0
- package/dist/cjs/hooks/useThemeState.js.map +6 -0
- package/dist/cjs/hooks/useThemeState.native.js +206 -0
- package/dist/cjs/hooks/useThemeState.native.js.map +6 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +3 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.native.js.map +1 -1
- package/dist/cjs/views/Theme.cjs +81 -85
- package/dist/cjs/views/Theme.js +44 -51
- package/dist/cjs/views/Theme.js.map +2 -2
- package/dist/cjs/views/Theme.native.js +58 -58
- package/dist/cjs/views/Theme.native.js.map +2 -2
- package/dist/cjs/views/ThemeDebug.cjs +21 -43
- package/dist/cjs/views/ThemeDebug.js +18 -38
- package/dist/cjs/views/ThemeDebug.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.cjs +1 -1
- package/dist/cjs/views/ThemeProvider.js +1 -1
- package/dist/cjs/views/ThemeProvider.js.map +1 -1
- package/dist/cjs/views/ThemeProvider.native.js +1 -1
- package/dist/cjs/views/ThemeProvider.native.js.map +2 -2
- package/dist/esm/Tamagui.js +0 -5
- package/dist/esm/Tamagui.js.map +1 -1
- package/dist/esm/Tamagui.mjs +0 -5
- package/dist/esm/Tamagui.mjs.map +1 -1
- package/dist/esm/Tamagui.native.js +1 -8
- package/dist/esm/Tamagui.native.js.map +2 -2
- package/dist/esm/createComponent.js +9 -8
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createComponent.mjs +9 -13
- package/dist/esm/createComponent.mjs.map +1 -1
- package/dist/esm/createComponent.native.js +16 -19
- package/dist/esm/createComponent.native.js.map +2 -2
- package/dist/esm/helpers/createShallowSetState.js +13 -7
- package/dist/esm/helpers/createShallowSetState.js.map +1 -1
- package/dist/esm/helpers/createShallowSetState.mjs +8 -5
- package/dist/esm/helpers/createShallowSetState.mjs.map +1 -1
- package/dist/esm/helpers/createShallowSetState.native.js +11 -5
- package/dist/esm/helpers/createShallowSetState.native.js.map +2 -2
- package/dist/esm/hooks/doesRootSchemeMatchSystem.js +7 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.js.map +6 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.mjs +5 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.mjs.map +1 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.native.js +10 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.native.js.map +6 -0
- package/dist/esm/hooks/getThemeProxied.js +40 -0
- package/dist/esm/hooks/getThemeProxied.js.map +6 -0
- package/dist/esm/hooks/getThemeProxied.mjs +35 -0
- package/dist/esm/hooks/getThemeProxied.mjs.map +1 -0
- package/dist/esm/hooks/getThemeProxied.native.js +59 -0
- package/dist/esm/hooks/getThemeProxied.native.js.map +6 -0
- package/dist/esm/hooks/useComponentState.js +22 -15
- package/dist/esm/hooks/useComponentState.js.map +1 -1
- package/dist/esm/hooks/useComponentState.mjs +16 -16
- package/dist/esm/hooks/useComponentState.mjs.map +1 -1
- package/dist/esm/hooks/useComponentState.native.js +15 -15
- package/dist/esm/hooks/useComponentState.native.js.map +2 -2
- package/dist/esm/hooks/useProps.js +2 -2
- package/dist/esm/hooks/useProps.js.map +1 -1
- package/dist/esm/hooks/useProps.mjs +2 -2
- package/dist/esm/hooks/useProps.mjs.map +1 -1
- package/dist/esm/hooks/useProps.native.js +2 -2
- package/dist/esm/hooks/useProps.native.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +9 -220
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/hooks/useTheme.mjs +10 -205
- package/dist/esm/hooks/useTheme.mjs.map +1 -1
- package/dist/esm/hooks/useTheme.native.js +11 -257
- package/dist/esm/hooks/useTheme.native.js.map +2 -2
- package/dist/esm/hooks/useThemeName.js +4 -12
- package/dist/esm/hooks/useThemeName.js.map +2 -2
- package/dist/esm/hooks/useThemeName.mjs +11 -12
- package/dist/esm/hooks/useThemeName.mjs.map +1 -1
- package/dist/esm/hooks/useThemeName.native.js +15 -14
- package/dist/esm/hooks/useThemeName.native.js.map +2 -2
- package/dist/esm/hooks/useThemeState.js +151 -0
- package/dist/esm/hooks/useThemeState.js.map +6 -0
- package/dist/esm/hooks/useThemeState.mjs +159 -0
- package/dist/esm/hooks/useThemeState.mjs.map +1 -0
- package/dist/esm/hooks/useThemeState.native.js +182 -0
- package/dist/esm/hooks/useThemeState.native.js.map +6 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js.map +1 -1
- package/dist/esm/views/TamaguiProvider.mjs.map +1 -1
- package/dist/esm/views/TamaguiProvider.native.js.map +1 -1
- package/dist/esm/views/Theme.js +57 -54
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/Theme.mjs +81 -85
- package/dist/esm/views/Theme.mjs.map +1 -1
- package/dist/esm/views/Theme.native.js +61 -61
- package/dist/esm/views/Theme.native.js.map +2 -2
- package/dist/esm/views/ThemeDebug.js +16 -29
- package/dist/esm/views/ThemeDebug.js.map +1 -1
- package/dist/esm/views/ThemeDebug.mjs +16 -27
- package/dist/esm/views/ThemeDebug.mjs.map +1 -1
- package/dist/esm/views/ThemeProvider.js +2 -2
- package/dist/esm/views/ThemeProvider.js.map +1 -1
- package/dist/esm/views/ThemeProvider.mjs +2 -2
- package/dist/esm/views/ThemeProvider.mjs.map +1 -1
- package/dist/esm/views/ThemeProvider.native.js +2 -2
- package/dist/esm/views/ThemeProvider.native.js.map +2 -2
- package/package.json +11 -11
- package/src/Tamagui.ts +0 -6
- package/src/createComponent.tsx +19 -28
- package/src/helpers/createShallowSetState.tsx +17 -8
- package/src/hooks/doesRootSchemeMatchSystem.native.ts +7 -0
- package/src/hooks/doesRootSchemeMatchSystem.ts +4 -0
- package/src/hooks/getThemeProxied.ts +165 -0
- package/src/hooks/useComponentState.ts +26 -21
- package/src/hooks/useProps.tsx +2 -2
- package/src/hooks/useTheme.tsx +22 -633
- package/src/hooks/useThemeName.tsx +6 -18
- package/src/hooks/useThemeState.ts +341 -0
- package/src/index.ts +1 -0
- package/src/types.tsx +2 -2
- package/src/views/TamaguiProvider.tsx +1 -1
- package/src/views/Theme.tsx +129 -132
- package/src/views/ThemeDebug.native.tsx +2 -2
- package/src/views/ThemeDebug.tsx +17 -39
- package/src/views/ThemeProvider.tsx +2 -2
- package/types/Tamagui.d.ts +0 -2
- package/types/Tamagui.d.ts.map +1 -1
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/createShallowSetState.d.ts +1 -1
- package/types/helpers/createShallowSetState.d.ts.map +1 -1
- package/types/hooks/doesRootSchemeMatchSystem.d.ts +2 -0
- package/types/hooks/doesRootSchemeMatchSystem.d.ts.map +1 -0
- package/types/hooks/doesRootSchemeMatchSystem.native.d.ts +2 -0
- package/types/hooks/doesRootSchemeMatchSystem.native.d.ts.map +1 -0
- package/types/hooks/getThemeProxied.d.ts +25 -0
- package/types/hooks/getThemeProxied.d.ts.map +1 -0
- package/types/hooks/useComponentState.d.ts.map +1 -1
- package/types/hooks/useConfiguration.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +9 -36
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/hooks/useThemeName.d.ts +1 -3
- package/types/hooks/useThemeName.d.ts.map +1 -1
- package/types/hooks/useThemeState.d.ts +22 -0
- package/types/hooks/useThemeState.d.ts.map +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +2 -2
- package/types/types.d.ts.map +1 -1
- package/types/views/Theme.d.ts +3 -3
- package/types/views/Theme.d.ts.map +1 -1
- package/types/views/ThemeDebug.d.ts +2 -2
- package/types/views/ThemeDebug.d.ts.map +1 -1
- package/types/views/ThemeDebug.native.d.ts +2 -2
- package/types/views/ThemeDebug.native.d.ts.map +1 -1
- package/dist/cjs/helpers/ThemeManager.cjs +0 -202
- package/dist/cjs/helpers/ThemeManager.js +0 -183
- package/dist/cjs/helpers/ThemeManager.js.map +0 -6
- package/dist/cjs/helpers/ThemeManager.native.js +0 -282
- package/dist/cjs/helpers/ThemeManager.native.js.map +0 -6
- package/dist/cjs/helpers/ThemeManagerContext.cjs +0 -38
- package/dist/cjs/helpers/ThemeManagerContext.js +0 -30
- package/dist/cjs/helpers/ThemeManagerContext.js.map +0 -6
- package/dist/cjs/helpers/ThemeManagerContext.native.js +0 -34
- package/dist/cjs/helpers/ThemeManagerContext.native.js.map +0 -6
- package/dist/cjs/hooks/shouldDeoptDueToParentScheme.js.map +0 -6
- package/dist/cjs/hooks/shouldDeoptDueToParentScheme.native.js +0 -50
- package/dist/cjs/hooks/shouldDeoptDueToParentScheme.native.js.map +0 -6
- package/dist/esm/helpers/ThemeManager.js +0 -169
- package/dist/esm/helpers/ThemeManager.js.map +0 -6
- package/dist/esm/helpers/ThemeManager.mjs +0 -177
- package/dist/esm/helpers/ThemeManager.mjs.map +0 -1
- package/dist/esm/helpers/ThemeManager.native.js +0 -261
- package/dist/esm/helpers/ThemeManager.native.js.map +0 -6
- package/dist/esm/helpers/ThemeManagerContext.js +0 -6
- package/dist/esm/helpers/ThemeManagerContext.js.map +0 -6
- package/dist/esm/helpers/ThemeManagerContext.mjs +0 -4
- package/dist/esm/helpers/ThemeManagerContext.mjs.map +0 -1
- package/dist/esm/helpers/ThemeManagerContext.native.js +0 -6
- package/dist/esm/helpers/ThemeManagerContext.native.js.map +0 -6
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.js +0 -7
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.js.map +0 -6
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.mjs +0 -5
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.mjs.map +0 -1
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.native.js +0 -29
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.native.js.map +0 -6
- package/src/helpers/ThemeManager.tsx +0 -405
- package/src/helpers/ThemeManagerContext.tsx +0 -4
- package/src/hooks/shouldDeoptDueToParentScheme.native.tsx +0 -37
- package/src/hooks/shouldDeoptDueToParentScheme.tsx +0 -6
- package/types/helpers/ThemeManager.d.ts +0 -45
- package/types/helpers/ThemeManager.d.ts.map +0 -1
- package/types/helpers/ThemeManagerContext.d.ts +0 -4
- package/types/helpers/ThemeManagerContext.d.ts.map +0 -1
- package/types/hooks/shouldDeoptDueToParentScheme.d.ts +0 -3
- package/types/hooks/shouldDeoptDueToParentScheme.d.ts.map +0 -1
- package/types/hooks/shouldDeoptDueToParentScheme.native.d.ts +0 -3
- package/types/hooks/shouldDeoptDueToParentScheme.native.d.ts.map +0 -1
|
@@ -1,211 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { ThemeManagerContext } from "../helpers/ThemeManagerContext.mjs";
|
|
7
|
-
import { isEqualShallow } from "../helpers/createShallowSetState.mjs";
|
|
8
|
-
import "./shouldDeoptDueToParentScheme.mjs";
|
|
9
|
-
const emptyProps = {
|
|
10
|
-
name: null
|
|
11
|
-
},
|
|
12
|
-
useTheme = (props = emptyProps) => {
|
|
13
|
-
const [_, theme] = useThemeWithState(props);
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { getThemeProxied } from "./getThemeProxied.mjs";
|
|
3
|
+
import { useThemeState } from "./useThemeState.mjs";
|
|
4
|
+
const useTheme = (props = {}) => {
|
|
5
|
+
const [theme] = useThemeWithState(props);
|
|
14
6
|
return theme;
|
|
15
7
|
},
|
|
16
|
-
useThemeWithState = props => {
|
|
8
|
+
useThemeWithState = (props, isRoot = !1) => {
|
|
17
9
|
const keys = useRef(null),
|
|
18
|
-
|
|
19
|
-
process.env.NODE_ENV === "development" &&
|
|
20
|
-
const {
|
|
21
|
-
themeManager,
|
|
22
|
-
state
|
|
23
|
-
} = changedThemeState;
|
|
24
|
-
process.env.NODE_ENV === "development" && (state?.theme || process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1" && console.error(`[tamagui] No theme found, this could be due to an invalid theme name (given theme props ${JSON.stringify(props)}).
|
|
10
|
+
themeState = useThemeState(props, isRoot, keys);
|
|
11
|
+
return process.env.NODE_ENV === "development" && (themeState?.theme || process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1" && console.error(`[tamagui] No theme found, this could be due to an invalid theme name (given theme props ${JSON.stringify(props)}).
|
|
25
12
|
|
|
26
|
-
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`));
|
|
27
|
-
const themeProxied = getThemeProxied(props, state, keys, themeManager);
|
|
28
|
-
return process.env.NODE_ENV === "development" && props.debug === "verbose" && (console.groupCollapsed(` \u{1F539} [${themeManager?.id}] useTheme =>`, state?.name), console.info("returning state", changedThemeState.state, changedThemeState.isNewTheme, "from props", props), console.groupEnd()), [changedThemeState, themeProxied];
|
|
29
|
-
},
|
|
30
|
-
emptyObject = {},
|
|
31
|
-
ProxiedThemes = /* @__PURE__ */new Map();
|
|
32
|
-
let curKeys, curProps, curThemeManger;
|
|
33
|
-
function getThemeProxied(_props, state, _keys, _themeManager) {
|
|
34
|
-
const theme = state?.theme;
|
|
35
|
-
if (!theme || !_themeManager) return emptyObject;
|
|
36
|
-
if (curKeys = _keys, curProps = _props, curThemeManger = _themeManager, ProxiedThemes.has(theme)) return ProxiedThemes.get(theme);
|
|
37
|
-
const {
|
|
38
|
-
name,
|
|
39
|
-
scheme
|
|
40
|
-
} = state,
|
|
41
|
-
config = getConfig();
|
|
42
|
-
function track(key) {
|
|
43
|
-
curKeys && (curKeys.current || (curKeys.current = []), curKeys.current.push(key), process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
|
|
44
|
-
}
|
|
45
|
-
const proxied = Object.fromEntries(Object.entries(theme).flatMap(([key, value]) => {
|
|
46
|
-
const proxied2 = {
|
|
47
|
-
...value,
|
|
48
|
-
get val() {
|
|
49
|
-
return globalThis.tamaguiAvoidTracking || track(key), value.val;
|
|
50
|
-
},
|
|
51
|
-
get(platform) {
|
|
52
|
-
return getVariable(value);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
return [[key, proxied2], [`$${key}`, proxied2]];
|
|
56
|
-
}));
|
|
57
|
-
return ProxiedThemes.set(theme, proxied), proxied;
|
|
58
|
-
}
|
|
59
|
-
const activeThemeManagers = /* @__PURE__ */new Set(),
|
|
60
|
-
_uidToManager = /* @__PURE__ */new WeakMap(),
|
|
61
|
-
_idToUID = {},
|
|
62
|
-
getId = id => _idToUID[id],
|
|
63
|
-
getThemeManager = id => _uidToManager.get(getId(id)),
|
|
64
|
-
registerThemeManager = t => {
|
|
65
|
-
if (!_idToUID[t.id]) {
|
|
66
|
-
const id = _idToUID[t.id] = {};
|
|
67
|
-
_uidToManager.set(id, t);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
ogLog = console.error,
|
|
71
|
-
preventWarnSetState = process.env.NODE_ENV === "production" ? ogLog :
|
|
72
|
-
// temporary fix for logs, they are harmless in that i've tried to rewrite this
|
|
73
|
-
// a few times using the "right" ways, but they are always slower. maybe skill issue
|
|
74
|
-
(a, ...args) => {
|
|
75
|
-
if (!(typeof a == "string" && a.includes("Cannot update a component"))) return ogLog(a, ...args);
|
|
76
|
-
};
|
|
77
|
-
function getShouldUpdateTheme(props, parentManager, keys, themeState, nextState, forceShouldChange = !1) {
|
|
78
|
-
if (isServer || !forceShouldChange && !keys?.current && (!themeState || !themeState.isNewTheme) && !getHasThemeUpdatingProps(props)) return;
|
|
79
|
-
const next = nextState || themeState?.themeManager?.getState(props, parentManager);
|
|
80
|
-
if (forceShouldChange) return next;
|
|
81
|
-
if (!(!next || next.theme === themeState?.state?.theme)) return next;
|
|
82
|
-
}
|
|
83
|
-
const useChangeThemeEffect = (props, isRoot = !1, keys) => {
|
|
84
|
-
const {
|
|
85
|
-
disable
|
|
86
|
-
} = props,
|
|
87
|
-
parentManager = useContext(ThemeManagerContext),
|
|
88
|
-
shouldAlwaysUpdate = props.needsUpdate?.() === !0 ? !0 : void 0;
|
|
89
|
-
if (!isRoot && !parentManager || disable) return {
|
|
90
|
-
isNewTheme: !1,
|
|
91
|
-
state: parentManager?.state,
|
|
92
|
-
themeManager: parentManager
|
|
93
|
-
};
|
|
94
|
-
const [themeState, setThemeState] = useState(createState),
|
|
95
|
-
{
|
|
96
|
-
state,
|
|
97
|
-
mounted,
|
|
98
|
-
isNewTheme,
|
|
99
|
-
themeManager,
|
|
100
|
-
prevState
|
|
101
|
-
} = themeState,
|
|
102
|
-
isInversingOnMount = !!(!themeState.mounted && props.inverse);
|
|
103
|
-
if (isServer || (useLayoutEffect(() => {
|
|
104
|
-
themeManager && state && prevState && state !== prevState && themeManager.notify();
|
|
105
|
-
}, [state]), useEffect(() => {
|
|
106
|
-
if (!themeManager) return;
|
|
107
|
-
if (props.inverse && !mounted) {
|
|
108
|
-
setThemeState(prev => createState({
|
|
109
|
-
...prev,
|
|
110
|
-
mounted: !0
|
|
111
|
-
}));
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
(isNewTheme || isRoot) && (activeThemeManagers.add(themeManager), process.env.NODE_ENV === "development" && isRoot && (globalThis.TamaguiRootThemeManager ||= themeManager));
|
|
115
|
-
const updated = getShouldUpdateTheme(props, parentManager, keys, themeState, void 0, shouldAlwaysUpdate);
|
|
116
|
-
updated && setThemeState(prev => createState(prev, void 0, updated));
|
|
117
|
-
const selfListenerDispose = themeManager.onChangeTheme((_a, _b, forced) => {
|
|
118
|
-
forced && setThemeState(prev => createState(prev, forced !== "self"));
|
|
119
|
-
}, !0),
|
|
120
|
-
disposeChangeListener = parentManager?.onChangeTheme((name, manager, forced) => {
|
|
121
|
-
const force = forced || (isServer ? void 0 : keys?.current ? !0 : void 0) || props.deopt || void 0,
|
|
122
|
-
shouldTryUpdate = force ?? !!(keys?.current || isNewTheme);
|
|
123
|
-
process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F538} onChange", {
|
|
124
|
-
id: themeManager.id,
|
|
125
|
-
force,
|
|
126
|
-
shouldTryUpdate,
|
|
127
|
-
props,
|
|
128
|
-
name,
|
|
129
|
-
keys
|
|
130
|
-
}), shouldTryUpdate && setThemeState(prev => createState(prev, !0));
|
|
131
|
-
}, themeManager.id);
|
|
132
|
-
return () => {
|
|
133
|
-
selfListenerDispose(), disposeChangeListener?.(), isNewTheme && activeThemeManagers.delete(themeManager);
|
|
134
|
-
};
|
|
135
|
-
}, [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), () => {
|
|
136
|
-
globalThis.TamaguiThemeManagers.delete(themeManager);
|
|
137
|
-
}), [themeManager])), isWeb && isInversingOnMount) return {
|
|
138
|
-
isNewTheme: !1,
|
|
139
|
-
inversed: !1,
|
|
140
|
-
themeManager: parentManager,
|
|
141
|
-
state: {
|
|
142
|
-
name: "",
|
|
143
|
-
...parentManager?.state,
|
|
144
|
-
className: ""
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
return {
|
|
148
|
-
state,
|
|
149
|
-
isNewTheme,
|
|
150
|
-
inversed: !!props.inverse,
|
|
151
|
-
themeManager
|
|
13
|
+
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`)), [getThemeProxied(props, themeState, keys), themeState];
|
|
152
14
|
};
|
|
153
|
-
|
|
154
|
-
if (prev && !foundNextState && !keys?.current && !force) return prev;
|
|
155
|
-
let themeManager2 = parentManager,
|
|
156
|
-
state2;
|
|
157
|
-
if (getHasThemeUpdatingProps(props)) {
|
|
158
|
-
const parentManagerProp = isRoot ? "root" : parentManager;
|
|
159
|
-
if (prev?.themeManager) {
|
|
160
|
-
themeManager2 = prev.themeManager;
|
|
161
|
-
const forceChange = force || shouldAlwaysUpdate || (keys?.current ? !0 : void 0);
|
|
162
|
-
let nextState = null;
|
|
163
|
-
if (foundNextState) nextState = foundNextState;else {
|
|
164
|
-
const next = themeManager2.getState(props, parentManager);
|
|
165
|
-
nextState = getShouldUpdateTheme(props, parentManager, keys, prev, next, forceChange);
|
|
166
|
-
}
|
|
167
|
-
nextState ? (state2 = nextState, !prev.isNewTheme && !isRoot ? themeManager2 = new ThemeManager(props, parentManagerProp) : themeManager2.updateState(nextState)) : prev.isNewTheme && parentManager && !nextState && (themeManager2 = parentManager);
|
|
168
|
-
} else themeManager2 = new ThemeManager(props, parentManagerProp), state2 = {
|
|
169
|
-
...themeManager2.state
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
const isNewTheme2 = !!(themeManager2 !== parentManager || props.inverse);
|
|
173
|
-
isNewTheme2 && registerThemeManager(themeManager2);
|
|
174
|
-
const mounted2 = (isWeb ? !getSetting("disableSSR") : !1) ? isRoot || prev?.mounted : !0;
|
|
175
|
-
state2 || (isNewTheme2 ? state2 = themeManager2.state : (state2 = parentManager.state, themeManager2 = parentManager));
|
|
176
|
-
const response = {
|
|
177
|
-
themeManager: themeManager2,
|
|
178
|
-
isNewTheme: isNewTheme2,
|
|
179
|
-
mounted: mounted2
|
|
180
|
-
};
|
|
181
|
-
props.inverse && (response.inversed = !0);
|
|
182
|
-
const shouldReturnPrev = prev && !force &&
|
|
183
|
-
// isEqualShallow uses the second arg as the keys so this should compare without state first...
|
|
184
|
-
isEqualShallow(prev, response) &&
|
|
185
|
-
// ... and then compare just the state, because we make a new state obj but is likely the same
|
|
186
|
-
isEqualShallow(prev.state, state2);
|
|
187
|
-
if (prev && shouldReturnPrev) return prev;
|
|
188
|
-
if (response.state = state2, response.prevState = prev?.state, process.env.NODE_ENV === "development" && props.debug && isClient) {
|
|
189
|
-
console.groupCollapsed(`\u{1F537} [${themeManager2.id}] useChangeThemeEffect createState`);
|
|
190
|
-
const parentState = {
|
|
191
|
-
...parentManager?.state
|
|
192
|
-
},
|
|
193
|
-
parentId = parentManager?.id,
|
|
194
|
-
themeManagerState = {
|
|
195
|
-
...themeManager2.state
|
|
196
|
-
};
|
|
197
|
-
console.info({
|
|
198
|
-
props,
|
|
199
|
-
parentState,
|
|
200
|
-
parentId,
|
|
201
|
-
themeManager: themeManager2,
|
|
202
|
-
prev,
|
|
203
|
-
response,
|
|
204
|
-
themeManagerState
|
|
205
|
-
}), console.groupEnd();
|
|
206
|
-
}
|
|
207
|
-
return response;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
export { activeThemeManagers, getThemeManager, useChangeThemeEffect, useTheme, useThemeWithState };
|
|
15
|
+
export { useTheme, useThemeWithState };
|
|
211
16
|
//# sourceMappingURL=useTheme.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isClient","isServer","isWeb","useContext","useEffect","useLayoutEffect","useRef","useState","getConfig","getSetting","getVariable","ThemeManager","getHasThemeUpdatingProps","ThemeManagerContext","isEqualShallow","emptyProps","name","useTheme","props","_","theme","useThemeWithState","keys","changedThemeState","useChangeThemeEffect","process","env","NODE_ENV","globalThis","time","themeManager","state","TAMAGUI_DISABLE_NO_THEME_WARNING","console","error","JSON","stringify","themeProxied","getThemeProxied","debug","groupCollapsed","id","info","isNewTheme","groupEnd","emptyObject","ProxiedThemes","Map","curKeys","curProps","curThemeManger","_props","_keys","_themeManager","has","get","scheme","config","track","key","current","push","proxied","Object","fromEntries","entries","flatMap","value","proxied2","val","tamaguiAvoidTracking","platform","set","activeThemeManagers","Set","_uidToManager","WeakMap","_idToUID","getId","getThemeManager","registerThemeManager","t","ogLog","preventWarnSetState","a","args","includes","getShouldUpdateTheme","parentManager","themeState","nextState","forceShouldChange","next","getState","isRoot","disable","shouldAlwaysUpdate","needsUpdate","setThemeState","createState","mounted","prevState","isInversingOnMount","inverse","notify","prev","add","TamaguiRootThemeManager","updated","selfListenerDispose","onChangeTheme","_a","_b","forced","disposeChangeListener","manager","force","deopt","shouldTryUpdate","delete","componentName","reset","TamaguiThemeManagers","inversed","className","foundNextState","themeManager2","state2","parentManagerProp","forceChange","updateState","isNewTheme2","mounted2","response","shouldReturnPrev","parentState","parentId","themeManagerState"],"sources":["../../../src/hooks/useTheme.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,EAAiBC,QAAA,EAAUC,KAAA,QAAa;AACjD,SACEC,UAAA,EACAC,SAAA,EACAC,eAAA,EACAC,MAAA,EACAC,QAAA,QAEK;AACP,SAASC,SAAA,EAAWC,UAAA,QAAkB;AAEtC,SAASC,WAAA,QAAmB;AAE5B,SAASC,YAAA,EAAcC,wBAAA,QAAgC;AACvD,SAASC,mBAAA,QAA2B;AACpC,SAASC,cAAA,QAAsB;AAS/B,OAA6C;AAa7C,MAA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useThemeWithState","isRoot","keys","themeState","process","env","NODE_ENV","TAMAGUI_DISABLE_NO_THEME_WARNING","console","error","JSON","stringify"],"sources":["../../../src/hooks/useTheme.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAEvB,SAASC,eAAA,QAA0C;AAEnD,SAASC,aAAA,QAAqB;AAEvB,MAAMC,QAAA,GAAWA,CAACC,KAAA,GAAoB,CAAC,MAAM;IAClD,MAAM,CAACC,KAAK,IAAIC,iBAAA,CAAkBF,KAAK;IAEvC,OADYC,KAAA;EAEd;EAOaC,iBAAA,GAAoBA,CAC/BF,KAAA,EACAG,MAAA,GAAS,OACU;IACnB,MAAMC,IAAA,GAAOR,MAAA,CAA2B,IAAI;MACtCS,UAAA,GAAaP,aAAA,CAAcE,KAAA,EAAOG,MAAA,EAAQC,IAAI;IAEpD,OAAIE,OAAA,CAAQC,GAAA,CAAIC,QAAA,KAAa,kBACtBH,UAAA,EAAYJ,KAAA,IACXK,OAAA,CAAQC,GAAA,CAAIE,gCAAA,KAAqC,OACnDC,OAAA,CAAQC,KAAA,CACN,2FAA2FC,IAAA,CAAKC,SAAA,CAC9Fb,KACF,CAAC;AAAA;AAAA,sKACH,IAOC,CAFcH,eAAA,CAAgBG,KAAA,EAAOK,UAAA,EAAYD,IAAI,GAEtCC,UAAU;EAClC","ignoreList":[]}
|
|
@@ -1,267 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
7
|
-
import { isEqualShallow } from "../helpers/createShallowSetState";
|
|
8
|
-
import { shouldDeoptDueToParentScheme } from "./shouldDeoptDueToParentScheme";
|
|
9
|
-
var emptyProps = {
|
|
10
|
-
name: null
|
|
11
|
-
}, useTheme = function() {
|
|
12
|
-
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : emptyProps, [_, theme] = useThemeWithState(props), res = theme;
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { getThemeProxied } from "./getThemeProxied";
|
|
3
|
+
import { useThemeState } from "./useThemeState";
|
|
4
|
+
var useTheme = function() {
|
|
5
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, [theme] = useThemeWithState(props), res = theme;
|
|
13
6
|
return res;
|
|
14
7
|
}, useThemeWithState = function(props) {
|
|
15
|
-
var keys = useRef(null),
|
|
16
|
-
process.env.NODE_ENV === "development" &&
|
|
17
|
-
var { themeManager, state } = changedThemeState;
|
|
18
|
-
process.env.NODE_ENV === "development" && (state?.theme || process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1" && console.error(`[tamagui] No theme found, this could be due to an invalid theme name (given theme props ${JSON.stringify(props)}).
|
|
8
|
+
var isRoot = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1, keys = useRef(null), themeState = useThemeState(props, isRoot, keys);
|
|
9
|
+
process.env.NODE_ENV === "development" && (themeState?.theme || process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1" && console.error(`[tamagui] No theme found, this could be due to an invalid theme name (given theme props ${JSON.stringify(props)}).
|
|
19
10
|
|
|
20
11
|
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`));
|
|
21
|
-
var themeProxied = getThemeProxied(props,
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
var themeProxied = getThemeProxied(props, themeState, keys);
|
|
13
|
+
return [
|
|
14
|
+
themeProxied,
|
|
15
|
+
themeState
|
|
25
16
|
];
|
|
26
|
-
}, emptyObject = {}, ProxiedThemes = /* @__PURE__ */ new Map(), curKeys, curProps, curThemeManger;
|
|
27
|
-
function getThemeProxied(_props, state, _keys, _themeManager) {
|
|
28
|
-
var theme = state?.theme;
|
|
29
|
-
if (!theme || !_themeManager)
|
|
30
|
-
return emptyObject;
|
|
31
|
-
if (curKeys = _keys, curProps = _props, curThemeManger = _themeManager, ProxiedThemes.has(theme)) {
|
|
32
|
-
var proxied = ProxiedThemes.get(theme);
|
|
33
|
-
return proxied;
|
|
34
|
-
}
|
|
35
|
-
var { name, scheme } = state, config = getConfig();
|
|
36
|
-
function track(key) {
|
|
37
|
-
curKeys && (curKeys.current || (curKeys.current = []), curKeys.current.push(key), process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
|
|
38
|
-
}
|
|
39
|
-
var proxied1 = Object.fromEntries(Object.entries(theme).flatMap(function(param) {
|
|
40
|
-
var [key, value] = param, proxied2 = {
|
|
41
|
-
...value,
|
|
42
|
-
get val() {
|
|
43
|
-
return globalThis.tamaguiAvoidTracking || track(key), value.val;
|
|
44
|
-
},
|
|
45
|
-
get(platform) {
|
|
46
|
-
var outVal = getVariable(value);
|
|
47
|
-
if (platform !== "web" && isIos && !curProps.deopt && getSetting("fastSchemeChange") && !shouldDeoptDueToParentScheme(curThemeManger) && scheme) {
|
|
48
|
-
var _config_themes_name, _config_themes_oppositeName, oppositeScheme = scheme === "dark" ? "light" : "dark", oppositeName = name.replace(scheme, oppositeScheme), color = getVariable((_config_themes_name = config.themes[name]) === null || _config_themes_name === void 0 ? void 0 : _config_themes_name[key]), oppositeColor = getVariable((_config_themes_oppositeName = config.themes[oppositeName]) === null || _config_themes_oppositeName === void 0 ? void 0 : _config_themes_oppositeName[key]), dynamicVal = {
|
|
49
|
-
dynamic: {
|
|
50
|
-
[scheme]: color,
|
|
51
|
-
[oppositeScheme]: oppositeColor
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
return dynamicVal;
|
|
55
|
-
}
|
|
56
|
-
return process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key because of:
|
|
57
|
-
not web: ${platform !== "web"}
|
|
58
|
-
isIOS: ${isIos}
|
|
59
|
-
deopt: ${curProps.deopt}
|
|
60
|
-
fastScheme: ${getSetting("fastSchemeChange")}
|
|
61
|
-
inversed: ${getIsInversed(curThemeManger)}
|
|
62
|
-
`), track(key), outVal;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
return [
|
|
66
|
-
[
|
|
67
|
-
key,
|
|
68
|
-
proxied2
|
|
69
|
-
],
|
|
70
|
-
[
|
|
71
|
-
`$${key}`,
|
|
72
|
-
proxied2
|
|
73
|
-
]
|
|
74
|
-
];
|
|
75
|
-
}));
|
|
76
|
-
return ProxiedThemes.set(theme, proxied1), proxied1;
|
|
77
|
-
}
|
|
78
|
-
function getIsInversed(manager) {
|
|
79
|
-
for (var isInversed = !1, cur = manager; cur; ) {
|
|
80
|
-
if (!cur.parentManager) return isInversed;
|
|
81
|
-
cur.parentManager.state.scheme !== cur.state.scheme && (isInversed = !isInversed), cur = cur.parentManager;
|
|
82
|
-
}
|
|
83
|
-
return !1;
|
|
84
|
-
}
|
|
85
|
-
var activeThemeManagers = /* @__PURE__ */ new Set(), _uidToManager = /* @__PURE__ */ new WeakMap(), _idToUID = {}, getId = function(id) {
|
|
86
|
-
return _idToUID[id];
|
|
87
|
-
}, getThemeManager = function(id) {
|
|
88
|
-
return _uidToManager.get(getId(id));
|
|
89
|
-
}, registerThemeManager = function(t) {
|
|
90
|
-
if (!_idToUID[t.id]) {
|
|
91
|
-
var id = _idToUID[t.id] = {};
|
|
92
|
-
_uidToManager.set(id, t);
|
|
93
|
-
}
|
|
94
|
-
}, ogLog = console.error, preventWarnSetState = process.env.NODE_ENV === "production" ? ogLog : (
|
|
95
|
-
// temporary fix for logs, they are harmless in that i've tried to rewrite this
|
|
96
|
-
// a few times using the "right" ways, but they are always slower. maybe skill issue
|
|
97
|
-
function(a) {
|
|
98
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++)
|
|
99
|
-
args[_key - 1] = arguments[_key];
|
|
100
|
-
if (!(typeof a == "string" && a.includes("Cannot update a component")))
|
|
101
|
-
return ogLog(a, ...args);
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
function getShouldUpdateTheme(props, parentManager, keys, themeState, nextState) {
|
|
105
|
-
var forceShouldChange = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : !1, _themeState_themeManager, _themeState_state;
|
|
106
|
-
if (!isServer && !(!forceShouldChange && !keys?.current && (!themeState || !themeState.isNewTheme) && !getHasThemeUpdatingProps(props))) {
|
|
107
|
-
var next = nextState || (themeState == null || (_themeState_themeManager = themeState.themeManager) === null || _themeState_themeManager === void 0 ? void 0 : _themeState_themeManager.getState(props, parentManager));
|
|
108
|
-
if (forceShouldChange)
|
|
109
|
-
return next;
|
|
110
|
-
if (!(!next || next.theme === (themeState == null || (_themeState_state = themeState.state) === null || _themeState_state === void 0 ? void 0 : _themeState_state.theme)))
|
|
111
|
-
return next;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
var useChangeThemeEffect = function(props) {
|
|
115
|
-
var isRoot = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1, keys = arguments.length > 2 ? arguments[2] : void 0, _props_needsUpdate, { disable } = props, parentManager = useContext(ThemeManagerContext), shouldAlwaysUpdate = ((_props_needsUpdate = props.needsUpdate) === null || _props_needsUpdate === void 0 ? void 0 : _props_needsUpdate.call(props)) === !0 ? !0 : void 0;
|
|
116
|
-
if (!isRoot && !parentManager || disable)
|
|
117
|
-
return {
|
|
118
|
-
isNewTheme: !1,
|
|
119
|
-
state: parentManager?.state,
|
|
120
|
-
themeManager: parentManager
|
|
121
|
-
};
|
|
122
|
-
var [themeState, setThemeState] = useState(createState), { state, mounted, isNewTheme, themeManager, prevState } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
|
|
123
|
-
if (themeManager) {
|
|
124
|
-
var nextState = getShouldUpdateTheme(props, parentManager, keys, themeState, void 0, shouldAlwaysUpdate);
|
|
125
|
-
if (nextState) {
|
|
126
|
-
var _next_state, _themeState_state, next = createState(themeState, void 0, nextState);
|
|
127
|
-
((_next_state = next.state) === null || _next_state === void 0 ? void 0 : _next_state.name) !== ((_themeState_state = themeState.state) === null || _themeState_state === void 0 ? void 0 : _themeState_state.name) && (setThemeState(next), console.error = preventWarnSetState, themeManager.notify(), console.error = ogLog);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (isServer || (useEffect(function() {
|
|
131
|
-
if (themeManager) {
|
|
132
|
-
if (props.inverse && !mounted) {
|
|
133
|
-
setThemeState(function(prev) {
|
|
134
|
-
return createState({
|
|
135
|
-
...prev,
|
|
136
|
-
mounted: !0
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if ((isNewTheme || isRoot) && (activeThemeManagers.add(themeManager), process.env.NODE_ENV === "development" && isRoot)) {
|
|
142
|
-
var _globalThis, _TamaguiRootThemeManager;
|
|
143
|
-
(_globalThis = globalThis)[_TamaguiRootThemeManager = "TamaguiRootThemeManager"] || (_globalThis[_TamaguiRootThemeManager] = themeManager);
|
|
144
|
-
}
|
|
145
|
-
var updated = getShouldUpdateTheme(props, parentManager, keys, themeState, void 0, shouldAlwaysUpdate);
|
|
146
|
-
updated && setThemeState(function(prev) {
|
|
147
|
-
return createState(prev, void 0, updated);
|
|
148
|
-
});
|
|
149
|
-
var selfListenerDispose = themeManager.onChangeTheme(function(_a, _b, forced) {
|
|
150
|
-
forced && setThemeState(function(prev) {
|
|
151
|
-
var next2 = createState(prev, forced !== "self");
|
|
152
|
-
return next2;
|
|
153
|
-
});
|
|
154
|
-
}, !0), disposeChangeListener = parentManager?.onChangeTheme(function(name, manager, forced) {
|
|
155
|
-
var force = forced || (isServer ? void 0 : keys?.current ? !0 : void 0) || props.deopt || props["disable-child-theme"], shouldTryUpdate = force ?? !!(keys?.current || isNewTheme);
|
|
156
|
-
process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F538} onChange", {
|
|
157
|
-
id: themeManager.id,
|
|
158
|
-
force,
|
|
159
|
-
shouldTryUpdate,
|
|
160
|
-
props,
|
|
161
|
-
name,
|
|
162
|
-
keys
|
|
163
|
-
}), shouldTryUpdate && setThemeState(function(prev) {
|
|
164
|
-
return createState(prev, !0);
|
|
165
|
-
});
|
|
166
|
-
}, themeManager.id);
|
|
167
|
-
return function() {
|
|
168
|
-
selfListenerDispose(), disposeChangeListener?.(), isNewTheme && activeThemeManagers.delete(themeManager);
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}, [
|
|
172
|
-
themeManager,
|
|
173
|
-
parentManager,
|
|
174
|
-
isNewTheme,
|
|
175
|
-
props.componentName,
|
|
176
|
-
props.inverse,
|
|
177
|
-
props.name,
|
|
178
|
-
props.reset,
|
|
179
|
-
mounted
|
|
180
|
-
]), process.env.NODE_ENV === "development" && props.debug !== "profile" && useEffect(function() {
|
|
181
|
-
var _globalThis, _TamaguiThemeManagers, _;
|
|
182
|
-
return (_ = (_globalThis = globalThis)[_TamaguiThemeManagers = "TamaguiThemeManagers"]) !== null && _ !== void 0 || (_globalThis[_TamaguiThemeManagers] = /* @__PURE__ */ new Set()), globalThis.TamaguiThemeManagers.add(themeManager), function() {
|
|
183
|
-
globalThis.TamaguiThemeManagers.delete(themeManager);
|
|
184
|
-
};
|
|
185
|
-
}, [
|
|
186
|
-
themeManager
|
|
187
|
-
])), isWeb && isInversingOnMount)
|
|
188
|
-
return {
|
|
189
|
-
isNewTheme: !1,
|
|
190
|
-
inversed: !1,
|
|
191
|
-
themeManager: parentManager,
|
|
192
|
-
state: {
|
|
193
|
-
name: "",
|
|
194
|
-
...parentManager?.state,
|
|
195
|
-
className: ""
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
return {
|
|
199
|
-
state,
|
|
200
|
-
isNewTheme,
|
|
201
|
-
inversed: !!props.inverse,
|
|
202
|
-
themeManager
|
|
203
|
-
};
|
|
204
|
-
function createState(prev) {
|
|
205
|
-
var force = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1, foundNextState = arguments.length > 2 ? arguments[2] : void 0;
|
|
206
|
-
if (prev && !foundNextState && !keys?.current && !force)
|
|
207
|
-
return prev;
|
|
208
|
-
var themeManager2 = parentManager, state2, hasThemeUpdatingProps = getHasThemeUpdatingProps(props);
|
|
209
|
-
if (hasThemeUpdatingProps) {
|
|
210
|
-
var parentManagerProp = isRoot ? "root" : parentManager;
|
|
211
|
-
if (prev?.themeManager) {
|
|
212
|
-
themeManager2 = prev.themeManager;
|
|
213
|
-
var forceChange = force || shouldAlwaysUpdate || (keys?.current ? !0 : void 0), nextState2 = null;
|
|
214
|
-
if (foundNextState)
|
|
215
|
-
nextState2 = foundNextState;
|
|
216
|
-
else {
|
|
217
|
-
var next2 = themeManager2.getState(props, parentManager);
|
|
218
|
-
nextState2 = getShouldUpdateTheme(props, parentManager, keys, prev, next2, forceChange);
|
|
219
|
-
}
|
|
220
|
-
nextState2 ? (state2 = nextState2, !prev.isNewTheme && !isRoot ? themeManager2 = new ThemeManager(props, parentManagerProp) : themeManager2.updateState(nextState2)) : prev.isNewTheme && parentManager && !nextState2 && (themeManager2 = parentManager);
|
|
221
|
-
} else
|
|
222
|
-
themeManager2 = new ThemeManager(props, parentManagerProp), state2 = {
|
|
223
|
-
...themeManager2.state
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
var isNewTheme2 = !!(themeManager2 !== parentManager || props.inverse);
|
|
227
|
-
isNewTheme2 && registerThemeManager(themeManager2);
|
|
228
|
-
var isWebSSR = isWeb ? !getSetting("disableSSR") : !1, mounted2 = isWebSSR ? isRoot || prev?.mounted : !0;
|
|
229
|
-
state2 || (isNewTheme2 ? state2 = themeManager2.state : (state2 = parentManager.state, themeManager2 = parentManager));
|
|
230
|
-
var response = {
|
|
231
|
-
themeManager: themeManager2,
|
|
232
|
-
isNewTheme: isNewTheme2,
|
|
233
|
-
mounted: mounted2
|
|
234
|
-
};
|
|
235
|
-
props.inverse && (response.inversed = !0);
|
|
236
|
-
var shouldReturnPrev = prev && !force && // isEqualShallow uses the second arg as the keys so this should compare without state first...
|
|
237
|
-
isEqualShallow(prev, response) && // ... and then compare just the state, because we make a new state obj but is likely the same
|
|
238
|
-
isEqualShallow(prev.state, state2);
|
|
239
|
-
if (prev && shouldReturnPrev)
|
|
240
|
-
return prev;
|
|
241
|
-
if (response.state = state2, response.prevState = prev?.state, process.env.NODE_ENV === "development" && props.debug && isClient) {
|
|
242
|
-
console.groupCollapsed(`\u{1F537} [${themeManager2.id}] useChangeThemeEffect createState`);
|
|
243
|
-
var parentState = {
|
|
244
|
-
...parentManager?.state
|
|
245
|
-
}, parentId = parentManager?.id, themeManagerState = {
|
|
246
|
-
...themeManager2.state
|
|
247
|
-
};
|
|
248
|
-
console.info({
|
|
249
|
-
props,
|
|
250
|
-
parentState,
|
|
251
|
-
parentId,
|
|
252
|
-
themeManager: themeManager2,
|
|
253
|
-
prev,
|
|
254
|
-
response,
|
|
255
|
-
themeManagerState
|
|
256
|
-
}), console.groupEnd();
|
|
257
|
-
}
|
|
258
|
-
return response;
|
|
259
|
-
}
|
|
260
17
|
};
|
|
261
18
|
export {
|
|
262
|
-
activeThemeManagers,
|
|
263
|
-
getThemeManager,
|
|
264
|
-
useChangeThemeEffect,
|
|
265
19
|
useTheme,
|
|
266
20
|
useThemeWithState
|
|
267
21
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/Users/n8/tamagui/code/core/web/src/hooks/useTheme.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAASA,
|
|
5
|
-
"names": ["
|
|
4
|
+
"mappings": "AAAA,SAASA,cAAc;AAEvB,SAASC,uBAA0C;AAEnD,SAASC,qBAAqB;AAEvB,IAAMC,WAAW,WAAA;MAACC,QAAAA,UAAAA,SAAAA,KAAAA,UAAAA,CAAAA,MAAAA,SAAAA,UAAAA,CAAAA,IAAoB,CAAC,GACtC,CAACC,KAAAA,IAASC,kBAAkBF,KAAAA,GAC5BG,MAAMF;AACZ,SAAOE;AACT,GAOaD,oBAAoB,SAC/BF,OAAAA;MACAI,SAAAA,UAAAA,SAAAA,KAAAA,UAAAA,CAAAA,MAAAA,SAAAA,UAAAA,CAAAA,IAAS,IAEHC,OAAOT,OAA2B,IAAA,GAClCU,aAAaR,cAAcE,OAAOI,QAAQC,IAAAA;AAEhD,EAAIE,QAAQC,IAAIC,aAAa,kBACtBH,YAAYL,SACXM,QAAQC,IAAIE,qCAAqC,OACnDC,QAAQC,MACN,2FAA2FC,KAAKC,UAC9Fd,KAAAA,CAAAA;;sKAC4K;AAMtL,MAAMe,eAAelB,gBAAgBG,OAAOM,YAAYD,IAAAA;AAExD,SAAO;IAACU;IAAcT;;AACxB;",
|
|
5
|
+
"names": ["useRef", "getThemeProxied", "useThemeState", "useTheme", "props", "theme", "useThemeWithState", "res", "isRoot", "keys", "themeState", "process", "env", "NODE_ENV", "TAMAGUI_DISABLE_NO_THEME_WARNING", "console", "error", "JSON", "stringify", "themeProxied"]
|
|
6
6
|
}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const manager = React.useContext(ThemeManagerContext), [name, setName] = React.useState(manager?.state.name || "");
|
|
6
|
-
return useIsomorphicLayoutEffect(() => {
|
|
7
|
-
if (manager)
|
|
8
|
-
return setName(manager.state.name), manager.onChangeTheme((next, manager2) => {
|
|
9
|
-
const name2 = opts?.parent && manager2.state.parentName || next;
|
|
10
|
-
name2 && setName(name2);
|
|
11
|
-
});
|
|
12
|
-
}, [manager?.state.name]), name;
|
|
1
|
+
import { useThemeState } from "./useThemeState";
|
|
2
|
+
const forceUpdateState = { forceClassName: !0, deopt: !0, needsUpdate: () => !0 }, forceKeys = { current: /* @__PURE__ */ new Set([""]) };
|
|
3
|
+
function useThemeName() {
|
|
4
|
+
return useThemeState(forceUpdateState, !1, forceKeys)?.name || "";
|
|
13
5
|
}
|
|
14
6
|
export {
|
|
15
7
|
useThemeName
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useThemeName.tsx"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": "AACA,SAAS,qBAAqB;AAG9B,MAAM,mBAAmB,EAAE,gBAAgB,IAAM,OAAO,IAAM,aAAa,MAAM,GAAK,GAChF,YAAY,EAAE,SAAS,oBAAI,IAAI,CAAC,EAAE,CAAC,EAAE;AAEpC,SAAS,eAA0B;AACxC,SAAO,cAAc,kBAAkB,IAAO,SAAS,GAAG,QAAQ;AACpE;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}, [manager?.state.name]), name;
|
|
1
|
+
import { useThemeState } from "./useThemeState.mjs";
|
|
2
|
+
const forceUpdateState = {
|
|
3
|
+
forceClassName: !0,
|
|
4
|
+
deopt: !0,
|
|
5
|
+
needsUpdate: () => !0
|
|
6
|
+
},
|
|
7
|
+
forceKeys = {
|
|
8
|
+
current: /* @__PURE__ */new Set([""])
|
|
9
|
+
};
|
|
10
|
+
function useThemeName() {
|
|
11
|
+
return useThemeState(forceUpdateState, !1, forceKeys)?.name || "";
|
|
13
12
|
}
|
|
14
13
|
export { useThemeName };
|
|
15
14
|
//# sourceMappingURL=useThemeName.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useThemeState","forceUpdateState","forceClassName","deopt","needsUpdate","forceKeys","current","Set","useThemeName","name"],"sources":["../../../src/hooks/useThemeName.tsx"],"sourcesContent":[null],"mappings":"AACA,SAASA,aAAA,QAAqB;AAG9B,MAAMC,gBAAA,GAAmB;IAAEC,cAAA,EAAgB;IAAMC,KAAA,EAAO;IAAMC,WAAA,EAAaA,CAAA,KAAM;EAAK;EAChFC,SAAA,GAAY;IAAEC,OAAA,EAAS,mBAAIC,GAAA,CAAI,CAAC,EAAE,CAAC;EAAE;AAEpC,SAASC,aAAA,EAA0B;EACxC,OAAOR,aAAA,CAAcC,gBAAA,EAAkB,IAAOI,SAAS,GAAGI,IAAA,IAAQ;AACpE","ignoreList":[]}
|