@tamagui/theme 1.116.0 → 1.116.2

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.
@@ -0,0 +1,122 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var mutateTheme_exports = {};
16
+ __export(mutateTheme_exports, {
17
+ _mutateTheme: () => _mutateTheme,
18
+ mutateThemes: () => mutateThemes
19
+ });
20
+ module.exports = __toCommonJS(mutateTheme_exports);
21
+ var import_constants = require("@tamagui/constants"), import_web = require("@tamagui/web"), import_start_transition = require("@tamagui/start-transition");
22
+ function mutateThemes({
23
+ themes,
24
+ batch,
25
+ insertCSS = !0,
26
+ ...props
27
+ }) {
28
+ const allThemesProxied = {}, allThemesRaw = {};
29
+ for (const { name, theme } of themes) {
30
+ const res = _mutateTheme({
31
+ ...props,
32
+ name,
33
+ theme,
34
+ // we'll do one update at the end
35
+ avoidUpdate: !0,
36
+ // always add which also replaces but doesnt fail first time
37
+ mutationType: "add"
38
+ });
39
+ res && (allThemesProxied[name] = res.theme, allThemesRaw[name] = res.themeRaw);
40
+ }
41
+ const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
42
+ return (0, import_start_transition.startTransition)(() => {
43
+ for (const themeName in allThemesProxied) {
44
+ const theme = allThemesProxied[themeName];
45
+ updateThemeConfig(themeName, theme), notifyThemeManagersOfUpdate(themeName, theme);
46
+ }
47
+ }), {
48
+ themes: allThemesProxied,
49
+ themesRaw: allThemesRaw,
50
+ cssRules
51
+ };
52
+ }
53
+ function _mutateTheme(props) {
54
+ if (import_constants.isServer) {
55
+ process.env.NODE_ENV === "development" && console.warn("Theme mutation is not supported on server side");
56
+ return;
57
+ }
58
+ const config = (0, import_web.getConfig)(), { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
59
+ if (process.env.NODE_ENV === "development") {
60
+ if (!config)
61
+ throw new Error("No config");
62
+ const theme2 = config.themes[props.name];
63
+ if (mutationType !== "add" && !theme2)
64
+ throw new Error(
65
+ `${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
66
+ );
67
+ }
68
+ const theme = {
69
+ ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
70
+ ...themeIn
71
+ };
72
+ for (const key in theme)
73
+ (0, import_web.ensureThemeVariable)(theme, key);
74
+ const themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme), response = {
75
+ themeRaw: theme,
76
+ theme: themeProxied,
77
+ cssRules: []
78
+ };
79
+ return props.avoidUpdate || (insertCSS && (response.cssRules = insertThemeCSS({
80
+ [themeName]: theme
81
+ })), updateThemeConfig(themeName, themeProxied), notifyThemeManagersOfUpdate(themeName, themeProxied)), response;
82
+ }
83
+ function updateThemeConfig(themeName, theme) {
84
+ const config = (0, import_web.getConfig)();
85
+ config.themes[themeName] = theme, (0, import_web.updateConfig)("themes", config.themes);
86
+ }
87
+ function notifyThemeManagersOfUpdate(themeName, theme) {
88
+ import_web.activeThemeManagers.forEach((manager) => {
89
+ manager.state.name === themeName && manager.updateStateFromProps(
90
+ {
91
+ name: themeName,
92
+ forceTheme: theme
93
+ },
94
+ !0
95
+ );
96
+ });
97
+ }
98
+ function insertThemeCSS(themes, batch = !1) {
99
+ const config = (0, import_web.getConfig)();
100
+ let cssRules = [];
101
+ for (const themeName in themes) {
102
+ const theme = themes[themeName], rules = (0, import_web.getThemeCSSRules)({
103
+ config,
104
+ themeName,
105
+ names: [themeName],
106
+ hasDarkLight: !0,
107
+ theme
108
+ });
109
+ cssRules = [...cssRules, ...rules], batch || updateStyle(`t_theme_style_${themeName}`, rules);
110
+ }
111
+ if (batch) {
112
+ const id = (0, import_web.simpleHash)(typeof batch == "string" ? batch : Object.keys(themes).join(""));
113
+ updateStyle(`t_theme_style_${id}`, cssRules);
114
+ }
115
+ return cssRules;
116
+ }
117
+ function updateStyle(id, rules) {
118
+ const existing = document.querySelector(`#${id}`), style = document.createElement("style");
119
+ style.id = id, style.appendChild(document.createTextNode(rules.join(`
120
+ `))), document.head.appendChild(style), existing && existing.parentElement?.removeChild(existing);
121
+ }
122
+ //# sourceMappingURL=_mutateTheme.js.map
@@ -0,0 +1,24 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var addTheme_exports = {};
16
+ __export(addTheme_exports, {
17
+ addTheme: () => addTheme
18
+ });
19
+ module.exports = __toCommonJS(addTheme_exports);
20
+ var import_mutateTheme = require("./_mutateTheme");
21
+ function addTheme(props) {
22
+ return (0, import_mutateTheme._mutateTheme)({ ...props, insertCSS: !0, mutationType: "add" });
23
+ }
24
+ //# sourceMappingURL=addTheme.js.map
@@ -0,0 +1,24 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var src_exports = {};
16
+ __export(src_exports, {
17
+ mutateThemes: () => import_mutateTheme.mutateThemes
18
+ });
19
+ module.exports = __toCommonJS(src_exports);
20
+ __reExport(src_exports, require("./addTheme"), module.exports);
21
+ __reExport(src_exports, require("./updateTheme"), module.exports);
22
+ __reExport(src_exports, require("./replaceTheme"), module.exports);
23
+ var import_mutateTheme = require("./_mutateTheme");
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var replaceTheme_exports = {};
16
+ __export(replaceTheme_exports, {
17
+ replaceTheme: () => replaceTheme
18
+ });
19
+ module.exports = __toCommonJS(replaceTheme_exports);
20
+ var import_mutateTheme = require("./_mutateTheme");
21
+ function replaceTheme({
22
+ name,
23
+ theme
24
+ }) {
25
+ return (0, import_mutateTheme._mutateTheme)({ name, theme, insertCSS: !0, mutationType: "replace" });
26
+ }
27
+ //# sourceMappingURL=replaceTheme.js.map
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var updateTheme_exports = {};
16
+ __export(updateTheme_exports, {
17
+ updateTheme: () => updateTheme
18
+ });
19
+ module.exports = __toCommonJS(updateTheme_exports);
20
+ var import_mutateTheme = require("./_mutateTheme");
21
+ function updateTheme({
22
+ name,
23
+ theme
24
+ }) {
25
+ return (0, import_mutateTheme._mutateTheme)({ name, theme, insertCSS: !0, mutationType: "update" });
26
+ }
27
+ //# sourceMappingURL=updateTheme.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/theme",
3
- "version": "1.116.0",
3
+ "version": "1.116.2",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -20,12 +20,23 @@
20
20
  "clean": "tamagui-build clean",
21
21
  "clean:build": "tamagui-build clean:build"
22
22
  },
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "react-native-import": "./dist/esm/index.native.js",
27
+ "react-native": "./dist/cjs/index.native.js",
28
+ "types": "./types/index.d.ts",
29
+ "import": "./dist/esm/index.mjs",
30
+ "require": "./dist/cjs/index.cjs",
31
+ "default": "./dist/cjs/index.native.js"
32
+ }
33
+ },
23
34
  "dependencies": {
24
- "@tamagui/constants": "1.116.0",
25
- "@tamagui/web": "1.116.0"
35
+ "@tamagui/constants": "1.116.2",
36
+ "@tamagui/web": "1.116.2"
26
37
  },
27
38
  "devDependencies": {
28
- "@tamagui/build": "1.116.0",
39
+ "@tamagui/build": "1.116.2",
29
40
  "react": "^18.2.0 || ^19.0.0"
30
41
  },
31
42
  "publishConfig": {
File without changes
File without changes