@tamagui/theme 1.74.3 → 1.74.4
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/esm/_mutateTheme.native.js +100 -0
- package/dist/esm/_mutateTheme.native.js.map +6 -0
- package/dist/esm/addTheme.native.js +8 -0
- package/dist/esm/addTheme.native.js.map +6 -0
- package/dist/esm/index.native.js +8 -0
- package/dist/esm/index.native.js.map +6 -0
- package/dist/esm/replaceTheme.native.js +11 -0
- package/dist/esm/replaceTheme.native.js.map +6 -0
- package/dist/esm/updateTheme.native.js +11 -0
- package/dist/esm/updateTheme.native.js.map +6 -0
- package/package.json +4 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isServer } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
activeThemeManagers,
|
|
4
|
+
ensureThemeVariable,
|
|
5
|
+
getConfig,
|
|
6
|
+
getThemeCSSRules,
|
|
7
|
+
proxyThemeToParents,
|
|
8
|
+
simpleHash,
|
|
9
|
+
updateConfig
|
|
10
|
+
} from "@tamagui/web";
|
|
11
|
+
import { startTransition } from "react";
|
|
12
|
+
function mutateThemes({
|
|
13
|
+
themes,
|
|
14
|
+
batch,
|
|
15
|
+
insertCSS = !0,
|
|
16
|
+
...props
|
|
17
|
+
}) {
|
|
18
|
+
const allThemesProxied = {}, allThemesRaw = {};
|
|
19
|
+
for (const { name, theme } of themes) {
|
|
20
|
+
const res = _mutateTheme({
|
|
21
|
+
...props,
|
|
22
|
+
name,
|
|
23
|
+
theme,
|
|
24
|
+
// we'll do one update at the end
|
|
25
|
+
avoidUpdate: !0,
|
|
26
|
+
// always add which also replaces but doesnt fail first time
|
|
27
|
+
mutationType: "add"
|
|
28
|
+
});
|
|
29
|
+
res && (allThemesProxied[name] = res.theme, allThemesRaw[name] = res.themeRaw);
|
|
30
|
+
}
|
|
31
|
+
const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
|
|
32
|
+
return startTransition(() => {
|
|
33
|
+
for (const themeName in allThemesProxied) {
|
|
34
|
+
const theme = allThemesProxied[themeName];
|
|
35
|
+
updateThemeConfig(themeName, theme), notifyThemeManagersOfUpdate(themeName, theme);
|
|
36
|
+
}
|
|
37
|
+
}), {
|
|
38
|
+
themes: allThemesProxied,
|
|
39
|
+
themesRaw: allThemesRaw,
|
|
40
|
+
cssRules
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function _mutateTheme(props) {
|
|
44
|
+
if (isServer) {
|
|
45
|
+
process.env.NODE_ENV === "development" && console.warn("Theme mutation is not supported on server side");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const config = getConfig(), { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
|
|
49
|
+
if (process.env.NODE_ENV === "development") {
|
|
50
|
+
if (!config)
|
|
51
|
+
throw new Error("No config");
|
|
52
|
+
const theme2 = config.themes[props.name];
|
|
53
|
+
if (mutationType !== "add" && !theme2)
|
|
54
|
+
throw new Error(
|
|
55
|
+
`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const theme = {
|
|
59
|
+
...mutationType === "update" ? config.themes[themeName] ?? {} : {},
|
|
60
|
+
...themeIn
|
|
61
|
+
};
|
|
62
|
+
for (const key in theme)
|
|
63
|
+
ensureThemeVariable(theme, key);
|
|
64
|
+
const themeProxied = proxyThemeToParents(themeName, theme), response = {
|
|
65
|
+
themeRaw: theme,
|
|
66
|
+
theme: themeProxied,
|
|
67
|
+
cssRules: []
|
|
68
|
+
};
|
|
69
|
+
return props.avoidUpdate || (insertCSS && (response.cssRules = insertThemeCSS({
|
|
70
|
+
[themeName]: theme
|
|
71
|
+
})), updateThemeConfig(themeName, themeProxied), notifyThemeManagersOfUpdate(themeName, themeProxied)), response;
|
|
72
|
+
}
|
|
73
|
+
function updateThemeConfig(themeName, theme) {
|
|
74
|
+
const config = getConfig();
|
|
75
|
+
config.themes[themeName] = theme, updateConfig("themes", config.themes);
|
|
76
|
+
}
|
|
77
|
+
function notifyThemeManagersOfUpdate(themeName, theme) {
|
|
78
|
+
activeThemeManagers.forEach((manager) => {
|
|
79
|
+
manager.state.name === themeName && manager.updateStateFromProps(
|
|
80
|
+
{
|
|
81
|
+
name: themeName,
|
|
82
|
+
forceTheme: theme
|
|
83
|
+
},
|
|
84
|
+
!0
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function insertThemeCSS(themes, batch = !1) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
function updateStyle(id, rules) {
|
|
92
|
+
const existing = document.querySelector(`#${id}`), style = document.createElement("style");
|
|
93
|
+
style.id = id, style.appendChild(document.createTextNode(rules.join(`
|
|
94
|
+
`))), document.head.appendChild(style), existing && existing.parentElement?.removeChild(existing);
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
_mutateTheme,
|
|
98
|
+
mutateThemes
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=_mutateTheme.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/_mutateTheme.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,gBAAgB;AAEzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAmBzB,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,GAAG;AACL,GAMG;AACD,QAAM,mBAAgD,CAAC,GACjD,eAA4C,CAAC;AAEnD,aAAW,EAAE,MAAM,MAAM,KAAK,QAAQ;AACpC,UAAM,MAAM,aAAa;AAAA,MACvB,GAAG;AAAA,MACH;AAAA,MACA;AAAA;AAAA,MAEA,aAAa;AAAA;AAAA,MAEb,cAAc;AAAA,IACh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AC,IAGH,kBAAkB,WAAW,YAAY,GACzC,4BAA4B,WAAW,YAAY,IAE5C;AACT;AAEA,SAAS,kBAAkB,WAAmB,OAAoB;AAChE,QAAM,SAAS,UAAU;AACzB,SAAO,OAAO,SAAS,IAAI,OAC3B,aAAa,UAAU,OAAO,MAAM;AACtC;AAEA,SAAS,4BAA4B,WAAmB,OAAoB;AAC1E,sBAAoB,QAAQ,CAAC,YAAY;AACvC,IAAI,QAAQ,MAAM,SAAS,aACzB,QAAQ;AAAA,MACN;AAAA,QACE,MAAM;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA;AAAA,IACF;AAAA,EAEJ,CAAC;AACH;AAEA,SAAS,eAAe,QAAsC,QAAe,IAAO;AAEhF,SAAO,CAAC;AA6BZ;AAEA,SAAS,YAAY,IAAY,OAAiB;AAChD,QAAM,WAAW,SAAS,cAAc,IAAI,EAAE,EAAE,GAC1C,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,KAAK,IACX,MAAM,YAAY,SAAS,eAAe,MAAM,KAAK;AAAA,CAAI,CAAC,CAAC,GAC3D,SAAS,KAAK,YAAY,KAAK,GAC3B,YACF,SAAS,eAAe,YAAY,QAAQ;AAEhD;",
|
|
5
|
+
"names": ["theme"]
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/theme",
|
|
3
|
-
"version": "1.74.
|
|
3
|
+
"version": "1.74.4",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"clean:build": "tamagui-build clean:build"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tamagui/constants": "1.74.
|
|
25
|
-
"@tamagui/web": "1.74.
|
|
24
|
+
"@tamagui/constants": "1.74.4",
|
|
25
|
+
"@tamagui/web": "1.74.4"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tamagui/build": "1.74.
|
|
31
|
+
"@tamagui/build": "1.74.4",
|
|
32
32
|
"react": "^18.2.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|