@tamagui/theme 2.7.7 → 3.0.0-beta.1097.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 +96 -116
- package/dist/cjs/_mutateTheme.native.cjs +113 -0
- package/dist/cjs/_mutateTheme.native.js +87 -109
- package/dist/cjs/_mutateTheme.native.js.map +1 -1
- package/dist/cjs/addTheme.cjs +19 -23
- package/dist/cjs/addTheme.native.cjs +33 -0
- package/dist/cjs/addTheme.native.js +19 -22
- package/dist/cjs/addTheme.native.js.map +1 -1
- package/dist/cjs/index.cjs +14 -18
- package/dist/cjs/index.native.cjs +30 -0
- package/dist/cjs/index.native.js +14 -17
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/replaceTheme.cjs +22 -29
- package/dist/cjs/replaceTheme.native.cjs +36 -0
- package/dist/cjs/replaceTheme.native.js +22 -28
- package/dist/cjs/replaceTheme.native.js.map +1 -1
- package/dist/cjs/updateTheme.cjs +21 -28
- package/dist/cjs/updateTheme.native.cjs +35 -0
- package/dist/cjs/updateTheme.native.js +21 -27
- package/dist/cjs/updateTheme.native.js.map +1 -1
- package/dist/esm/_mutateTheme.mjs +84 -100
- package/dist/esm/_mutateTheme.mjs.map +1 -1
- package/dist/esm/_mutateTheme.native.js +75 -94
- 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 +7 -6
- package/src/_mutateTheme.ts +17 -15
- package/types/_mutateTheme.d.ts +1 -1
- package/types/_mutateTheme.d.ts.map +1 -1
- package/types/addTheme.d.ts +1 -1
- package/types/replaceTheme.d.ts +1 -1
- package/types/updateTheme.d.ts +1 -1
- 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,115 +1,99 @@
|
|
|
1
1
|
import { isServer } from "@tamagui/constants";
|
|
2
2
|
import { startTransition } from "@tamagui/start-transition";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
updateThemeConfig(themeName, theme);
|
|
33
|
-
}
|
|
34
|
-
updateThemeStates();
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
themes: allThemesProxied,
|
|
38
|
-
themesRaw: allThemesRaw,
|
|
39
|
-
cssRules
|
|
40
|
-
};
|
|
3
|
+
import { forceUpdateThemes, getConfig, getMutatedAutoVariableCSS, simpleHash, updateConfig } from "@tamagui/web";
|
|
4
|
+
import { ensureThemeVariable, getThemeCSSRules, proxyThemeToParents } from "@tamagui/web/internal-runtime";
|
|
5
|
+
|
|
6
|
+
function mutateThemes({ themes, batch, insertCSS = true, ...props }) {
|
|
7
|
+
const allThemesProxied = {};
|
|
8
|
+
const allThemesRaw = {};
|
|
9
|
+
for (const { name, theme } of themes) {
|
|
10
|
+
const res = _mutateTheme({
|
|
11
|
+
...props,
|
|
12
|
+
name,
|
|
13
|
+
theme,
|
|
14
|
+
avoidUpdate: true,
|
|
15
|
+
mutationType: "add"
|
|
16
|
+
});
|
|
17
|
+
if (res) {
|
|
18
|
+
allThemesProxied[name] = res.theme;
|
|
19
|
+
allThemesRaw[name] = res.themeRaw;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
23
|
+
startTransition(() => {
|
|
24
|
+
updateConfig("themes", allThemesProxied);
|
|
25
|
+
updateThemeStates();
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
themes: allThemesProxied,
|
|
29
|
+
themesRaw: allThemesRaw,
|
|
30
|
+
cssRules
|
|
31
|
+
};
|
|
41
32
|
}
|
|
42
33
|
function _mutateTheme(props) {
|
|
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
|
-
if (props.avoidUpdate) return response;
|
|
71
|
-
if (insertCSS) response.cssRules = insertThemeCSS({
|
|
72
|
-
[themeName]: theme
|
|
73
|
-
});
|
|
74
|
-
updateThemeConfig(themeName, themeProxied);
|
|
75
|
-
updateThemeStates();
|
|
76
|
-
return response;
|
|
34
|
+
if (isServer) {
|
|
35
|
+
if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const config = getConfig();
|
|
39
|
+
const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
40
|
+
if (process.env.NODE_ENV === "development") {
|
|
41
|
+
if (!config) throw new Error("No config");
|
|
42
|
+
const theme2 = config.themes[props.name];
|
|
43
|
+
if (mutationType !== "add" && !theme2) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
|
|
44
|
+
}
|
|
45
|
+
const theme = {
|
|
46
|
+
...mutationType === "update" ? config.themes[themeName] ?? {} : {},
|
|
47
|
+
...themeIn
|
|
48
|
+
};
|
|
49
|
+
for (const key in theme) ensureThemeVariable(theme, key);
|
|
50
|
+
const themeProxied = proxyThemeToParents(themeName, theme);
|
|
51
|
+
const response = {
|
|
52
|
+
themeRaw: theme,
|
|
53
|
+
theme: themeProxied,
|
|
54
|
+
cssRules: []
|
|
55
|
+
};
|
|
56
|
+
if (props.avoidUpdate) return response;
|
|
57
|
+
if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme });
|
|
58
|
+
updateThemeConfig(themeName, themeProxied);
|
|
59
|
+
updateThemeStates();
|
|
60
|
+
return response;
|
|
77
61
|
}
|
|
78
62
|
function updateThemeConfig(themeName, theme) {
|
|
79
|
-
|
|
80
|
-
config.themes[themeName] = theme;
|
|
81
|
-
updateConfig("themes", config.themes);
|
|
63
|
+
updateConfig("themes", { [themeName]: theme });
|
|
82
64
|
}
|
|
83
65
|
function updateThemeStates() {
|
|
84
|
-
|
|
66
|
+
forceUpdateThemes();
|
|
85
67
|
}
|
|
86
68
|
function insertThemeCSS(themes, batch = false) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
69
|
+
const config = getConfig();
|
|
70
|
+
let cssRules = [];
|
|
71
|
+
for (const themeName in themes) {
|
|
72
|
+
const theme = themes[themeName];
|
|
73
|
+
const rules = getThemeCSSRules({
|
|
74
|
+
config,
|
|
75
|
+
themeName,
|
|
76
|
+
names: [themeName],
|
|
77
|
+
hasDarkLight: true,
|
|
78
|
+
theme,
|
|
79
|
+
useMutatedVariables: true
|
|
80
|
+
});
|
|
81
|
+
cssRules = [...cssRules, ...rules];
|
|
82
|
+
if (!batch) updateStyle(`t_theme_style_${themeName}`, rules);
|
|
83
|
+
}
|
|
84
|
+
const mutatedAutoVariableCSS = getMutatedAutoVariableCSS();
|
|
85
|
+
if (mutatedAutoVariableCSS) updateStyle(`t_mutate_vars`, [`:root{${mutatedAutoVariableCSS}}`]);
|
|
86
|
+
if (batch) updateStyle(`t_theme_style_${typeof batch == "string" ? batch : simpleHash(Object.keys(themes).join(""))}`, cssRules);
|
|
87
|
+
return cssRules;
|
|
105
88
|
}
|
|
106
89
|
function updateStyle(id, rules) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
90
|
+
const existing = document.querySelector(`#${id}`);
|
|
91
|
+
const style = document.createElement("style");
|
|
92
|
+
style.id = id;
|
|
93
|
+
style.appendChild(document.createTextNode(rules.join("\n")));
|
|
94
|
+
document.head.appendChild(style);
|
|
95
|
+
if (existing) existing.parentElement?.removeChild(existing);
|
|
113
96
|
}
|
|
97
|
+
|
|
114
98
|
export { _mutateTheme, mutateThemes };
|
|
115
99
|
//# sourceMappingURL=_mutateTheme.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"_mutateTheme.js","names":[],"sources":["esm/_mutateTheme.js"],"sourcesContent":["import { isServer } from \"@tamagui/constants\";\nimport { startTransition } from \"@tamagui/start-transition\";\nimport { forceUpdateThemes, getConfig, getMutatedAutoVariableCSS, simpleHash, updateConfig } from \"@tamagui/web\";\nimport { ensureThemeVariable, getThemeCSSRules, proxyThemeToParents } from \"@tamagui/web/internal-runtime\";\n\nfunction mutateThemes({ themes, batch, insertCSS = true, ...props }) {\n\tconst allThemesProxied = {};\n\tconst allThemesRaw = {};\n\tfor (const { name, theme } of themes) {\n\t\tconst res = _mutateTheme({\n\t\t\t...props,\n\t\t\tname,\n\t\t\ttheme,\n\t\t\tavoidUpdate: true,\n\t\t\tmutationType: \"add\"\n\t\t});\n\t\tif (res) {\n\t\t\tallThemesProxied[name] = res.theme;\n\t\t\tallThemesRaw[name] = res.themeRaw;\n\t\t}\n\t}\n\tconst cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];\n\tstartTransition(() => {\n\t\tupdateConfig(\"themes\", allThemesProxied);\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 (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\tconst config = getConfig();\n\tconst { 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\tconst theme2 = config.themes[props.name];\n\t\tif (mutationType !== \"add\" && !theme2) throw new Error(`${mutationType === \"replace\" ? \"Replace\" : \"Update\"} theme failed! Theme ${props.name} does not exist`);\n\t}\n\tconst theme = {\n\t\t...mutationType === \"update\" ? config.themes[themeName] ?? {} : {},\n\t\t...themeIn\n\t};\n\tfor (const key in theme) ensureThemeVariable(theme, key);\n\tconst themeProxied = proxyThemeToParents(themeName, theme);\n\tconst response = {\n\t\tthemeRaw: theme,\n\t\ttheme: themeProxied,\n\t\tcssRules: []\n\t};\n\tif (props.avoidUpdate) return response;\n\tif (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme });\n\tupdateThemeConfig(themeName, themeProxied);\n\tupdateThemeStates();\n\treturn response;\n}\nfunction updateThemeConfig(themeName, theme) {\n\tupdateConfig(\"themes\", { [themeName]: theme });\n}\nfunction updateThemeStates() {\n\tforceUpdateThemes();\n}\nfunction insertThemeCSS(themes, batch = false) {\n\tconst config = getConfig();\n\tlet cssRules = [];\n\tfor (const themeName in themes) {\n\t\tconst theme = themes[themeName];\n\t\tconst rules = getThemeCSSRules({\n\t\t\tconfig,\n\t\t\tthemeName,\n\t\t\tnames: [themeName],\n\t\t\thasDarkLight: true,\n\t\t\ttheme,\n\t\t\tuseMutatedVariables: true\n\t\t});\n\t\tcssRules = [...cssRules, ...rules];\n\t\tif (!batch) updateStyle(`t_theme_style_${themeName}`, rules);\n\t}\n\tconst mutatedAutoVariableCSS = getMutatedAutoVariableCSS();\n\tif (mutatedAutoVariableCSS) updateStyle(`t_mutate_vars`, [`:root{${mutatedAutoVariableCSS}}`]);\n\tif (batch) updateStyle(`t_theme_style_${typeof batch == \"string\" ? batch : simpleHash(Object.keys(themes).join(\"\"))}`, cssRules);\n\treturn cssRules;\n}\nfunction updateStyle(id, rules) {\n\tconst existing = document.querySelector(`#${id}`);\n\tconst style = document.createElement(\"style\");\n\tstyle.id = id;\n\tstyle.appendChild(document.createTextNode(rules.join(\"\\n\")));\n\tdocument.head.appendChild(style);\n\tif (existing) existing.parentElement?.removeChild(existing);\n}\n\nexport { _mutateTheme, mutateThemes };"],"mappings":";;;;;;AAKA,SAAS,aAAa,EAAE,QAAQ,OAAO,YAAY,MAAM,GAAG,SAAS;CACpE,MAAM,mBAAmB,CAAC;CAC1B,MAAM,eAAe,CAAC;CACtB,KAAK,MAAM,EAAE,MAAM,WAAW,QAAQ;EACrC,MAAM,MAAM,aAAa;GACxB,GAAG;GACH;GACA;GACA,aAAa;GACb,cAAc;EACf,CAAC;EACD,IAAI,KAAK;GACR,iBAAiB,QAAQ,IAAI;GAC7B,aAAa,QAAQ,IAAI;EAC1B;CACD;CACA,MAAM,WAAW,YAAY,eAAe,cAAc,KAAK,IAAI,CAAC;CACpE,sBAA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AiB;GAC9B;GACA;GACA,OAAO,CAAC,SAAS;GACjB,cAAc;GACd;GACA,qBAAqB;EACtB,CAAC;EACD,WAAW,CAAC,GAAG,UAAU,GAAG,KAAK;EACjC,IAAI,CAAC,OAAO,YAAY,iBAAiB,aAAa,KAAK;CAC5D;CACA,MAAM,yBAAyB,0BAA0B;CACzD,IAAI,wBAAwB,YAAY,iBAAiB,CAAC,SAAS,uBAAuB,EAAE,CAAC;CAC7F,IAAI,OAAO,YAAY,iBAAiB,OAAO,SAAS,WAAW,QAAQ,WAAW,OAAO,KAAK,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ;CAC/H,OAAO;AACR;AACA,SAAS,YAAY,IAAI,OAAO;CAC/B,MAAM,WAAW,SAAS,cAAc,IAAI,IAAI;CAChD,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,KAAK;CACX,MAAM,YAAY,SAAS,eAAe,MAAM,KAAK,IAAI,CAAC,CAAC;CAC3D,SAAS,KAAK,YAAY,KAAK;CAC/B,IAAI,UAAU,SAAS,eAAe,YAAY,QAAQ;AAC3D"}
|
|
@@ -1,108 +1,89 @@
|
|
|
1
1
|
import { isServer } from "@tamagui/constants";
|
|
2
2
|
import { startTransition } from "@tamagui/start-transition";
|
|
3
|
-
import {
|
|
3
|
+
import { forceUpdateThemes, getConfig, updateConfig } from "@tamagui/web";
|
|
4
|
+
import { ensureThemeVariable, proxyThemeToParents } from "@tamagui/web/internal-runtime";
|
|
5
|
+
|
|
4
6
|
function mutateThemes(param) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
45
|
-
startTransition(function () {
|
|
46
|
-
for (var themeName in allThemesProxied) {
|
|
47
|
-
var theme2 = allThemesProxied[themeName];
|
|
48
|
-
updateThemeConfig(themeName, theme2);
|
|
49
|
-
}
|
|
50
|
-
updateThemeStates();
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
themes: allThemesProxied,
|
|
54
|
-
themesRaw: allThemesRaw,
|
|
55
|
-
cssRules
|
|
56
|
-
};
|
|
7
|
+
var { themes, batch, insertCSS = true, ...props } = param;
|
|
8
|
+
var allThemesProxied = {};
|
|
9
|
+
var allThemesRaw = {};
|
|
10
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
11
|
+
try {
|
|
12
|
+
for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
13
|
+
var { name, theme } = _step.value;
|
|
14
|
+
var res = _mutateTheme({
|
|
15
|
+
...props,
|
|
16
|
+
name,
|
|
17
|
+
theme,
|
|
18
|
+
avoidUpdate: true,
|
|
19
|
+
mutationType: "add"
|
|
20
|
+
});
|
|
21
|
+
if (res) {
|
|
22
|
+
allThemesProxied[name] = res.theme;
|
|
23
|
+
allThemesRaw[name] = res.themeRaw;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} catch (err) {
|
|
27
|
+
_didIteratorError = true;
|
|
28
|
+
_iteratorError = err;
|
|
29
|
+
} finally {
|
|
30
|
+
try {
|
|
31
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
32
|
+
} finally {
|
|
33
|
+
if (_didIteratorError) throw _iteratorError;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
37
|
+
startTransition(function() {
|
|
38
|
+
updateConfig("themes", allThemesProxied);
|
|
39
|
+
updateThemeStates();
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
themes: allThemesProxied,
|
|
43
|
+
themesRaw: allThemesRaw,
|
|
44
|
+
cssRules
|
|
45
|
+
};
|
|
57
46
|
}
|
|
58
47
|
function _mutateTheme(props) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (props.avoidUpdate) return response;
|
|
88
|
-
if (insertCSS) response.cssRules = insertThemeCSS({
|
|
89
|
-
[themeName]: theme1
|
|
90
|
-
});
|
|
91
|
-
updateThemeConfig(themeName, themeProxied);
|
|
92
|
-
updateThemeStates();
|
|
93
|
-
return response;
|
|
48
|
+
if (isServer) {
|
|
49
|
+
if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
var config = getConfig();
|
|
53
|
+
var { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
54
|
+
if (process.env.NODE_ENV === "development") {
|
|
55
|
+
if (!config) throw new Error("No config");
|
|
56
|
+
var theme = config.themes[props.name];
|
|
57
|
+
if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
|
|
58
|
+
}
|
|
59
|
+
var _config_themes_themeName;
|
|
60
|
+
var theme1 = {
|
|
61
|
+
...mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {},
|
|
62
|
+
...themeIn
|
|
63
|
+
};
|
|
64
|
+
for (var key in theme1) ensureThemeVariable(theme1, key);
|
|
65
|
+
var themeProxied = proxyThemeToParents(themeName, theme1);
|
|
66
|
+
var response = {
|
|
67
|
+
themeRaw: theme1,
|
|
68
|
+
theme: themeProxied,
|
|
69
|
+
cssRules: []
|
|
70
|
+
};
|
|
71
|
+
if (props.avoidUpdate) return response;
|
|
72
|
+
if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme1 });
|
|
73
|
+
updateThemeConfig(themeName, themeProxied);
|
|
74
|
+
updateThemeStates();
|
|
75
|
+
return response;
|
|
94
76
|
}
|
|
95
77
|
function updateThemeConfig(themeName, theme) {
|
|
96
|
-
|
|
97
|
-
config.themes[themeName] = theme;
|
|
98
|
-
updateConfig("themes", config.themes);
|
|
78
|
+
updateConfig("themes", { [themeName]: theme });
|
|
99
79
|
}
|
|
100
80
|
function updateThemeStates() {
|
|
101
|
-
|
|
81
|
+
forceUpdateThemes();
|
|
102
82
|
}
|
|
103
83
|
function insertThemeCSS(themes) {
|
|
104
|
-
|
|
105
|
-
|
|
84
|
+
arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
|
|
85
|
+
return [];
|
|
106
86
|
}
|
|
87
|
+
|
|
107
88
|
export { _mutateTheme, mutateThemes };
|
|
108
89
|
//# sourceMappingURL=_mutateTheme.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"_mutateTheme.native.js","names":[],"sources":["esm/_mutateTheme.native.js"],"sourcesContent":["import { isServer } from \"@tamagui/constants\";\nimport { startTransition } from \"@tamagui/start-transition\";\nimport { forceUpdateThemes, getConfig, updateConfig } from \"@tamagui/web\";\nimport { ensureThemeVariable, proxyThemeToParents } from \"@tamagui/web/internal-runtime\";\n\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\tstartTransition(function() {\n\t\tupdateConfig(\"themes\", allThemesProxied);\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 (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 = 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) ensureThemeVariable(theme1, key);\n\tvar themeProxied = 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\tupdateConfig(\"themes\", { [themeName]: theme });\n}\nfunction updateThemeStates() {\n\tforceUpdateThemes();\n}\nfunction insertThemeCSS(themes) {\n\targuments.length > 1 && arguments[1] !== void 0 && arguments[1];\n\treturn [];\n}\n\nexport { _mutateTheme, mutateThemes };"],"mappings":";;;;;;AAKA,SAAS,aAAa,OAAO;CAC5B,IAAI,EAAE,QAAQ,OAAO,YAAY,MAAM,GAAG,UAAU;CACpD,IAAI,mBAAmB,CAAC;CACxB,IAAI,eAAe,CAAC;CACpB,IAAI,4BAA4B,MAAM,oBAAoB,OAAO,iBAAiB,KAAK;CACvF,IAAI;EACH,KAAK,IAAI,YAAY,OAAO,OAAO,SAAS,CAAC,GAAG,OAAO,EAAE,6BAA6B,QAAQ,UAAU,KAAK,EAAC,CAAE,OAAO,4BAA4B,MAAM;GACxJ,IAAI,EAAE,MAAM,UAAU,MAAM;GAC5B,IAAI,MAAM,aAAa;IACtB,GAAG;IACH;IACA;IACA,aAAa;IACb,cAAc;GACf,CAAC;GACD,IAAI,KAAK;IACR,iBAAiB,QAAQ,IAAI;IAC7B,aAAa,QAAQ,IAAI;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,kBAAkB;CAClB,OAAO;AACR;AACA,SAAS,kBAAkB,WAAW,OAAO;CAC5C,aAAa,UAAU,GAAG,YAAY,MAAM,CAAC;AAC9C;AACA,SAAS,oBAAoB;CAC5B,kBAAkB;AACnB;AACA,SAAS,eAAe,QAAQ;CAC/B,UAAU,SAAS,KAAK,UAAU,OAAO,KAAK,KAAK,UAAU;CAC7D,OAAO,CAAC;AACT"}
|
package/dist/esm/addTheme.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { _mutateTheme } from "./_mutateTheme.mjs";
|
|
2
|
+
|
|
2
3
|
function addTheme(props) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
return _mutateTheme({
|
|
5
|
+
...props,
|
|
6
|
+
insertCSS: true,
|
|
7
|
+
mutationType: "add"
|
|
8
|
+
});
|
|
8
9
|
}
|
|
10
|
+
|
|
9
11
|
export { addTheme };
|
|
10
12
|
//# sourceMappingURL=addTheme.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"addTheme.js","names":[],"sources":["esm/addTheme.js"],"sourcesContent":["import { _mutateTheme } from \"./_mutateTheme\";\nfunction addTheme(props) {\n return _mutateTheme({ ...props, insertCSS: true, mutationType: \"add\" });\n}\nexport {\n addTheme\n};\n//# sourceMappingURL=addTheme.js.map\n"],"mappings":";;;AACA,SAAS,SAAS,OAAO;CACvB,OAAO,aAAa;EAAE,GAAG;EAAO,WAAW;EAAM,cAAc;CAAM,CAAC;AACxE"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { _mutateTheme } from "./_mutateTheme.native.js";
|
|
2
|
+
|
|
2
3
|
function addTheme(props) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
return _mutateTheme({
|
|
5
|
+
...props,
|
|
6
|
+
insertCSS: true,
|
|
7
|
+
mutationType: "add"
|
|
8
|
+
});
|
|
8
9
|
}
|
|
10
|
+
|
|
9
11
|
export { addTheme };
|
|
10
12
|
//# sourceMappingURL=addTheme.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"addTheme.native.js","names":[],"sources":["esm/addTheme.native.js"],"sourcesContent":["import { _mutateTheme } from \"./_mutateTheme\";\nfunction addTheme(props) {\n return _mutateTheme({\n ...props,\n insertCSS: true,\n mutationType: \"add\"\n });\n}\nexport {\n addTheme\n};\n//# sourceMappingURL=addTheme.js.map\n"],"mappings":";;;AACA,SAAS,SAAS,OAAO;CACvB,OAAO,aAAa;EAClB,GAAG;EACH,WAAW;EACX,cAAc;CAChB,CAAC;AACH"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export * from "./addTheme.mjs";
|
|
2
|
-
export * from "./updateTheme.mjs";
|
|
3
|
-
export * from "./replaceTheme.mjs";
|
|
4
1
|
import { mutateThemes } from "./_mutateTheme.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
export * from "./addTheme.mjs"
|
|
4
|
+
|
|
5
|
+
export * from "./updateTheme.mjs"
|
|
6
|
+
|
|
7
|
+
export * from "./replaceTheme.mjs"
|
|
8
|
+
|
|
9
|
+
export { mutateThemes };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export * from "./addTheme.mjs";
|
|
2
|
-
export * from "./updateTheme.mjs";
|
|
3
|
-
export * from "./replaceTheme.mjs";
|
|
4
1
|
import { mutateThemes } from "./_mutateTheme.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
export * from "./addTheme.mjs"
|
|
4
|
+
|
|
5
|
+
export * from "./updateTheme.mjs"
|
|
6
|
+
|
|
7
|
+
export * from "./replaceTheme.mjs"
|
|
8
|
+
|
|
9
|
+
export { mutateThemes };
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export * from "./addTheme.native.js";
|
|
2
|
-
export * from "./updateTheme.native.js";
|
|
3
|
-
export * from "./replaceTheme.native.js";
|
|
4
1
|
import { mutateThemes } from "./_mutateTheme.native.js";
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
export * from "./addTheme.native.js"
|
|
4
|
+
|
|
5
|
+
export * from "./updateTheme.native.js"
|
|
6
|
+
|
|
7
|
+
export * from "./replaceTheme.native.js"
|
|
8
|
+
|
|
9
|
+
export { mutateThemes };
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { _mutateTheme } from "./_mutateTheme.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
return next;
|
|
2
|
+
|
|
3
|
+
function replaceTheme({ name, theme }) {
|
|
4
|
+
const next = _mutateTheme({
|
|
5
|
+
name,
|
|
6
|
+
theme,
|
|
7
|
+
insertCSS: true,
|
|
8
|
+
mutationType: "replace"
|
|
9
|
+
});
|
|
10
|
+
return next;
|
|
13
11
|
}
|
|
12
|
+
|
|
14
13
|
export { replaceTheme };
|
|
15
14
|
//# sourceMappingURL=replaceTheme.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"replaceTheme.js","names":[],"sources":["esm/replaceTheme.js"],"sourcesContent":["import { _mutateTheme } from \"./_mutateTheme\";\nfunction replaceTheme({\n name,\n theme\n}) {\n const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: \"replace\" });\n return next;\n}\nexport {\n replaceTheme\n};\n//# sourceMappingURL=replaceTheme.js.map\n"],"mappings":";;;AACA,SAAS,aAAa,EACpB,MACA,SACC;CACD,MAAM,OAAO,aAAa;EAAE;EAAM;EAAO,WAAW;EAAM,cAAc;CAAU,CAAC;CACnF,OAAO;AACT"}
|