@tamagui/theme 2.7.7 → 3.0.0-beta.643.1
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/_mutateTheme.cjs +101 -116
- package/dist/cjs/_mutateTheme.native.cjs +118 -0
- package/dist/cjs/_mutateTheme.native.js +92 -109
- package/dist/cjs/_mutateTheme.native.js.map +1 -1
- package/dist/cjs/addTheme.cjs +20 -23
- package/dist/cjs/addTheme.native.cjs +34 -0
- package/dist/cjs/addTheme.native.js +20 -22
- package/dist/cjs/addTheme.native.js.map +1 -1
- package/dist/cjs/index.cjs +15 -18
- package/dist/cjs/index.native.cjs +31 -0
- package/dist/cjs/index.native.js +15 -17
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/replaceTheme.cjs +23 -29
- package/dist/cjs/replaceTheme.native.cjs +37 -0
- package/dist/cjs/replaceTheme.native.js +23 -28
- package/dist/cjs/replaceTheme.native.js.map +1 -1
- package/dist/cjs/updateTheme.cjs +22 -28
- package/dist/cjs/updateTheme.native.cjs +36 -0
- package/dist/cjs/updateTheme.native.js +22 -27
- package/dist/cjs/updateTheme.native.js.map +1 -1
- package/dist/esm/_mutateTheme.mjs +88 -100
- package/dist/esm/_mutateTheme.mjs.map +1 -1
- package/dist/esm/_mutateTheme.native.js +78 -93
- package/dist/esm/_mutateTheme.native.js.map +1 -1
- package/dist/esm/addTheme.mjs +7 -5
- package/dist/esm/addTheme.mjs.map +1 -1
- package/dist/esm/addTheme.native.js +7 -5
- package/dist/esm/addTheme.native.js.map +1 -1
- package/dist/esm/index.js +8 -5
- package/dist/esm/index.mjs +8 -5
- package/dist/esm/index.native.js +8 -5
- package/dist/esm/replaceTheme.mjs +10 -11
- package/dist/esm/replaceTheme.mjs.map +1 -1
- package/dist/esm/replaceTheme.native.js +10 -11
- package/dist/esm/replaceTheme.native.js.map +1 -1
- package/dist/esm/updateTheme.mjs +9 -10
- package/dist/esm/updateTheme.mjs.map +1 -1
- package/dist/esm/updateTheme.native.js +9 -10
- package/dist/esm/updateTheme.native.js.map +1 -1
- package/package.json +5 -5
- package/src/_mutateTheme.ts +5 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
|
@@ -1,141 +1,126 @@
|
|
|
1
|
+
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
6
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
10
11
|
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
19
20
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
22
|
var mutateTheme_exports = {};
|
|
24
23
|
__export(mutateTheme_exports, {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
_mutateTheme: () => _mutateTheme,
|
|
25
|
+
mutateThemes: () => mutateThemes
|
|
27
26
|
});
|
|
28
27
|
module.exports = __toCommonJS(mutateTheme_exports);
|
|
29
28
|
var import_constants = require("@tamagui/constants");
|
|
30
29
|
var import_start_transition = require("@tamagui/start-transition");
|
|
31
30
|
var import_web = require("@tamagui/web");
|
|
32
|
-
function mutateThemes({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
updateThemeStates();
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
themes: allThemesProxied,
|
|
66
|
-
themesRaw: allThemesRaw,
|
|
67
|
-
cssRules
|
|
68
|
-
};
|
|
31
|
+
function mutateThemes({ themes, batch, insertCSS = true, ...props }) {
|
|
32
|
+
const allThemesProxied = {};
|
|
33
|
+
const allThemesRaw = {};
|
|
34
|
+
for (const { name, theme } of themes) {
|
|
35
|
+
const res = _mutateTheme({
|
|
36
|
+
...props,
|
|
37
|
+
name,
|
|
38
|
+
theme,
|
|
39
|
+
avoidUpdate: true,
|
|
40
|
+
mutationType: "add"
|
|
41
|
+
});
|
|
42
|
+
if (res) {
|
|
43
|
+
allThemesProxied[name] = res.theme;
|
|
44
|
+
allThemesRaw[name] = res.themeRaw;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
48
|
+
(0, import_start_transition.startTransition)(() => {
|
|
49
|
+
for (const themeName in allThemesProxied) {
|
|
50
|
+
const theme = allThemesProxied[themeName];
|
|
51
|
+
updateThemeConfig(themeName, theme);
|
|
52
|
+
}
|
|
53
|
+
updateThemeStates();
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
themes: allThemesProxied,
|
|
57
|
+
themesRaw: allThemesRaw,
|
|
58
|
+
cssRules
|
|
59
|
+
};
|
|
69
60
|
}
|
|
70
61
|
function _mutateTheme(props) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (props.avoidUpdate) return response;
|
|
99
|
-
if (insertCSS) response.cssRules = insertThemeCSS({
|
|
100
|
-
[themeName]: theme
|
|
101
|
-
});
|
|
102
|
-
updateThemeConfig(themeName, themeProxied);
|
|
103
|
-
updateThemeStates();
|
|
104
|
-
return response;
|
|
62
|
+
if (import_constants.isServer) {
|
|
63
|
+
if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const config = (0, import_web.getConfig)();
|
|
67
|
+
const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
68
|
+
if (process.env.NODE_ENV === "development") {
|
|
69
|
+
if (!config) throw new Error("No config");
|
|
70
|
+
const theme2 = config.themes[props.name];
|
|
71
|
+
if (mutationType !== "add" && !theme2) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
|
|
72
|
+
}
|
|
73
|
+
const theme = {
|
|
74
|
+
...mutationType === "update" ? config.themes[themeName] ?? {} : {},
|
|
75
|
+
...themeIn
|
|
76
|
+
};
|
|
77
|
+
for (const key in theme) (0, import_web.ensureThemeVariable)(theme, key);
|
|
78
|
+
const themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme);
|
|
79
|
+
const response = {
|
|
80
|
+
themeRaw: theme,
|
|
81
|
+
theme: themeProxied,
|
|
82
|
+
cssRules: []
|
|
83
|
+
};
|
|
84
|
+
if (props.avoidUpdate) return response;
|
|
85
|
+
if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme });
|
|
86
|
+
updateThemeConfig(themeName, themeProxied);
|
|
87
|
+
updateThemeStates();
|
|
88
|
+
return response;
|
|
105
89
|
}
|
|
106
90
|
function updateThemeConfig(themeName, theme) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
const config = (0, import_web.getConfig)();
|
|
92
|
+
config.themes[themeName] = theme;
|
|
93
|
+
(0, import_web.updateConfig)("themes", config.themes);
|
|
110
94
|
}
|
|
111
95
|
function updateThemeStates() {
|
|
112
|
-
|
|
96
|
+
(0, import_web.forceUpdateThemes)();
|
|
113
97
|
}
|
|
114
98
|
function insertThemeCSS(themes, batch = false) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
99
|
+
const config = (0, import_web.getConfig)();
|
|
100
|
+
let cssRules = [];
|
|
101
|
+
for (const themeName in themes) {
|
|
102
|
+
const theme = themes[themeName];
|
|
103
|
+
const rules = (0, import_web.getThemeCSSRules)({
|
|
104
|
+
config,
|
|
105
|
+
themeName,
|
|
106
|
+
names: [themeName],
|
|
107
|
+
hasDarkLight: true,
|
|
108
|
+
theme,
|
|
109
|
+
useMutatedVariables: true
|
|
110
|
+
});
|
|
111
|
+
cssRules = [...cssRules, ...rules];
|
|
112
|
+
if (!batch) updateStyle(`t_theme_style_${themeName}`, rules);
|
|
113
|
+
}
|
|
114
|
+
const mutatedAutoVariableCSS = (0, import_web.getMutatedAutoVariableCSS)();
|
|
115
|
+
if (mutatedAutoVariableCSS) updateStyle(`t_mutate_vars`, [`:root{${mutatedAutoVariableCSS}}`]);
|
|
116
|
+
if (batch) updateStyle(`t_theme_style_${typeof batch == "string" ? batch : (0, import_web.simpleHash)(Object.keys(themes).join(""))}`, cssRules);
|
|
117
|
+
return cssRules;
|
|
133
118
|
}
|
|
134
119
|
function updateStyle(id, rules) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
120
|
+
const existing = document.querySelector(`#${id}`);
|
|
121
|
+
const style = document.createElement("style");
|
|
122
|
+
style.id = id;
|
|
123
|
+
style.appendChild(document.createTextNode(rules.join("\n")));
|
|
124
|
+
document.head.appendChild(style);
|
|
125
|
+
if (existing) existing.parentElement?.removeChild(existing);
|
|
126
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var mutateTheme_exports = {};
|
|
25
|
+
__export(mutateTheme_exports, {
|
|
26
|
+
_mutateTheme: () => _mutateTheme,
|
|
27
|
+
mutateThemes: () => mutateThemes
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(mutateTheme_exports);
|
|
30
|
+
var import_constants = require("@tamagui/constants");
|
|
31
|
+
var import_start_transition = require("@tamagui/start-transition");
|
|
32
|
+
var import_web = require("@tamagui/web");
|
|
33
|
+
function mutateThemes(param) {
|
|
34
|
+
var { themes, batch, insertCSS = true, ...props } = param;
|
|
35
|
+
var allThemesProxied = {};
|
|
36
|
+
var allThemesRaw = {};
|
|
37
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
38
|
+
try {
|
|
39
|
+
for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
40
|
+
var { name, theme } = _step.value;
|
|
41
|
+
var res = _mutateTheme({
|
|
42
|
+
...props,
|
|
43
|
+
name,
|
|
44
|
+
theme,
|
|
45
|
+
avoidUpdate: true,
|
|
46
|
+
mutationType: "add"
|
|
47
|
+
});
|
|
48
|
+
if (res) {
|
|
49
|
+
allThemesProxied[name] = res.theme;
|
|
50
|
+
allThemesRaw[name] = res.themeRaw;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_didIteratorError = true;
|
|
55
|
+
_iteratorError = err;
|
|
56
|
+
} finally {
|
|
57
|
+
try {
|
|
58
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
59
|
+
} finally {
|
|
60
|
+
if (_didIteratorError) throw _iteratorError;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
64
|
+
(0, import_start_transition.startTransition)(function() {
|
|
65
|
+
for (var themeName in allThemesProxied) {
|
|
66
|
+
var theme2 = allThemesProxied[themeName];
|
|
67
|
+
updateThemeConfig(themeName, theme2);
|
|
68
|
+
}
|
|
69
|
+
updateThemeStates();
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
themes: allThemesProxied,
|
|
73
|
+
themesRaw: allThemesRaw,
|
|
74
|
+
cssRules
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function _mutateTheme(props) {
|
|
78
|
+
if (import_constants.isServer) {
|
|
79
|
+
if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var config = (0, import_web.getConfig)();
|
|
83
|
+
var { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
84
|
+
if (process.env.NODE_ENV === "development") {
|
|
85
|
+
if (!config) throw new Error("No config");
|
|
86
|
+
var theme = config.themes[props.name];
|
|
87
|
+
if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
|
|
88
|
+
}
|
|
89
|
+
var _config_themes_themeName;
|
|
90
|
+
var theme1 = {
|
|
91
|
+
...mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {},
|
|
92
|
+
...themeIn
|
|
93
|
+
};
|
|
94
|
+
for (var key in theme1) (0, import_web.ensureThemeVariable)(theme1, key);
|
|
95
|
+
var themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme1);
|
|
96
|
+
var response = {
|
|
97
|
+
themeRaw: theme1,
|
|
98
|
+
theme: themeProxied,
|
|
99
|
+
cssRules: []
|
|
100
|
+
};
|
|
101
|
+
if (props.avoidUpdate) return response;
|
|
102
|
+
if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme1 });
|
|
103
|
+
updateThemeConfig(themeName, themeProxied);
|
|
104
|
+
updateThemeStates();
|
|
105
|
+
return response;
|
|
106
|
+
}
|
|
107
|
+
function updateThemeConfig(themeName, theme) {
|
|
108
|
+
var config = (0, import_web.getConfig)();
|
|
109
|
+
config.themes[themeName] = theme;
|
|
110
|
+
(0, import_web.updateConfig)("themes", config.themes);
|
|
111
|
+
}
|
|
112
|
+
function updateThemeStates() {
|
|
113
|
+
(0, import_web.forceUpdateThemes)();
|
|
114
|
+
}
|
|
115
|
+
function insertThemeCSS(themes) {
|
|
116
|
+
arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
@@ -1,137 +1,120 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
24
|
var mutateTheme_exports = {};
|
|
26
25
|
__export(mutateTheme_exports, {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
_mutateTheme: () => _mutateTheme,
|
|
27
|
+
mutateThemes: () => mutateThemes
|
|
29
28
|
});
|
|
30
29
|
module.exports = __toCommonJS(mutateTheme_exports);
|
|
31
30
|
var import_constants = require("@tamagui/constants");
|
|
32
31
|
var import_start_transition = require("@tamagui/start-transition");
|
|
33
32
|
var import_web = require("@tamagui/web");
|
|
34
33
|
function mutateThemes(param) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var theme2 = allThemesProxied[themeName];
|
|
78
|
-
updateThemeConfig(themeName, theme2);
|
|
79
|
-
}
|
|
80
|
-
updateThemeStates();
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
themes: allThemesProxied,
|
|
84
|
-
themesRaw: allThemesRaw,
|
|
85
|
-
cssRules
|
|
86
|
-
};
|
|
34
|
+
var { themes, batch, insertCSS = true, ...props } = param;
|
|
35
|
+
var allThemesProxied = {};
|
|
36
|
+
var allThemesRaw = {};
|
|
37
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
38
|
+
try {
|
|
39
|
+
for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
40
|
+
var { name, theme } = _step.value;
|
|
41
|
+
var res = _mutateTheme({
|
|
42
|
+
...props,
|
|
43
|
+
name,
|
|
44
|
+
theme,
|
|
45
|
+
avoidUpdate: true,
|
|
46
|
+
mutationType: "add"
|
|
47
|
+
});
|
|
48
|
+
if (res) {
|
|
49
|
+
allThemesProxied[name] = res.theme;
|
|
50
|
+
allThemesRaw[name] = res.themeRaw;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_didIteratorError = true;
|
|
55
|
+
_iteratorError = err;
|
|
56
|
+
} finally {
|
|
57
|
+
try {
|
|
58
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
59
|
+
} finally {
|
|
60
|
+
if (_didIteratorError) throw _iteratorError;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
64
|
+
(0, import_start_transition.startTransition)(function() {
|
|
65
|
+
for (var themeName in allThemesProxied) {
|
|
66
|
+
var theme2 = allThemesProxied[themeName];
|
|
67
|
+
updateThemeConfig(themeName, theme2);
|
|
68
|
+
}
|
|
69
|
+
updateThemeStates();
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
themes: allThemesProxied,
|
|
73
|
+
themesRaw: allThemesRaw,
|
|
74
|
+
cssRules
|
|
75
|
+
};
|
|
87
76
|
}
|
|
88
77
|
function _mutateTheme(props) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (props.avoidUpdate) return response;
|
|
118
|
-
if (insertCSS) response.cssRules = insertThemeCSS({
|
|
119
|
-
[themeName]: theme1
|
|
120
|
-
});
|
|
121
|
-
updateThemeConfig(themeName, themeProxied);
|
|
122
|
-
updateThemeStates();
|
|
123
|
-
return response;
|
|
78
|
+
if (import_constants.isServer) {
|
|
79
|
+
if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var config = (0, import_web.getConfig)();
|
|
83
|
+
var { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
84
|
+
if (process.env.NODE_ENV === "development") {
|
|
85
|
+
if (!config) throw new Error("No config");
|
|
86
|
+
var theme = config.themes[props.name];
|
|
87
|
+
if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
|
|
88
|
+
}
|
|
89
|
+
var _config_themes_themeName;
|
|
90
|
+
var theme1 = {
|
|
91
|
+
...mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {},
|
|
92
|
+
...themeIn
|
|
93
|
+
};
|
|
94
|
+
for (var key in theme1) (0, import_web.ensureThemeVariable)(theme1, key);
|
|
95
|
+
var themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme1);
|
|
96
|
+
var response = {
|
|
97
|
+
themeRaw: theme1,
|
|
98
|
+
theme: themeProxied,
|
|
99
|
+
cssRules: []
|
|
100
|
+
};
|
|
101
|
+
if (props.avoidUpdate) return response;
|
|
102
|
+
if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme1 });
|
|
103
|
+
updateThemeConfig(themeName, themeProxied);
|
|
104
|
+
updateThemeStates();
|
|
105
|
+
return response;
|
|
124
106
|
}
|
|
125
107
|
function updateThemeConfig(themeName, theme) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
108
|
+
var config = (0, import_web.getConfig)();
|
|
109
|
+
config.themes[themeName] = theme;
|
|
110
|
+
(0, import_web.updateConfig)("themes", config.themes);
|
|
129
111
|
}
|
|
130
112
|
function updateThemeStates() {
|
|
131
|
-
|
|
113
|
+
(0, import_web.forceUpdateThemes)();
|
|
132
114
|
}
|
|
133
115
|
function insertThemeCSS(themes) {
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
|
|
117
|
+
return [];
|
|
136
118
|
}
|
|
119
|
+
|
|
137
120
|
//# sourceMappingURL=_mutateTheme.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"_mutateTheme.native.js","names":[],"sources":["cjs/_mutateTheme.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n\tfor (var name in all) __defProp(target, name, {\n\t\tget: all[name],\n\t\tenumerable: true\n\t});\n};\nvar __copyProps = (to, from, except, desc) => {\n\tif (from && typeof from === \"object\" || typeof from === \"function\") {\n\t\tfor (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {\n\t\t\tget: () => from[key],\n\t\t\tenumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable\n\t\t});\n\t}\n\treturn to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar mutateTheme_exports = {};\n__export(mutateTheme_exports, {\n\t_mutateTheme: () => _mutateTheme,\n\tmutateThemes: () => mutateThemes\n});\nmodule.exports = __toCommonJS(mutateTheme_exports);\nvar import_constants = require(\"@tamagui/constants\");\nvar import_start_transition = require(\"@tamagui/start-transition\");\nvar import_web = require(\"@tamagui/web\");\nfunction mutateThemes(param) {\n\tvar { themes, batch, insertCSS = true, ...props } = param;\n\tvar allThemesProxied = {};\n\tvar allThemesRaw = {};\n\tvar _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n\ttry {\n\t\tfor (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n\t\t\tvar { name, theme } = _step.value;\n\t\t\tvar res = _mutateTheme({\n\t\t\t\t...props,\n\t\t\t\tname,\n\t\t\t\ttheme,\n\t\t\t\tavoidUpdate: true,\n\t\t\t\tmutationType: \"add\"\n\t\t\t});\n\t\t\tif (res) {\n\t\t\t\tallThemesProxied[name] = res.theme;\n\t\t\t\tallThemesRaw[name] = res.themeRaw;\n\t\t\t}\n\t\t}\n\t} catch (err) {\n\t\t_didIteratorError = true;\n\t\t_iteratorError = err;\n\t} finally {\n\t\ttry {\n\t\t\tif (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();\n\t\t} finally {\n\t\t\tif (_didIteratorError) throw _iteratorError;\n\t\t}\n\t}\n\tvar cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];\n\t(0, import_start_transition.startTransition)(function() {\n\t\tfor (var themeName in allThemesProxied) {\n\t\t\tvar theme2 = allThemesProxied[themeName];\n\t\t\tupdateThemeConfig(themeName, theme2);\n\t\t}\n\t\tupdateThemeStates();\n\t});\n\treturn {\n\t\tthemes: allThemesProxied,\n\t\tthemesRaw: allThemesRaw,\n\t\tcssRules\n\t};\n}\nfunction _mutateTheme(props) {\n\tif (import_constants.isServer) {\n\t\tif (process.env.NODE_ENV === \"development\") console.warn(\"Theme mutation is not supported on server side\");\n\t\treturn;\n\t}\n\tvar config = (0, import_web.getConfig)();\n\tvar { name: themeName, theme: themeIn, insertCSS, mutationType } = props;\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tif (!config) throw new Error(\"No config\");\n\t\tvar theme = config.themes[props.name];\n\t\tif (mutationType !== \"add\" && !theme) throw new Error(`${mutationType === \"replace\" ? \"Replace\" : \"Update\"} theme failed! Theme ${props.name} does not exist`);\n\t}\n\tvar _config_themes_themeName;\n\tvar theme1 = {\n\t\t...mutationType === \"update\" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {},\n\t\t...themeIn\n\t};\n\tfor (var key in theme1) (0, import_web.ensureThemeVariable)(theme1, key);\n\tvar themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme1);\n\tvar response = {\n\t\tthemeRaw: theme1,\n\t\ttheme: themeProxied,\n\t\tcssRules: []\n\t};\n\tif (props.avoidUpdate) return response;\n\tif (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme1 });\n\tupdateThemeConfig(themeName, themeProxied);\n\tupdateThemeStates();\n\treturn response;\n}\nfunction updateThemeConfig(themeName, theme) {\n\tvar config = (0, import_web.getConfig)();\n\tconfig.themes[themeName] = theme;\n\t(0, import_web.updateConfig)(\"themes\", config.themes);\n}\nfunction updateThemeStates() {\n\t(0, import_web.forceUpdateThemes)();\n}\nfunction insertThemeCSS(themes) {\n\targuments.length > 1 && arguments[1] !== void 0 && arguments[1];\n\treturn [];\n}\n//# sourceMappingURL=_mutateTheme.js.map\n"],"mappings":";;;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC/B,KAAK,IAAI,QAAQ,KA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