@tamagui/web 1.121.12 → 1.122.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/createComponent.cjs +9 -10
- package/dist/cjs/createComponent.js +7 -16
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createComponent.native.js +9 -13
- package/dist/cjs/createComponent.native.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js.map +1 -1
- package/dist/cjs/helpers/ThemeManager.native.js.map +1 -1
- package/dist/cjs/helpers/ThemeManagerContext.cjs +2 -2
- package/dist/cjs/helpers/ThemeManagerContext.js +2 -2
- package/dist/cjs/helpers/ThemeManagerContext.js.map +1 -1
- package/dist/cjs/helpers/ThemeManagerContext.native.js +3 -3
- package/dist/cjs/helpers/ThemeManagerContext.native.js.map +2 -2
- package/dist/cjs/helpers/expandStyle.cjs +3 -3
- package/dist/cjs/helpers/expandStyle.js +2 -2
- package/dist/cjs/helpers/expandStyle.js.map +1 -1
- package/dist/cjs/helpers/expandStyle.native.js +1 -1
- package/dist/cjs/helpers/expandStyle.native.js.map +1 -1
- package/dist/cjs/helpers/expandStyles.js.map +1 -1
- package/dist/cjs/helpers/expandStyles.native.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.cjs +64 -93
- package/dist/cjs/helpers/getSplitStyles.js +60 -86
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.native.js +344 -372
- package/dist/cjs/helpers/getSplitStyles.native.js.map +2 -2
- package/dist/cjs/helpers/getThemeCSSRules.cjs +1 -1
- package/dist/cjs/helpers/getThemeCSSRules.js +1 -1
- package/dist/cjs/helpers/getThemeCSSRules.js.map +1 -1
- package/dist/cjs/helpers/insertStyleRule.cjs +6 -6
- package/dist/cjs/helpers/insertStyleRule.js +6 -11
- package/dist/cjs/helpers/insertStyleRule.js.map +1 -1
- package/dist/cjs/helpers/insertStyleRule.native.js +17 -16
- package/dist/cjs/helpers/insertStyleRule.native.js.map +2 -2
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +1 -1
- package/dist/cjs/helpers/normalizeValueWithProperty.native.js.map +1 -1
- package/dist/cjs/helpers/propMapper.cjs +21 -15
- package/dist/cjs/helpers/propMapper.js +26 -20
- package/dist/cjs/helpers/propMapper.js.map +2 -2
- package/dist/cjs/helpers/propMapper.native.js +27 -21
- package/dist/cjs/helpers/propMapper.native.js.map +2 -2
- package/dist/cjs/hooks/useTheme.cjs +148 -169
- package/dist/cjs/hooks/useTheme.js +64 -69
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/hooks/useTheme.native.js +60 -72
- package/dist/cjs/hooks/useTheme.native.js.map +2 -2
- package/dist/cjs/hooks/useThemeName.cjs +4 -5
- package/dist/cjs/hooks/useThemeName.js +2 -2
- package/dist/cjs/hooks/useThemeName.js.map +1 -1
- package/dist/cjs/hooks/useThemeName.native.js +2 -2
- package/dist/cjs/hooks/useThemeName.native.js.map +2 -2
- package/dist/cjs/views/Theme.cjs +3 -4
- package/dist/cjs/views/Theme.js +2 -3
- package/dist/cjs/views/Theme.js.map +1 -1
- package/dist/cjs/views/Theme.native.js +3 -4
- package/dist/cjs/views/Theme.native.js.map +2 -2
- package/dist/esm/createComponent.js +7 -16
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createComponent.mjs +9 -10
- package/dist/esm/createComponent.mjs.map +1 -1
- package/dist/esm/createComponent.native.js +8 -11
- package/dist/esm/createComponent.native.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js.map +1 -1
- package/dist/esm/helpers/ThemeManager.mjs.map +1 -1
- package/dist/esm/helpers/ThemeManager.native.js.map +1 -1
- package/dist/esm/helpers/ThemeManagerContext.js +2 -2
- package/dist/esm/helpers/ThemeManagerContext.js.map +1 -1
- package/dist/esm/helpers/ThemeManagerContext.mjs +2 -2
- package/dist/esm/helpers/ThemeManagerContext.mjs.map +1 -1
- package/dist/esm/helpers/ThemeManagerContext.native.js +2 -2
- package/dist/esm/helpers/ThemeManagerContext.native.js.map +2 -2
- package/dist/esm/helpers/expandStyle.js +2 -2
- package/dist/esm/helpers/expandStyle.js.map +1 -1
- package/dist/esm/helpers/expandStyle.mjs +2 -2
- package/dist/esm/helpers/expandStyle.mjs.map +1 -1
- package/dist/esm/helpers/expandStyle.native.js +1 -1
- package/dist/esm/helpers/expandStyle.native.js.map +1 -1
- package/dist/esm/helpers/expandStyles.js.map +1 -1
- package/dist/esm/helpers/expandStyles.mjs.map +1 -1
- package/dist/esm/helpers/expandStyles.native.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +61 -92
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.mjs +65 -94
- package/dist/esm/helpers/getSplitStyles.mjs.map +1 -1
- package/dist/esm/helpers/getSplitStyles.native.js +347 -375
- package/dist/esm/helpers/getSplitStyles.native.js.map +2 -2
- package/dist/esm/helpers/getThemeCSSRules.js +1 -1
- package/dist/esm/helpers/getThemeCSSRules.js.map +1 -1
- package/dist/esm/helpers/getThemeCSSRules.mjs +1 -1
- package/dist/esm/helpers/getThemeCSSRules.mjs.map +1 -1
- package/dist/esm/helpers/insertStyleRule.js +6 -11
- package/dist/esm/helpers/insertStyleRule.js.map +1 -1
- package/dist/esm/helpers/insertStyleRule.mjs +6 -6
- package/dist/esm/helpers/insertStyleRule.mjs.map +1 -1
- package/dist/esm/helpers/insertStyleRule.native.js +17 -16
- package/dist/esm/helpers/insertStyleRule.native.js.map +2 -2
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +1 -1
- package/dist/esm/helpers/normalizeValueWithProperty.mjs.map +1 -1
- package/dist/esm/helpers/normalizeValueWithProperty.native.js.map +1 -1
- package/dist/esm/helpers/propMapper.js +26 -20
- package/dist/esm/helpers/propMapper.js.map +2 -2
- package/dist/esm/helpers/propMapper.mjs +22 -15
- package/dist/esm/helpers/propMapper.mjs.map +1 -1
- package/dist/esm/helpers/propMapper.native.js +28 -21
- package/dist/esm/helpers/propMapper.native.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +70 -60
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/hooks/useTheme.mjs +145 -154
- package/dist/esm/hooks/useTheme.mjs.map +1 -1
- package/dist/esm/hooks/useTheme.native.js +59 -62
- package/dist/esm/hooks/useTheme.native.js.map +2 -2
- package/dist/esm/hooks/useThemeName.js +3 -4
- package/dist/esm/hooks/useThemeName.js.map +1 -1
- package/dist/esm/hooks/useThemeName.mjs +3 -4
- package/dist/esm/hooks/useThemeName.mjs.map +1 -1
- package/dist/esm/hooks/useThemeName.native.js +3 -4
- package/dist/esm/hooks/useThemeName.native.js.map +2 -2
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/views/Theme.js +3 -4
- package/dist/esm/views/Theme.js.map +1 -1
- package/dist/esm/views/Theme.mjs +4 -5
- package/dist/esm/views/Theme.mjs.map +1 -1
- package/dist/esm/views/Theme.native.js +4 -5
- package/dist/esm/views/Theme.native.js.map +2 -2
- package/package.json +11 -11
- package/src/createComponent.tsx +7 -15
- package/src/helpers/ThemeManager.tsx +1 -0
- package/src/helpers/ThemeManagerContext.tsx +2 -1
- package/src/helpers/expandStyle.ts +3 -3
- package/src/helpers/expandStyles.ts +0 -1
- package/src/helpers/getSplitStyles.tsx +111 -127
- package/src/helpers/getThemeCSSRules.ts +7 -6
- package/src/helpers/insertStyleRule.tsx +9 -16
- package/src/helpers/normalizeValueWithProperty.ts +0 -2
- package/src/helpers/propMapper.ts +28 -36
- package/src/hooks/useTheme.tsx +143 -113
- package/src/hooks/useThemeName.tsx +3 -5
- package/src/setupHooks.ts +1 -7
- package/src/types.tsx +15 -15
- package/src/views/Theme.tsx +5 -5
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/helpers/ThemeManagerContext.d.ts +2 -1
- package/types/helpers/ThemeManagerContext.d.ts.map +1 -1
- package/types/helpers/expandStyle.d.ts.map +1 -1
- package/types/helpers/expandStyles.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getThemeCSSRules.d.ts.map +1 -1
- package/types/helpers/insertStyleRule.d.ts.map +1 -1
- package/types/helpers/normalizeValueWithProperty.d.ts.map +1 -1
- package/types/helpers/propMapper.d.ts +0 -1
- package/types/helpers/propMapper.d.ts.map +1 -1
- package/types/hooks/useConfiguration.d.ts +30 -50
- package/types/hooks/useConfiguration.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +3 -3
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/hooks/useThemeName.d.ts.map +1 -1
- package/types/setupHooks.d.ts +1 -1
- package/types/setupHooks.d.ts.map +1 -1
- package/types/types.d.ts +23 -13
- package/types/types.d.ts.map +1 -1
- package/types/views/Theme.d.ts.map +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var
|
|
6
|
-
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all) __defProp(target, name, {
|
|
9
7
|
get: all[name],
|
|
@@ -17,30 +15,20 @@ var __export = (target, all) => {
|
|
|
17
15
|
});
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
-
value: mod,
|
|
27
|
-
enumerable: !0
|
|
28
|
-
}) : target, mod)),
|
|
29
|
-
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
-
value: !0
|
|
31
|
-
}), mod);
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
32
21
|
var useTheme_exports = {};
|
|
33
22
|
__export(useTheme_exports, {
|
|
34
23
|
activeThemeManagers: () => activeThemeManagers,
|
|
35
24
|
getThemeManager: () => getThemeManager,
|
|
36
|
-
getThemeProxied: () => getThemeProxied,
|
|
37
25
|
useChangeThemeEffect: () => useChangeThemeEffect,
|
|
38
26
|
useTheme: () => useTheme,
|
|
39
27
|
useThemeWithState: () => useThemeWithState
|
|
40
28
|
});
|
|
41
29
|
module.exports = __toCommonJS(useTheme_exports);
|
|
42
|
-
var
|
|
43
|
-
|
|
30
|
+
var import_constants = require("@tamagui/constants"),
|
|
31
|
+
import_react = require("react"),
|
|
44
32
|
import_config = require("../config.cjs"),
|
|
45
33
|
import_createVariable = require("../createVariable.cjs"),
|
|
46
34
|
import_ThemeManager = require("../helpers/ThemeManager.cjs"),
|
|
@@ -48,50 +36,37 @@ var import_react = __toESM(require("react")),
|
|
|
48
36
|
import_createShallowSetState = require("../helpers/createShallowSetState.cjs"),
|
|
49
37
|
import_shouldDeoptDueToParentScheme = require("./shouldDeoptDueToParentScheme.cjs");
|
|
50
38
|
const emptyProps = {
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getDefaultThemeProxied() {
|
|
55
|
-
if (cached) return cached;
|
|
56
|
-
const config = (0, import_config.getConfig)(),
|
|
57
|
-
name = config.themes.light ? "light" : Object.keys(config.themes)[0],
|
|
58
|
-
defaultTheme = config.themes[name];
|
|
59
|
-
return cached = getThemeProxied({
|
|
60
|
-
theme: defaultTheme,
|
|
61
|
-
name
|
|
62
|
-
}), cached;
|
|
63
|
-
}
|
|
64
|
-
const useTheme = (props = emptyProps) => {
|
|
39
|
+
name: null
|
|
40
|
+
},
|
|
41
|
+
useTheme = (props = emptyProps) => {
|
|
65
42
|
const [_, theme] = useThemeWithState(props);
|
|
66
|
-
return theme
|
|
43
|
+
return theme;
|
|
67
44
|
},
|
|
68
45
|
useThemeWithState = props => {
|
|
69
|
-
const keys = import_react.
|
|
70
|
-
changedThemeState = useChangeThemeEffect(props, !1, keys
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
state
|
|
77
|
-
} = changedThemeState;
|
|
46
|
+
const keys = (0, import_react.useRef)(null),
|
|
47
|
+
changedThemeState = useChangeThemeEffect(props, !1, keys);
|
|
48
|
+
process.env.NODE_ENV === "development" && globalThis.time && time`theme-change-effect`;
|
|
49
|
+
const {
|
|
50
|
+
themeManager,
|
|
51
|
+
state
|
|
52
|
+
} = changedThemeState;
|
|
78
53
|
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)}).
|
|
79
54
|
|
|
80
55
|
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`));
|
|
81
|
-
const themeProxied = import_react.
|
|
56
|
+
const themeProxied = (0, import_react.useMemo)(() => (keys.current && (keys.current = null), !themeManager || !state?.theme ? {} : getThemeProxied(state, props.deopt, keys, themeManager, props.debug)), [state?.theme, themeManager, props.deopt, props.debug]);
|
|
82
57
|
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];
|
|
83
58
|
};
|
|
84
59
|
function getThemeProxied({
|
|
85
60
|
theme,
|
|
86
61
|
name,
|
|
87
62
|
scheme
|
|
88
|
-
}, deopt = !1,
|
|
63
|
+
}, deopt = !1, keys, themeManager, debug) {
|
|
89
64
|
if (!theme) return {};
|
|
90
65
|
const config = (0, import_config.getConfig)();
|
|
91
66
|
function track(key) {
|
|
92
|
-
keys
|
|
67
|
+
keys.current || (keys.current = [], setTimeout(() => {
|
|
93
68
|
themeManager?.selfUpdate();
|
|
94
|
-
}), keys.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`)
|
|
69
|
+
})), keys.current.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`);
|
|
95
70
|
}
|
|
96
71
|
return new Proxy(theme, {
|
|
97
72
|
has(_, key) {
|
|
@@ -137,133 +112,137 @@ const activeThemeManagers = /* @__PURE__ */new Set(),
|
|
|
137
112
|
// a few times using the "right" ways, but they are always slower. maybe skill issue
|
|
138
113
|
(a, ...args) => {
|
|
139
114
|
if (!(typeof a == "string" && a.includes("Cannot update a component"))) return ogLog(a, ...args);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
115
|
+
};
|
|
116
|
+
function getShouldUpdateTheme(props, parentManager, keys, themeState, nextState, forceShouldChange = !1) {
|
|
117
|
+
if (import_constants.isServer || !forceShouldChange && !keys?.current && (!themeState || !themeState.isNewTheme) && !(0, import_ThemeManager.getHasThemeUpdatingProps)(props)) return;
|
|
118
|
+
const next = nextState || themeState?.themeManager?.getState(props, parentManager);
|
|
119
|
+
if (forceShouldChange) return next;
|
|
120
|
+
if (!(!next || next.theme === themeState?.state?.theme)) return next;
|
|
121
|
+
}
|
|
122
|
+
const useChangeThemeEffect = (props, isRoot = !1, keys) => {
|
|
123
|
+
const {
|
|
124
|
+
disable
|
|
125
|
+
} = props,
|
|
126
|
+
parentManager = (0, import_react.useContext)(import_ThemeManagerContext.ThemeManagerContext),
|
|
127
|
+
shouldAlwaysUpdate = props.needsUpdate?.() === !0 ? !0 : void 0;
|
|
128
|
+
if (!isRoot && !parentManager || disable) return {
|
|
129
|
+
isNewTheme: !1,
|
|
130
|
+
state: parentManager?.state,
|
|
131
|
+
themeManager: parentManager
|
|
132
|
+
};
|
|
133
|
+
const [themeState, setThemeState] = (0, import_react.useState)(createState),
|
|
134
|
+
{
|
|
135
|
+
state,
|
|
136
|
+
mounted,
|
|
137
|
+
isNewTheme,
|
|
138
|
+
themeManager,
|
|
139
|
+
prevState
|
|
140
|
+
} = themeState,
|
|
141
|
+
isInversingOnMount = !!(!themeState.mounted && props.inverse);
|
|
142
|
+
if (import_constants.isServer || ((0, import_react.useLayoutEffect)(() => {
|
|
143
|
+
themeManager && state && prevState && state !== prevState && themeManager.notify();
|
|
144
|
+
}, [state]), (0, import_react.useEffect)(() => {
|
|
145
|
+
if (!themeManager) return;
|
|
146
|
+
if (props.inverse && !mounted) {
|
|
147
|
+
setThemeState(prev => createState({
|
|
148
|
+
...prev,
|
|
149
|
+
mounted: !0
|
|
150
|
+
}));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
(isNewTheme || isRoot) && (activeThemeManagers.add(themeManager), process.env.NODE_ENV === "development" && isRoot && (globalThis.TamaguiRootThemeManager ||= themeManager));
|
|
154
|
+
const updated = getShouldUpdateTheme(props, parentManager, keys, themeState, void 0, shouldAlwaysUpdate);
|
|
155
|
+
updated && setThemeState(prev => createState(prev, void 0, updated));
|
|
156
|
+
const selfListenerDispose = themeManager.onChangeTheme((_a, _b, forced) => {
|
|
157
|
+
forced && setThemeState(prev => createState(prev, forced !== "self"));
|
|
158
|
+
}, !0),
|
|
159
|
+
disposeChangeListener = parentManager?.onChangeTheme((name, manager, forced) => {
|
|
160
|
+
const force = forced || (import_constants.isServer ? void 0 : keys?.current ? !0 : void 0) || props.deopt || void 0,
|
|
161
|
+
shouldTryUpdate = force ?? !!(keys?.current || isNewTheme);
|
|
162
|
+
process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F538} onChange", {
|
|
163
|
+
id: themeManager.id,
|
|
164
|
+
force,
|
|
165
|
+
shouldTryUpdate,
|
|
166
|
+
props,
|
|
167
|
+
name,
|
|
168
|
+
keys
|
|
169
|
+
}), shouldTryUpdate && setThemeState(prev => createState(prev, !0));
|
|
170
|
+
}, themeManager.id);
|
|
171
|
+
return () => {
|
|
172
|
+
selfListenerDispose(), disposeChangeListener?.(), isNewTheme && activeThemeManagers.delete(themeManager);
|
|
151
173
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const forceUpdate = shouldUpdate?.();
|
|
163
|
-
if (!manager || !forceShouldChange && forceUpdate === !1) return;
|
|
164
|
-
const next = nextState || manager.getState(props, parentManager);
|
|
165
|
-
if (forceShouldChange) return next;
|
|
166
|
-
if (next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState2))) return next;
|
|
174
|
+
}, [themeManager, parentManager, isNewTheme, props.componentName, props.inverse, props.name, props.reset, mounted]), process.env.NODE_ENV === "development" && props.debug !== "profile" && (0, import_react.useEffect)(() => (globalThis.TamaguiThemeManagers ??= /* @__PURE__ */new Set(), globalThis.TamaguiThemeManagers.add(themeManager), () => {
|
|
175
|
+
globalThis.TamaguiThemeManagers.delete(themeManager);
|
|
176
|
+
}), [themeManager])), import_constants.isWeb && isInversingOnMount) return {
|
|
177
|
+
isNewTheme: !1,
|
|
178
|
+
inversed: !1,
|
|
179
|
+
themeManager: parentManager,
|
|
180
|
+
state: {
|
|
181
|
+
name: "",
|
|
182
|
+
...parentManager?.state,
|
|
183
|
+
className: ""
|
|
167
184
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
keys
|
|
193
|
-
}), shouldTryUpdate && setThemeState(prev => createState(prev, force));
|
|
194
|
-
}, themeManager.id);
|
|
195
|
-
return () => {
|
|
196
|
-
selfListenerDispose(), disposeChangeListener?.(), isNewTheme && activeThemeManagers.delete(themeManager);
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
state,
|
|
188
|
+
isNewTheme,
|
|
189
|
+
inversed: !!props.inverse,
|
|
190
|
+
themeManager
|
|
191
|
+
};
|
|
192
|
+
function createState(prev, force = !1, foundNextState) {
|
|
193
|
+
if (prev && !foundNextState && !keys?.current && !force) return prev;
|
|
194
|
+
let themeManager2 = parentManager,
|
|
195
|
+
state2;
|
|
196
|
+
if ((0, import_ThemeManager.getHasThemeUpdatingProps)(props)) {
|
|
197
|
+
const parentManagerProp = isRoot ? "root" : parentManager;
|
|
198
|
+
if (prev?.themeManager) {
|
|
199
|
+
themeManager2 = prev.themeManager;
|
|
200
|
+
const forceChange = force || shouldAlwaysUpdate || (keys?.current ? !0 : void 0);
|
|
201
|
+
let nextState = null;
|
|
202
|
+
if (foundNextState) nextState = foundNextState;else {
|
|
203
|
+
const next = themeManager2.getState(props, parentManager);
|
|
204
|
+
nextState = getShouldUpdateTheme(props, parentManager, keys, prev, next, forceChange);
|
|
205
|
+
}
|
|
206
|
+
nextState ? (state2 = nextState, !prev.isNewTheme && !isRoot ? themeManager2 = new import_ThemeManager.ThemeManager(props, parentManagerProp) : themeManager2.updateState(nextState)) : prev.isNewTheme && parentManager && !nextState && (themeManager2 = parentManager);
|
|
207
|
+
} else themeManager2 = new import_ThemeManager.ThemeManager(props, parentManagerProp), state2 = {
|
|
208
|
+
...themeManager2.state
|
|
197
209
|
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
className: ""
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
return {
|
|
211
|
-
state,
|
|
212
|
-
isNewTheme,
|
|
213
|
-
inversed: !!props.inverse,
|
|
214
|
-
themeManager
|
|
210
|
+
}
|
|
211
|
+
const isNewTheme2 = !!(themeManager2 !== parentManager || props.inverse);
|
|
212
|
+
isNewTheme2 && registerThemeManager(themeManager2);
|
|
213
|
+
const mounted2 = (import_constants.isWeb ? !(0, import_config.getSetting)("disableSSR") : !1) ? isRoot || prev?.mounted : !0;
|
|
214
|
+
state2 || (isNewTheme2 ? state2 = themeManager2.state : (state2 = parentManager.state, themeManager2 = parentManager));
|
|
215
|
+
const response = {
|
|
216
|
+
themeManager: themeManager2,
|
|
217
|
+
isNewTheme: isNewTheme2,
|
|
218
|
+
mounted: mounted2
|
|
215
219
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
220
|
+
props.inverse && (response.inversed = !0);
|
|
221
|
+
const shouldReturnPrev = prev && !force &&
|
|
222
|
+
// isEqualShallow uses the second arg as the keys so this should compare without state first...
|
|
223
|
+
(0, import_createShallowSetState.isEqualShallow)(prev, response) &&
|
|
224
|
+
// ... and then compare just the state, because we make a new state obj but is likely the same
|
|
225
|
+
(0, import_createShallowSetState.isEqualShallow)(prev.state, state2);
|
|
226
|
+
if (prev && shouldReturnPrev) return prev;
|
|
227
|
+
if (response.state = state2, response.prevState = prev?.state, process.env.NODE_ENV === "development" && props.debug && import_constants.isClient) {
|
|
228
|
+
console.groupCollapsed(`\u{1F537} [${themeManager2.id}] useChangeThemeEffect createState`);
|
|
229
|
+
const parentState = {
|
|
230
|
+
...parentManager?.state
|
|
231
|
+
},
|
|
232
|
+
parentId = parentManager?.id,
|
|
233
|
+
themeManagerState = {
|
|
229
234
|
...themeManager2.state
|
|
230
235
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
inversed: props.inverse
|
|
241
|
-
},
|
|
242
|
-
shouldReturnPrev = prev && !force &&
|
|
243
|
-
// isEqualShallow uses the second arg as the keys so this should compare without state first...
|
|
244
|
-
(0, import_createShallowSetState.isEqualShallow)(prev, response) &&
|
|
245
|
-
// ... and then compare just the state, because we make a new state obj but is likely the same
|
|
246
|
-
(0, import_createShallowSetState.isEqualShallow)(prev.state, state2);
|
|
247
|
-
if (prev && shouldReturnPrev) return prev;
|
|
248
|
-
if (response.state = state2, response.prevState = prev?.state, process.env.NODE_ENV === "development" && props.debug && import_constants.isClient) {
|
|
249
|
-
console.groupCollapsed(`\u{1F537} [${themeManager2.id}] useChangeThemeEffect createState`);
|
|
250
|
-
const parentState = {
|
|
251
|
-
...parentManager?.state
|
|
252
|
-
},
|
|
253
|
-
parentId = parentManager?.id,
|
|
254
|
-
themeManagerState = {
|
|
255
|
-
...themeManager2.state
|
|
256
|
-
};
|
|
257
|
-
console.info({
|
|
258
|
-
props,
|
|
259
|
-
parentState,
|
|
260
|
-
parentId,
|
|
261
|
-
themeManager: themeManager2,
|
|
262
|
-
prev,
|
|
263
|
-
response,
|
|
264
|
-
themeManagerState
|
|
265
|
-
}), console.groupEnd();
|
|
266
|
-
}
|
|
267
|
-
return response;
|
|
236
|
+
console.info({
|
|
237
|
+
props,
|
|
238
|
+
parentState,
|
|
239
|
+
parentId,
|
|
240
|
+
themeManager: themeManager2,
|
|
241
|
+
prev,
|
|
242
|
+
response,
|
|
243
|
+
themeManagerState
|
|
244
|
+
}), console.groupEnd();
|
|
268
245
|
}
|
|
269
|
-
|
|
246
|
+
return response;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
7
|
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
@@ -12,48 +11,24 @@ var __export = (target, all) => {
|
|
|
12
11
|
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
12
|
return to;
|
|
14
13
|
};
|
|
15
|
-
var
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
15
|
var useTheme_exports = {};
|
|
24
16
|
__export(useTheme_exports, {
|
|
25
17
|
activeThemeManagers: () => activeThemeManagers,
|
|
26
18
|
getThemeManager: () => getThemeManager,
|
|
27
|
-
getThemeProxied: () => getThemeProxied,
|
|
28
19
|
useChangeThemeEffect: () => useChangeThemeEffect,
|
|
29
20
|
useTheme: () => useTheme,
|
|
30
21
|
useThemeWithState: () => useThemeWithState
|
|
31
22
|
});
|
|
32
23
|
module.exports = __toCommonJS(useTheme_exports);
|
|
33
|
-
var
|
|
34
|
-
const emptyProps = { name: null }
|
|
35
|
-
let cached;
|
|
36
|
-
function getDefaultThemeProxied() {
|
|
37
|
-
if (cached) return cached;
|
|
38
|
-
const config = (0, import_config.getConfig)(), name = config.themes.light ? "light" : Object.keys(config.themes)[0], defaultTheme = config.themes[name];
|
|
39
|
-
return cached = getThemeProxied({ theme: defaultTheme, name }), cached;
|
|
40
|
-
}
|
|
41
|
-
const useTheme = (props = emptyProps) => {
|
|
24
|
+
var import_constants = require("@tamagui/constants"), import_react = require("react"), import_config = require("../config"), import_createVariable = require("../createVariable"), import_ThemeManager = require("../helpers/ThemeManager"), import_ThemeManagerContext = require("../helpers/ThemeManagerContext"), import_createShallowSetState = require("../helpers/createShallowSetState"), import_shouldDeoptDueToParentScheme = require("./shouldDeoptDueToParentScheme");
|
|
25
|
+
const emptyProps = { name: null }, useTheme = (props = emptyProps) => {
|
|
42
26
|
const [_, theme] = useThemeWithState(props);
|
|
43
|
-
return theme
|
|
27
|
+
return theme;
|
|
44
28
|
}, useThemeWithState = (props) => {
|
|
45
|
-
const keys = import_react.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
keys.current,
|
|
49
|
-
import_constants.isServer ? void 0 : () => {
|
|
50
|
-
const next = props.shouldUpdate?.() ?? (keys.current.length > 0 ? !0 : void 0);
|
|
51
|
-
return process.env.NODE_ENV === "development" && typeof props.debug == "string" && props.debug !== "profile" && console.info(
|
|
52
|
-
` \u{1F3A8} useTheme() shouldUpdate? tracking keys ${keys.current.length} ${props.shouldUpdate?.()}`,
|
|
53
|
-
next
|
|
54
|
-
), next;
|
|
55
|
-
}
|
|
56
|
-
), { themeManager, state } = changedThemeState;
|
|
29
|
+
const keys = (0, import_react.useRef)(null), changedThemeState = useChangeThemeEffect(props, !1, keys);
|
|
30
|
+
process.env.NODE_ENV === "development" && globalThis.time && time`theme-change-effect`;
|
|
31
|
+
const { themeManager, state } = changedThemeState;
|
|
57
32
|
process.env.NODE_ENV === "development" && (state?.theme || process.env.TAMAGUI_DISABLE_NO_THEME_WARNING !== "1" && console.error(
|
|
58
33
|
`[tamagui] No theme found, this could be due to an invalid theme name (given theme props ${JSON.stringify(
|
|
59
34
|
props
|
|
@@ -61,7 +36,7 @@ const useTheme = (props = emptyProps) => {
|
|
|
61
36
|
|
|
62
37
|
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`
|
|
63
38
|
));
|
|
64
|
-
const themeProxied = import_react.
|
|
39
|
+
const themeProxied = (0, import_react.useMemo)(() => (keys.current && (keys.current = null), !themeManager || !state?.theme ? {} : getThemeProxied(state, props.deopt, keys, themeManager, props.debug)), [state?.theme, themeManager, props.deopt, props.debug]);
|
|
65
40
|
return process.env.NODE_ENV === "development" && props.debug === "verbose" && (console.groupCollapsed(` \u{1F539} [${themeManager?.id}] useTheme =>`, state?.name), console.info(
|
|
66
41
|
"returning state",
|
|
67
42
|
changedThemeState.state,
|
|
@@ -70,13 +45,13 @@ If this is intended and you are using Tamagui without any themes, you can disabl
|
|
|
70
45
|
props
|
|
71
46
|
), console.groupEnd()), [changedThemeState, themeProxied];
|
|
72
47
|
};
|
|
73
|
-
function getThemeProxied({ theme, name, scheme }, deopt = !1,
|
|
48
|
+
function getThemeProxied({ theme, name, scheme }, deopt = !1, keys, themeManager, debug) {
|
|
74
49
|
if (!theme) return {};
|
|
75
50
|
const config = (0, import_config.getConfig)();
|
|
76
51
|
function track(key) {
|
|
77
|
-
keys
|
|
52
|
+
keys.current || (keys.current = [], setTimeout(() => {
|
|
78
53
|
themeManager?.selfUpdate();
|
|
79
|
-
}), keys.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`)
|
|
54
|
+
})), keys.current.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`);
|
|
80
55
|
}
|
|
81
56
|
return new Proxy(theme, {
|
|
82
57
|
has(_, key) {
|
|
@@ -131,27 +106,28 @@ const activeThemeManagers = /* @__PURE__ */ new Set(), _uidToManager = /* @__PUR
|
|
|
131
106
|
if (!(typeof a == "string" && a.includes("Cannot update a component")))
|
|
132
107
|
return ogLog(a, ...args);
|
|
133
108
|
}
|
|
134
|
-
)
|
|
135
|
-
|
|
109
|
+
);
|
|
110
|
+
function getShouldUpdateTheme(props, parentManager, keys, themeState, nextState, forceShouldChange = !1) {
|
|
111
|
+
if (import_constants.isServer || !forceShouldChange && !keys?.current && (!themeState || !themeState.isNewTheme) && !(0, import_ThemeManager.getHasThemeUpdatingProps)(props))
|
|
112
|
+
return;
|
|
113
|
+
const next = nextState || themeState?.themeManager?.getState(props, parentManager);
|
|
114
|
+
if (forceShouldChange)
|
|
115
|
+
return next;
|
|
116
|
+
if (!(!next || next.theme === themeState?.state?.theme))
|
|
117
|
+
return next;
|
|
118
|
+
}
|
|
119
|
+
const useChangeThemeEffect = (props, isRoot = !1, keys) => {
|
|
120
|
+
const { disable } = props, parentManager = (0, import_react.useContext)(import_ThemeManagerContext.ThemeManagerContext), shouldAlwaysUpdate = props.needsUpdate?.() === !0 ? !0 : void 0;
|
|
136
121
|
if (!isRoot && !parentManager || disable)
|
|
137
122
|
return {
|
|
138
123
|
isNewTheme: !1,
|
|
139
124
|
state: parentManager?.state,
|
|
140
125
|
themeManager: parentManager
|
|
141
126
|
};
|
|
142
|
-
const [themeState, setThemeState] = import_react.
|
|
143
|
-
|
|
144
|
-
const forceUpdate = shouldUpdate?.();
|
|
145
|
-
if (!manager || !forceShouldChange && forceUpdate === !1) return;
|
|
146
|
-
const next = nextState || manager.getState(props, parentManager);
|
|
147
|
-
if (forceShouldChange)
|
|
148
|
-
return next;
|
|
149
|
-
if (next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState2)))
|
|
150
|
-
return next;
|
|
151
|
-
}
|
|
152
|
-
if (import_constants.isServer || (import_react.default.useLayoutEffect(() => {
|
|
127
|
+
const [themeState, setThemeState] = (0, import_react.useState)(createState), { state, mounted, isNewTheme, themeManager, prevState } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
|
|
128
|
+
if (import_constants.isServer || ((0, import_react.useLayoutEffect)(() => {
|
|
153
129
|
themeManager && state && prevState && state !== prevState && themeManager.notify();
|
|
154
|
-
}, [state]), import_react.
|
|
130
|
+
}, [state]), (0, import_react.useEffect)(() => {
|
|
155
131
|
if (!themeManager) return;
|
|
156
132
|
if (props.inverse && !mounted) {
|
|
157
133
|
setThemeState((prev) => createState({
|
|
@@ -160,12 +136,21 @@ const activeThemeManagers = /* @__PURE__ */ new Set(), _uidToManager = /* @__PUR
|
|
|
160
136
|
}));
|
|
161
137
|
return;
|
|
162
138
|
}
|
|
163
|
-
(isNewTheme ||
|
|
139
|
+
(isNewTheme || isRoot) && (activeThemeManagers.add(themeManager), process.env.NODE_ENV === "development" && isRoot && (globalThis.TamaguiRootThemeManager ||= themeManager));
|
|
140
|
+
const updated = getShouldUpdateTheme(
|
|
141
|
+
props,
|
|
142
|
+
parentManager,
|
|
143
|
+
keys,
|
|
144
|
+
themeState,
|
|
145
|
+
void 0,
|
|
146
|
+
shouldAlwaysUpdate
|
|
147
|
+
);
|
|
148
|
+
updated && setThemeState((prev) => createState(prev, void 0, updated));
|
|
164
149
|
const selfListenerDispose = themeManager.onChangeTheme((_a, _b, forced) => {
|
|
165
150
|
forced && setThemeState((prev) => createState(prev, forced !== "self"));
|
|
166
151
|
}, !0), disposeChangeListener = parentManager?.onChangeTheme(
|
|
167
152
|
(name, manager, forced) => {
|
|
168
|
-
const force = forced ||
|
|
153
|
+
const force = forced || (import_constants.isServer ? void 0 : keys?.current ? !0 : void 0) || props.deopt || void 0, shouldTryUpdate = force ?? !!(keys?.current || isNewTheme);
|
|
169
154
|
process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F538} onChange", {
|
|
170
155
|
id: themeManager.id,
|
|
171
156
|
force,
|
|
@@ -173,7 +158,7 @@ const activeThemeManagers = /* @__PURE__ */ new Set(), _uidToManager = /* @__PUR
|
|
|
173
158
|
props,
|
|
174
159
|
name,
|
|
175
160
|
keys
|
|
176
|
-
}), shouldTryUpdate && setThemeState((prev) => createState(prev,
|
|
161
|
+
}), shouldTryUpdate && setThemeState((prev) => createState(prev, !0));
|
|
177
162
|
},
|
|
178
163
|
themeManager.id
|
|
179
164
|
);
|
|
@@ -189,7 +174,7 @@ const activeThemeManagers = /* @__PURE__ */ new Set(), _uidToManager = /* @__PUR
|
|
|
189
174
|
props.name,
|
|
190
175
|
props.reset,
|
|
191
176
|
mounted
|
|
192
|
-
]), process.env.NODE_ENV === "development" && props.debug !== "profile" && import_react.
|
|
177
|
+
]), process.env.NODE_ENV === "development" && props.debug !== "profile" && (0, import_react.useEffect)(() => (globalThis.TamaguiThemeManagers ??= /* @__PURE__ */ new Set(), globalThis.TamaguiThemeManagers.add(themeManager), () => {
|
|
193
178
|
globalThis.TamaguiThemeManagers.delete(themeManager);
|
|
194
179
|
}), [themeManager])), import_constants.isWeb && isInversingOnMount)
|
|
195
180
|
return {
|
|
@@ -208,23 +193,32 @@ const activeThemeManagers = /* @__PURE__ */ new Set(), _uidToManager = /* @__PUR
|
|
|
208
193
|
inversed: !!props.inverse,
|
|
209
194
|
themeManager
|
|
210
195
|
};
|
|
211
|
-
function createState(prev, force = !1) {
|
|
212
|
-
if (prev &&
|
|
196
|
+
function createState(prev, force = !1, foundNextState) {
|
|
197
|
+
if (prev && !foundNextState && !keys?.current && !force)
|
|
213
198
|
return prev;
|
|
214
199
|
let themeManager2 = parentManager, state2;
|
|
215
200
|
if ((0, import_ThemeManager.getHasThemeUpdatingProps)(props)) {
|
|
216
|
-
const
|
|
201
|
+
const parentManagerProp = isRoot ? "root" : parentManager;
|
|
217
202
|
if (prev?.themeManager) {
|
|
218
203
|
themeManager2 = prev.themeManager;
|
|
219
|
-
const forceChange = force ||
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
204
|
+
const forceChange = force || shouldAlwaysUpdate || (keys?.current ? !0 : void 0);
|
|
205
|
+
let nextState = null;
|
|
206
|
+
if (foundNextState)
|
|
207
|
+
nextState = foundNextState;
|
|
208
|
+
else {
|
|
209
|
+
const next = themeManager2.getState(props, parentManager);
|
|
210
|
+
nextState = getShouldUpdateTheme(
|
|
211
|
+
props,
|
|
212
|
+
parentManager,
|
|
213
|
+
keys,
|
|
214
|
+
prev,
|
|
215
|
+
next,
|
|
216
|
+
forceChange
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
nextState ? (state2 = nextState, !prev.isNewTheme && !isRoot ? themeManager2 = new import_ThemeManager.ThemeManager(props, parentManagerProp) : themeManager2.updateState(nextState)) : prev.isNewTheme && parentManager && !nextState && (themeManager2 = parentManager);
|
|
226
220
|
} else
|
|
227
|
-
themeManager2 =
|
|
221
|
+
themeManager2 = new import_ThemeManager.ThemeManager(props, parentManagerProp), state2 = { ...themeManager2.state };
|
|
228
222
|
}
|
|
229
223
|
const isNewTheme2 = !!(themeManager2 !== parentManager || props.inverse);
|
|
230
224
|
isNewTheme2 && registerThemeManager(themeManager2);
|
|
@@ -233,9 +227,10 @@ const activeThemeManagers = /* @__PURE__ */ new Set(), _uidToManager = /* @__PUR
|
|
|
233
227
|
const response = {
|
|
234
228
|
themeManager: themeManager2,
|
|
235
229
|
isNewTheme: isNewTheme2,
|
|
236
|
-
mounted: mounted2
|
|
237
|
-
|
|
238
|
-
|
|
230
|
+
mounted: mounted2
|
|
231
|
+
};
|
|
232
|
+
props.inverse && (response.inversed = !0);
|
|
233
|
+
const shouldReturnPrev = prev && !force && // isEqualShallow uses the second arg as the keys so this should compare without state first...
|
|
239
234
|
(0, import_createShallowSetState.isEqualShallow)(prev, response) && // ... and then compare just the state, because we make a new state obj but is likely the same
|
|
240
235
|
(0, import_createShallowSetState.isEqualShallow)(prev.state, state2);
|
|
241
236
|
if (prev && shouldReturnPrev)
|