@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,43 +1,38 @@
|
|
|
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 updateTheme_exports = {};
|
|
26
|
-
__export(updateTheme_exports, {
|
|
27
|
-
updateTheme: () => updateTheme
|
|
28
|
-
});
|
|
25
|
+
__export(updateTheme_exports, { updateTheme: () => updateTheme });
|
|
29
26
|
module.exports = __toCommonJS(updateTheme_exports);
|
|
30
27
|
var import_mutateTheme = require("./_mutateTheme.native.js");
|
|
31
28
|
function updateTheme(param) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
insertCSS: true,
|
|
40
|
-
mutationType: "update"
|
|
41
|
-
});
|
|
29
|
+
var { name, theme } = param;
|
|
30
|
+
return (0, import_mutateTheme._mutateTheme)({
|
|
31
|
+
name,
|
|
32
|
+
theme,
|
|
33
|
+
insertCSS: true,
|
|
34
|
+
mutationType: "update"
|
|
35
|
+
});
|
|
42
36
|
}
|
|
37
|
+
|
|
43
38
|
//# sourceMappingURL=updateTheme.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"updateTheme.native.js","names":[],"sources":["cjs/updateTheme.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 for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar updateTheme_exports = {};\n__export(updateTheme_exports, {\n updateTheme: () => updateTheme\n});\nmodule.exports = __toCommonJS(updateTheme_exports);\nvar import_mutateTheme = require(\"./_mutateTheme\");\nfunction updateTheme(param) {\n var { name, theme } = param;\n return (0, import_mutateTheme._mutateTheme)({\n name,\n theme,\n insertCSS: true,\n mutationType: \"update\"\n });\n}\n//# sourceMappingURL=updateTheme.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;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,sBAAsB,CAAC;AAC3B,SAAS,qBAAqB,EAC5B,mBAAmB,YACrB,CAAC;AACD,OAAO,UAAU,aAAa,mBAAmB;AACjD,IAAI,qBAAqB,QAAQ,0BAAgB;AACjD,SAAS,YAAY,OAAO;CAC1B,IAAI,EAAE,MAAM,UAAU;CACtB,QAAQ,GAAG,mBAAmB,cAAc;EAC1C;EACA;EACA,WAAW;EACX,cAAc;CAChB,CAAC;AACH"}
|
|
@@ -1,115 +1,103 @@
|
|
|
1
1
|
import { isServer } from "@tamagui/constants";
|
|
2
2
|
import { startTransition } from "@tamagui/start-transition";
|
|
3
|
-
import { ensureThemeVariable, forceUpdateThemes, getConfig,
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
updateThemeStates();
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
themes: allThemesProxied,
|
|
38
|
-
themesRaw: allThemesRaw,
|
|
39
|
-
cssRules
|
|
40
|
-
};
|
|
3
|
+
import { ensureThemeVariable, forceUpdateThemes, getConfig, getMutatedAutoVariableCSS, getThemeCSSRules, proxyThemeToParents, simpleHash, updateConfig } from "@tamagui/web";
|
|
4
|
+
|
|
5
|
+
function mutateThemes({ themes, batch, insertCSS = true, ...props }) {
|
|
6
|
+
const allThemesProxied = {};
|
|
7
|
+
const allThemesRaw = {};
|
|
8
|
+
for (const { name, theme } of themes) {
|
|
9
|
+
const res = _mutateTheme({
|
|
10
|
+
...props,
|
|
11
|
+
name,
|
|
12
|
+
theme,
|
|
13
|
+
avoidUpdate: true,
|
|
14
|
+
mutationType: "add"
|
|
15
|
+
});
|
|
16
|
+
if (res) {
|
|
17
|
+
allThemesProxied[name] = res.theme;
|
|
18
|
+
allThemesRaw[name] = res.themeRaw;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
22
|
+
startTransition(() => {
|
|
23
|
+
for (const themeName in allThemesProxied) {
|
|
24
|
+
const theme = allThemesProxied[themeName];
|
|
25
|
+
updateThemeConfig(themeName, theme);
|
|
26
|
+
}
|
|
27
|
+
updateThemeStates();
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
themes: allThemesProxied,
|
|
31
|
+
themesRaw: allThemesRaw,
|
|
32
|
+
cssRules
|
|
33
|
+
};
|
|
41
34
|
}
|
|
42
35
|
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;
|
|
36
|
+
if (isServer) {
|
|
37
|
+
if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const config = getConfig();
|
|
41
|
+
const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
42
|
+
if (process.env.NODE_ENV === "development") {
|
|
43
|
+
if (!config) throw new Error("No config");
|
|
44
|
+
const theme2 = config.themes[props.name];
|
|
45
|
+
if (mutationType !== "add" && !theme2) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
|
|
46
|
+
}
|
|
47
|
+
const theme = {
|
|
48
|
+
...mutationType === "update" ? config.themes[themeName] ?? {} : {},
|
|
49
|
+
...themeIn
|
|
50
|
+
};
|
|
51
|
+
for (const key in theme) ensureThemeVariable(theme, key);
|
|
52
|
+
const themeProxied = proxyThemeToParents(themeName, theme);
|
|
53
|
+
const response = {
|
|
54
|
+
themeRaw: theme,
|
|
55
|
+
theme: themeProxied,
|
|
56
|
+
cssRules: []
|
|
57
|
+
};
|
|
58
|
+
if (props.avoidUpdate) return response;
|
|
59
|
+
if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme });
|
|
60
|
+
updateThemeConfig(themeName, themeProxied);
|
|
61
|
+
updateThemeStates();
|
|
62
|
+
return response;
|
|
77
63
|
}
|
|
78
64
|
function updateThemeConfig(themeName, theme) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
const config = getConfig();
|
|
66
|
+
config.themes[themeName] = theme;
|
|
67
|
+
updateConfig("themes", config.themes);
|
|
82
68
|
}
|
|
83
69
|
function updateThemeStates() {
|
|
84
|
-
|
|
70
|
+
forceUpdateThemes();
|
|
85
71
|
}
|
|
86
72
|
function insertThemeCSS(themes, batch = false) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
73
|
+
const config = getConfig();
|
|
74
|
+
let cssRules = [];
|
|
75
|
+
for (const themeName in themes) {
|
|
76
|
+
const theme = themes[themeName];
|
|
77
|
+
const rules = getThemeCSSRules({
|
|
78
|
+
config,
|
|
79
|
+
themeName,
|
|
80
|
+
names: [themeName],
|
|
81
|
+
hasDarkLight: true,
|
|
82
|
+
theme,
|
|
83
|
+
useMutatedVariables: true
|
|
84
|
+
});
|
|
85
|
+
cssRules = [...cssRules, ...rules];
|
|
86
|
+
if (!batch) updateStyle(`t_theme_style_${themeName}`, rules);
|
|
87
|
+
}
|
|
88
|
+
const mutatedAutoVariableCSS = getMutatedAutoVariableCSS();
|
|
89
|
+
if (mutatedAutoVariableCSS) updateStyle(`t_mutate_vars`, [`:root{${mutatedAutoVariableCSS}}`]);
|
|
90
|
+
if (batch) updateStyle(`t_theme_style_${typeof batch == "string" ? batch : simpleHash(Object.keys(themes).join(""))}`, cssRules);
|
|
91
|
+
return cssRules;
|
|
105
92
|
}
|
|
106
93
|
function updateStyle(id, rules) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
94
|
+
const existing = document.querySelector(`#${id}`);
|
|
95
|
+
const style = document.createElement("style");
|
|
96
|
+
style.id = id;
|
|
97
|
+
style.appendChild(document.createTextNode(rules.join("\n")));
|
|
98
|
+
document.head.appendChild(style);
|
|
99
|
+
if (existing) existing.parentElement?.removeChild(existing);
|
|
113
100
|
}
|
|
101
|
+
|
|
114
102
|
export { _mutateTheme, mutateThemes };
|
|
115
103
|
//# 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 { ensureThemeVariable, forceUpdateThemes, getConfig, getMutatedAutoVariableCSS, getThemeCSSRules, proxyThemeToParents, simpleHash, updateConfig } from \"@tamagui/web\";\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\tfor (const themeName in allThemesProxied) {\n\t\t\tconst theme = allThemesProxied[themeName];\n\t\t\tupdateThemeConfig(themeName, theme);\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 (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\tconst config = getConfig();\n\tconfig.themes[themeName] = theme;\n\tupdateConfig(\"themes\", config.themes);\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":";;;;;AAIA,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,sBAAsB;EACrB,KAAK,MAAM,aAAa,kBAAkB;GACzC,MAAM,QAAQ,iBAAiB;GAC/B,kBAAkB,WAAW,KAAK;EACnC;EACA,kBAAkB;CACnB,CAAC;CACD,OAAO;EACN,QAAQ;EACR,WAAW;EACX;CACD;AACD;AACA,SAAS,aAAa,OAAO;CAC5B,IAAI,UAAU;EACb,IAAI,QAAQ,IAAI,aAAa,eAAe,QAAQ,KAAK,gDAAgD;EACzG;CACD;CACA,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,MAAM,WAAW,OAAO,SAAS,WAAW,iBAAiB;CACrE,IAAI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CAAC;CAC7F,IAAI,OAAO,YAAY,iBAAiB,OAAO,SAAS,WAAW,QAAQ,WAAW,OAAO,KAAK,MAAM,EAAE,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,93 @@
|
|
|
1
1
|
import { isServer } from "@tamagui/constants";
|
|
2
2
|
import { startTransition } from "@tamagui/start-transition";
|
|
3
3
|
import { ensureThemeVariable, forceUpdateThemes, getConfig, proxyThemeToParents, updateConfig } from "@tamagui/web";
|
|
4
|
+
|
|
4
5
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var theme2 = allThemesProxied[themeName];
|
|
48
|
-
updateThemeConfig(themeName, theme2);
|
|
49
|
-
}
|
|
50
|
-
updateThemeStates();
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
themes: allThemesProxied,
|
|
54
|
-
themesRaw: allThemesRaw,
|
|
55
|
-
cssRules
|
|
56
|
-
};
|
|
6
|
+
var { themes, batch, insertCSS = true, ...props } = param;
|
|
7
|
+
var allThemesProxied = {};
|
|
8
|
+
var allThemesRaw = {};
|
|
9
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
10
|
+
try {
|
|
11
|
+
for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
12
|
+
var { name, theme } = _step.value;
|
|
13
|
+
var res = _mutateTheme({
|
|
14
|
+
...props,
|
|
15
|
+
name,
|
|
16
|
+
theme,
|
|
17
|
+
avoidUpdate: true,
|
|
18
|
+
mutationType: "add"
|
|
19
|
+
});
|
|
20
|
+
if (res) {
|
|
21
|
+
allThemesProxied[name] = res.theme;
|
|
22
|
+
allThemesRaw[name] = res.themeRaw;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} catch (err) {
|
|
26
|
+
_didIteratorError = true;
|
|
27
|
+
_iteratorError = err;
|
|
28
|
+
} finally {
|
|
29
|
+
try {
|
|
30
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
31
|
+
} finally {
|
|
32
|
+
if (_didIteratorError) throw _iteratorError;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
36
|
+
startTransition(function() {
|
|
37
|
+
for (var themeName in allThemesProxied) {
|
|
38
|
+
var theme2 = allThemesProxied[themeName];
|
|
39
|
+
updateThemeConfig(themeName, theme2);
|
|
40
|
+
}
|
|
41
|
+
updateThemeStates();
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
themes: allThemesProxied,
|
|
45
|
+
themesRaw: allThemesRaw,
|
|
46
|
+
cssRules
|
|
47
|
+
};
|
|
57
48
|
}
|
|
58
49
|
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;
|
|
50
|
+
if (isServer) {
|
|
51
|
+
if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
var config = getConfig();
|
|
55
|
+
var { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
56
|
+
if (process.env.NODE_ENV === "development") {
|
|
57
|
+
if (!config) throw new Error("No config");
|
|
58
|
+
var theme = config.themes[props.name];
|
|
59
|
+
if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
|
|
60
|
+
}
|
|
61
|
+
var _config_themes_themeName;
|
|
62
|
+
var theme1 = {
|
|
63
|
+
...mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {},
|
|
64
|
+
...themeIn
|
|
65
|
+
};
|
|
66
|
+
for (var key in theme1) ensureThemeVariable(theme1, key);
|
|
67
|
+
var themeProxied = proxyThemeToParents(themeName, theme1);
|
|
68
|
+
var response = {
|
|
69
|
+
themeRaw: theme1,
|
|
70
|
+
theme: themeProxied,
|
|
71
|
+
cssRules: []
|
|
72
|
+
};
|
|
73
|
+
if (props.avoidUpdate) return response;
|
|
74
|
+
if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme1 });
|
|
75
|
+
updateThemeConfig(themeName, themeProxied);
|
|
76
|
+
updateThemeStates();
|
|
77
|
+
return response;
|
|
94
78
|
}
|
|
95
79
|
function updateThemeConfig(themeName, theme) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
80
|
+
var config = getConfig();
|
|
81
|
+
config.themes[themeName] = theme;
|
|
82
|
+
updateConfig("themes", config.themes);
|
|
99
83
|
}
|
|
100
84
|
function updateThemeStates() {
|
|
101
|
-
|
|
85
|
+
forceUpdateThemes();
|
|
102
86
|
}
|
|
103
87
|
function insertThemeCSS(themes) {
|
|
104
|
-
|
|
105
|
-
|
|
88
|
+
arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
|
|
89
|
+
return [];
|
|
106
90
|
}
|
|
91
|
+
|
|
107
92
|
export { _mutateTheme, mutateThemes };
|
|
108
93
|
//# 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 { ensureThemeVariable, forceUpdateThemes, getConfig, proxyThemeToParents, updateConfig } from \"@tamagui/web\";\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\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 (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\tvar config = getConfig();\n\tconfig.themes[themeName] = theme;\n\tupdateConfig(\"themes\", config.themes);\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":";;;;;AAIA,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,UAAU,GAAG,OAAO,EAAE,6BAA6B,QAAQ,UAAU,KAAK,GAAG,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;GAC1B;EACD;CACD,SAAS,KAAK;EACb,oBAAoB;EACpB,iBAAiB;CAClB,UAAU;EACT,IAAI;GACH,IAAI,CAAC,6BAA6B,UAAU,UAAU,MAAM,UAAU,OAAO;EAC9E,UAAU;GACT,IAAI,mBAAmB,MAAM;EAC9B;CACD;CACA,IAAI,WAAW,YAAY,eAAe,cAAc,KAAK,IAAI,CAAC;CAClE,gBAAgB,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A,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"}
|