@tamagui/theme 1.15.25 → 1.15.27
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.js +90 -0
- package/dist/cjs/_mutateTheme.js.map +6 -0
- package/dist/cjs/addTheme.js +2 -46
- package/dist/cjs/addTheme.js.map +2 -2
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/replaceTheme.js +47 -0
- package/dist/cjs/replaceTheme.js.map +6 -0
- package/dist/cjs/updateTheme.js +3 -3
- package/dist/cjs/updateTheme.js.map +1 -1
- package/dist/esm/_mutateTheme.js +72 -0
- package/dist/esm/_mutateTheme.js.map +6 -0
- package/dist/esm/_mutateTheme.mjs +72 -0
- package/dist/esm/_mutateTheme.mjs.map +6 -0
- package/dist/esm/addTheme.js +2 -52
- package/dist/esm/addTheme.js.map +2 -2
- package/dist/esm/addTheme.mjs +2 -52
- package/dist/esm/addTheme.mjs.map +2 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/replaceTheme.js +23 -0
- package/dist/esm/replaceTheme.js.map +6 -0
- package/dist/esm/replaceTheme.mjs +23 -0
- package/dist/esm/replaceTheme.mjs.map +6 -0
- package/dist/esm/updateTheme.js +3 -3
- package/dist/esm/updateTheme.js.map +1 -1
- package/dist/esm/updateTheme.mjs +3 -3
- package/dist/esm/updateTheme.mjs.map +1 -1
- package/dist/jsx/_mutateTheme.js +71 -0
- package/dist/jsx/_mutateTheme.js.map +6 -0
- package/dist/jsx/_mutateTheme.mjs +71 -0
- package/dist/jsx/_mutateTheme.mjs.map +6 -0
- package/dist/jsx/addTheme.js +2 -51
- package/dist/jsx/addTheme.js.map +2 -2
- package/dist/jsx/addTheme.mjs +2 -51
- package/dist/jsx/addTheme.mjs.map +2 -2
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -0
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/replaceTheme.js +23 -0
- package/dist/jsx/replaceTheme.js.map +6 -0
- package/dist/jsx/replaceTheme.mjs +23 -0
- package/dist/jsx/replaceTheme.mjs.map +6 -0
- package/dist/jsx/updateTheme.js +3 -3
- package/dist/jsx/updateTheme.js.map +1 -1
- package/dist/jsx/updateTheme.mjs +3 -3
- package/dist/jsx/updateTheme.mjs.map +1 -1
- package/package.json +4 -4
- package/src/_mutateTheme.ts +84 -0
- package/src/addTheme.ts +3 -60
- package/src/index.ts +1 -0
- package/src/replaceTheme.ts +27 -0
- package/src/updateTheme.ts +3 -3
- package/types/_mutateTheme.d.ts +32 -0
- package/types/_mutateTheme.d.ts.map +1 -0
- package/types/addTheme.d.ts +1 -2
- package/types/addTheme.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/replaceTheme.d.ts +30 -0
- package/types/replaceTheme.d.ts.map +1 -0
- package/types/updateTheme.d.ts +1 -1
- package/types/updateTheme.d.ts.map +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
+
import { _mutateTheme } from "./_mutateTheme.js";
|
|
3
|
+
function replaceTheme({
|
|
4
|
+
name,
|
|
5
|
+
theme
|
|
6
|
+
}) {
|
|
7
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "replace" });
|
|
8
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
|
+
activeThemeManagers.forEach((manager) => {
|
|
10
|
+
if (manager.state.name === name) {
|
|
11
|
+
manager.updateState({
|
|
12
|
+
name,
|
|
13
|
+
forceTheme: next == null ? void 0 : next.theme
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
replaceTheme
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=replaceTheme.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/replaceTheme.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,UAAU,CAAC;AAEnF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,6BAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/esm/updateTheme.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
-
import {
|
|
2
|
+
import { _mutateTheme } from "./_mutateTheme.js";
|
|
3
3
|
function updateTheme({
|
|
4
4
|
name,
|
|
5
5
|
theme
|
|
6
6
|
}) {
|
|
7
|
-
const next =
|
|
7
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "update" });
|
|
8
8
|
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
9
|
activeThemeManagers.forEach((manager) => {
|
|
10
10
|
if (manager.state.name === name) {
|
|
11
11
|
manager.updateState({
|
|
12
12
|
name,
|
|
13
|
-
forceTheme: next.theme
|
|
13
|
+
forceTheme: next == null ? void 0 : next.theme
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAElF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,6BAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/esm/updateTheme.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
-
import {
|
|
2
|
+
import { _mutateTheme } from "./_mutateTheme.js";
|
|
3
3
|
function updateTheme({
|
|
4
4
|
name,
|
|
5
5
|
theme
|
|
6
6
|
}) {
|
|
7
|
-
const next =
|
|
7
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "update" });
|
|
8
8
|
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
9
|
activeThemeManagers.forEach((manager) => {
|
|
10
10
|
if (manager.state.name === name) {
|
|
11
11
|
manager.updateState({
|
|
12
12
|
name,
|
|
13
|
-
forceTheme: next.theme
|
|
13
|
+
forceTheme: next == null ? void 0 : next.theme
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAElF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,6BAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isServer, isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig
|
|
8
|
+
} from "@tamagui/web";
|
|
9
|
+
function _mutateTheme(props) {
|
|
10
|
+
if (isServer) {
|
|
11
|
+
if (process.env.NODE_ENV === "development") {
|
|
12
|
+
console.warn("Theme mutation is not supported on server side");
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const config = getConfig();
|
|
17
|
+
const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
18
|
+
if (process.env.NODE_ENV === "development") {
|
|
19
|
+
if (!config) {
|
|
20
|
+
throw new Error("No config");
|
|
21
|
+
}
|
|
22
|
+
const theme2 = config.themes[props.name];
|
|
23
|
+
if (mutationType && !theme2) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (!props.mutationType && theme2) {
|
|
29
|
+
return { theme: theme2 };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const theme = {
|
|
33
|
+
...mutationType === "update" ? config.themes[themeName] ?? {} : {},
|
|
34
|
+
...themeIn
|
|
35
|
+
};
|
|
36
|
+
for (const key in theme) {
|
|
37
|
+
ensureThemeVariable(theme, key);
|
|
38
|
+
}
|
|
39
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
40
|
+
config.themes[themeName] = themeProxied;
|
|
41
|
+
let cssRules = [];
|
|
42
|
+
if (isWeb) {
|
|
43
|
+
if (insertCSS) {
|
|
44
|
+
cssRules = getThemeCSSRules({
|
|
45
|
+
// @ts-ignore this works but should be fixed types
|
|
46
|
+
config,
|
|
47
|
+
themeName,
|
|
48
|
+
names: [themeName],
|
|
49
|
+
theme
|
|
50
|
+
});
|
|
51
|
+
const id = `t_theme_style_${themeName}`;
|
|
52
|
+
const existing = document.querySelector(`#${id}`);
|
|
53
|
+
const style = document.createElement("style");
|
|
54
|
+
style.id = id;
|
|
55
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
56
|
+
document.head.appendChild(style);
|
|
57
|
+
if (existing) {
|
|
58
|
+
existing.parentElement?.removeChild(existing);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
63
|
+
return {
|
|
64
|
+
theme: themeProxied,
|
|
65
|
+
cssRules
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
_mutateTheme
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=_mutateTheme.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/_mutateTheme.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,UAAU,aAAa;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,iBAAS,eAAe,YAAY,QAAQ;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
5
|
+
"names": ["theme"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isServer, isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig
|
|
8
|
+
} from "@tamagui/web";
|
|
9
|
+
function _mutateTheme(props) {
|
|
10
|
+
if (isServer) {
|
|
11
|
+
if (process.env.NODE_ENV === "development") {
|
|
12
|
+
console.warn("Theme mutation is not supported on server side");
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const config = getConfig();
|
|
17
|
+
const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
18
|
+
if (process.env.NODE_ENV === "development") {
|
|
19
|
+
if (!config) {
|
|
20
|
+
throw new Error("No config");
|
|
21
|
+
}
|
|
22
|
+
const theme2 = config.themes[props.name];
|
|
23
|
+
if (mutationType && !theme2) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (!props.mutationType && theme2) {
|
|
29
|
+
return { theme: theme2 };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const theme = {
|
|
33
|
+
...mutationType === "update" ? config.themes[themeName] ?? {} : {},
|
|
34
|
+
...themeIn
|
|
35
|
+
};
|
|
36
|
+
for (const key in theme) {
|
|
37
|
+
ensureThemeVariable(theme, key);
|
|
38
|
+
}
|
|
39
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
40
|
+
config.themes[themeName] = themeProxied;
|
|
41
|
+
let cssRules = [];
|
|
42
|
+
if (isWeb) {
|
|
43
|
+
if (insertCSS) {
|
|
44
|
+
cssRules = getThemeCSSRules({
|
|
45
|
+
// @ts-ignore this works but should be fixed types
|
|
46
|
+
config,
|
|
47
|
+
themeName,
|
|
48
|
+
names: [themeName],
|
|
49
|
+
theme
|
|
50
|
+
});
|
|
51
|
+
const id = `t_theme_style_${themeName}`;
|
|
52
|
+
const existing = document.querySelector(`#${id}`);
|
|
53
|
+
const style = document.createElement("style");
|
|
54
|
+
style.id = id;
|
|
55
|
+
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
56
|
+
document.head.appendChild(style);
|
|
57
|
+
if (existing) {
|
|
58
|
+
existing.parentElement?.removeChild(existing);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
63
|
+
return {
|
|
64
|
+
theme: themeProxied,
|
|
65
|
+
cssRules
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
_mutateTheme
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=_mutateTheme.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/_mutateTheme.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,UAAU,aAAa;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,aAAa,OAK1B;AACD,MAAI,UAAU;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,gDAAgD;AAAA,IAC/D;AACA;AAAA,EACF;AACA,QAAM,SAAS,UAAU;AACzB,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;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
|
|
5
|
+
"names": ["theme"]
|
|
6
|
+
}
|
package/dist/jsx/addTheme.js
CHANGED
|
@@ -1,55 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
ensureThemeVariable,
|
|
4
|
-
getConfig,
|
|
5
|
-
getThemeCSSRules,
|
|
6
|
-
proxyThemeToParents,
|
|
7
|
-
updateConfig
|
|
8
|
-
} from "@tamagui/web";
|
|
1
|
+
import { _mutateTheme } from "./_mutateTheme";
|
|
9
2
|
function addTheme(props) {
|
|
10
|
-
|
|
11
|
-
if (process.env.NODE_ENV === "development") {
|
|
12
|
-
if (!config) {
|
|
13
|
-
throw new Error("No config");
|
|
14
|
-
}
|
|
15
|
-
const theme2 = config.themes[props.name];
|
|
16
|
-
if (!props.update && theme2) {
|
|
17
|
-
return { theme: theme2 };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const { name: themeName, theme: themeIn, insertCSS } = props;
|
|
21
|
-
const theme = { ...themeIn };
|
|
22
|
-
for (const key in theme) {
|
|
23
|
-
ensureThemeVariable(theme, key);
|
|
24
|
-
}
|
|
25
|
-
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
26
|
-
config.themes[themeName] = themeProxied;
|
|
27
|
-
let cssRules = [];
|
|
28
|
-
if (isWeb) {
|
|
29
|
-
if (insertCSS) {
|
|
30
|
-
cssRules = getThemeCSSRules({
|
|
31
|
-
// @ts-ignore this works but should be fixed types
|
|
32
|
-
config,
|
|
33
|
-
themeName,
|
|
34
|
-
names: [themeName],
|
|
35
|
-
theme
|
|
36
|
-
});
|
|
37
|
-
const id = `t_theme_style_${themeName}`;
|
|
38
|
-
const existing = document.querySelector(`#${id}`);
|
|
39
|
-
const style = document.createElement("style");
|
|
40
|
-
style.id = id;
|
|
41
|
-
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
42
|
-
document.head.appendChild(style);
|
|
43
|
-
if (existing) {
|
|
44
|
-
existing.parentElement?.removeChild(existing);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
49
|
-
return {
|
|
50
|
-
theme: themeProxied,
|
|
51
|
-
cssRules
|
|
52
|
-
};
|
|
3
|
+
return _mutateTheme({ ...props });
|
|
53
4
|
}
|
|
54
5
|
export {
|
|
55
6
|
addTheme
|
package/dist/jsx/addTheme.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/addTheme.ts"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
package/dist/jsx/addTheme.mjs
CHANGED
|
@@ -1,55 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
ensureThemeVariable,
|
|
4
|
-
getConfig,
|
|
5
|
-
getThemeCSSRules,
|
|
6
|
-
proxyThemeToParents,
|
|
7
|
-
updateConfig
|
|
8
|
-
} from "@tamagui/web";
|
|
1
|
+
import { _mutateTheme } from "./_mutateTheme";
|
|
9
2
|
function addTheme(props) {
|
|
10
|
-
|
|
11
|
-
if (process.env.NODE_ENV === "development") {
|
|
12
|
-
if (!config) {
|
|
13
|
-
throw new Error("No config");
|
|
14
|
-
}
|
|
15
|
-
const theme2 = config.themes[props.name];
|
|
16
|
-
if (!props.update && theme2) {
|
|
17
|
-
return { theme: theme2 };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const { name: themeName, theme: themeIn, insertCSS } = props;
|
|
21
|
-
const theme = { ...themeIn };
|
|
22
|
-
for (const key in theme) {
|
|
23
|
-
ensureThemeVariable(theme, key);
|
|
24
|
-
}
|
|
25
|
-
const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
|
|
26
|
-
config.themes[themeName] = themeProxied;
|
|
27
|
-
let cssRules = [];
|
|
28
|
-
if (isWeb) {
|
|
29
|
-
if (insertCSS) {
|
|
30
|
-
cssRules = getThemeCSSRules({
|
|
31
|
-
// @ts-ignore this works but should be fixed types
|
|
32
|
-
config,
|
|
33
|
-
themeName,
|
|
34
|
-
names: [themeName],
|
|
35
|
-
theme
|
|
36
|
-
});
|
|
37
|
-
const id = `t_theme_style_${themeName}`;
|
|
38
|
-
const existing = document.querySelector(`#${id}`);
|
|
39
|
-
const style = document.createElement("style");
|
|
40
|
-
style.id = id;
|
|
41
|
-
style.appendChild(document.createTextNode(cssRules.join("\n")));
|
|
42
|
-
document.head.appendChild(style);
|
|
43
|
-
if (existing) {
|
|
44
|
-
existing.parentElement?.removeChild(existing);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
|
|
49
|
-
return {
|
|
50
|
-
theme: themeProxied,
|
|
51
|
-
cssRules
|
|
52
|
-
};
|
|
3
|
+
return _mutateTheme({ ...props });
|
|
53
4
|
}
|
|
54
5
|
export {
|
|
55
6
|
addTheme
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/addTheme.ts"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
package/dist/jsx/index.js
CHANGED
package/dist/jsx/index.js.map
CHANGED
package/dist/jsx/index.mjs
CHANGED
package/dist/jsx/index.mjs.map
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
+
import { _mutateTheme } from "./_mutateTheme.js";
|
|
3
|
+
function replaceTheme({
|
|
4
|
+
name,
|
|
5
|
+
theme
|
|
6
|
+
}) {
|
|
7
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "replace" });
|
|
8
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
|
+
activeThemeManagers.forEach((manager) => {
|
|
10
|
+
if (manager.state.name === name) {
|
|
11
|
+
manager.updateState({
|
|
12
|
+
name,
|
|
13
|
+
forceTheme: next?.theme
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
replaceTheme
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=replaceTheme.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/replaceTheme.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,UAAU,CAAC;AAEnF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,MAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
+
import { _mutateTheme } from "./_mutateTheme.js";
|
|
3
|
+
function replaceTheme({
|
|
4
|
+
name,
|
|
5
|
+
theme
|
|
6
|
+
}) {
|
|
7
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "replace" });
|
|
8
|
+
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
|
+
activeThemeManagers.forEach((manager) => {
|
|
10
|
+
if (manager.state.name === name) {
|
|
11
|
+
manager.updateState({
|
|
12
|
+
name,
|
|
13
|
+
forceTheme: next?.theme
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
replaceTheme
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=replaceTheme.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/replaceTheme.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,UAAU,CAAC;AAEnF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,MAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/jsx/updateTheme.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
-
import {
|
|
2
|
+
import { _mutateTheme } from "./_mutateTheme.js";
|
|
3
3
|
function updateTheme({
|
|
4
4
|
name,
|
|
5
5
|
theme
|
|
6
6
|
}) {
|
|
7
|
-
const next =
|
|
7
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "update" });
|
|
8
8
|
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
9
|
activeThemeManagers.forEach((manager) => {
|
|
10
10
|
if (manager.state.name === name) {
|
|
11
11
|
manager.updateState({
|
|
12
12
|
name,
|
|
13
|
-
forceTheme: next
|
|
13
|
+
forceTheme: next?.theme
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAElF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,MAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/jsx/updateTheme.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { activeThemeManagers } from "@tamagui/web";
|
|
2
|
-
import {
|
|
2
|
+
import { _mutateTheme } from "./_mutateTheme.js";
|
|
3
3
|
function updateTheme({
|
|
4
4
|
name,
|
|
5
5
|
theme
|
|
6
6
|
}) {
|
|
7
|
-
const next =
|
|
7
|
+
const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "update" });
|
|
8
8
|
if (process.env.TAMAGUI_TARGET === "native") {
|
|
9
9
|
activeThemeManagers.forEach((manager) => {
|
|
10
10
|
if (manager.state.name === name) {
|
|
11
11
|
manager.updateState({
|
|
12
12
|
name,
|
|
13
|
-
forceTheme: next
|
|
13
|
+
forceTheme: next?.theme
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/updateTheme.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAElF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,MAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/theme",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.27",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"watch": "tamagui-build --watch"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@tamagui/constants": "1.15.
|
|
21
|
-
"@tamagui/web": "1.15.
|
|
20
|
+
"@tamagui/constants": "1.15.27",
|
|
21
|
+
"@tamagui/web": "1.15.27"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "*"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tamagui/build": "1.15.
|
|
27
|
+
"@tamagui/build": "1.15.27",
|
|
28
28
|
"react": "^18.2.0"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isServer, isWeb } from '@tamagui/constants'
|
|
2
|
+
import {
|
|
3
|
+
ensureThemeVariable,
|
|
4
|
+
getConfig,
|
|
5
|
+
getThemeCSSRules,
|
|
6
|
+
proxyThemeToParents,
|
|
7
|
+
updateConfig,
|
|
8
|
+
} from '@tamagui/web'
|
|
9
|
+
import type { ThemeDefinition, ThemeParsed } from '@tamagui/web'
|
|
10
|
+
|
|
11
|
+
export function _mutateTheme(props: {
|
|
12
|
+
name: string
|
|
13
|
+
theme: Partial<Record<keyof ThemeDefinition, any>>
|
|
14
|
+
insertCSS?: boolean
|
|
15
|
+
mutationType?: 'replace' | 'update'
|
|
16
|
+
}) {
|
|
17
|
+
if (isServer) {
|
|
18
|
+
if (process.env.NODE_ENV === 'development') {
|
|
19
|
+
console.warn('Theme mutation is not supported on server side')
|
|
20
|
+
}
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
const config = getConfig()
|
|
24
|
+
const { name: themeName, theme: themeIn, insertCSS, mutationType } = props
|
|
25
|
+
|
|
26
|
+
if (process.env.NODE_ENV === 'development') {
|
|
27
|
+
if (!config) {
|
|
28
|
+
throw new Error('No config')
|
|
29
|
+
}
|
|
30
|
+
const theme = config.themes[props.name]
|
|
31
|
+
if (mutationType && !theme) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`${mutationType === 'replace' ? 'Replace' : 'Update'} theme failed! Theme ${
|
|
34
|
+
props.name
|
|
35
|
+
} does not exist`
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
if (!props.mutationType && theme) {
|
|
39
|
+
return { theme }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const theme = {
|
|
44
|
+
...(mutationType === 'update' ? config.themes[themeName] ?? {} : {}),
|
|
45
|
+
...themeIn,
|
|
46
|
+
} as ThemeParsed
|
|
47
|
+
for (const key in theme) {
|
|
48
|
+
ensureThemeVariable(theme, key)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const themeProxied = proxyThemeToParents(themeName, theme, config.themes)
|
|
52
|
+
config.themes[themeName] = themeProxied
|
|
53
|
+
|
|
54
|
+
let cssRules: string[] = []
|
|
55
|
+
|
|
56
|
+
if (isWeb) {
|
|
57
|
+
if (insertCSS) {
|
|
58
|
+
cssRules = getThemeCSSRules({
|
|
59
|
+
// @ts-ignore this works but should be fixed types
|
|
60
|
+
config,
|
|
61
|
+
themeName,
|
|
62
|
+
names: [themeName],
|
|
63
|
+
theme,
|
|
64
|
+
})
|
|
65
|
+
const id = `t_theme_style_${themeName}`
|
|
66
|
+
const existing = document.querySelector(`#${id}`)
|
|
67
|
+
const style = document.createElement('style')
|
|
68
|
+
style.id = id
|
|
69
|
+
style.appendChild(document.createTextNode(cssRules.join('\n')))
|
|
70
|
+
document.head.appendChild(style)
|
|
71
|
+
if (existing) {
|
|
72
|
+
existing.parentElement?.removeChild(existing)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
updateConfig('themes', { ...config.themes, [themeName]: themeProxied })
|
|
78
|
+
|
|
79
|
+
// trigger updates in components
|
|
80
|
+
return {
|
|
81
|
+
theme: themeProxied,
|
|
82
|
+
cssRules,
|
|
83
|
+
}
|
|
84
|
+
}
|