@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.
Files changed (49) hide show
  1. package/dist/cjs/_mutateTheme.cjs +96 -116
  2. package/dist/cjs/_mutateTheme.native.cjs +113 -0
  3. package/dist/cjs/_mutateTheme.native.js +87 -109
  4. package/dist/cjs/_mutateTheme.native.js.map +1 -1
  5. package/dist/cjs/addTheme.cjs +19 -23
  6. package/dist/cjs/addTheme.native.cjs +33 -0
  7. package/dist/cjs/addTheme.native.js +19 -22
  8. package/dist/cjs/addTheme.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +14 -18
  10. package/dist/cjs/index.native.cjs +30 -0
  11. package/dist/cjs/index.native.js +14 -17
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/replaceTheme.cjs +22 -29
  14. package/dist/cjs/replaceTheme.native.cjs +36 -0
  15. package/dist/cjs/replaceTheme.native.js +22 -28
  16. package/dist/cjs/replaceTheme.native.js.map +1 -1
  17. package/dist/cjs/updateTheme.cjs +21 -28
  18. package/dist/cjs/updateTheme.native.cjs +35 -0
  19. package/dist/cjs/updateTheme.native.js +21 -27
  20. package/dist/cjs/updateTheme.native.js.map +1 -1
  21. package/dist/esm/_mutateTheme.mjs +84 -100
  22. package/dist/esm/_mutateTheme.mjs.map +1 -1
  23. package/dist/esm/_mutateTheme.native.js +75 -94
  24. package/dist/esm/_mutateTheme.native.js.map +1 -1
  25. package/dist/esm/addTheme.mjs +7 -5
  26. package/dist/esm/addTheme.mjs.map +1 -1
  27. package/dist/esm/addTheme.native.js +7 -5
  28. package/dist/esm/addTheme.native.js.map +1 -1
  29. package/dist/esm/index.js +8 -5
  30. package/dist/esm/index.mjs +8 -5
  31. package/dist/esm/index.native.js +8 -5
  32. package/dist/esm/replaceTheme.mjs +10 -11
  33. package/dist/esm/replaceTheme.mjs.map +1 -1
  34. package/dist/esm/replaceTheme.native.js +10 -11
  35. package/dist/esm/replaceTheme.native.js.map +1 -1
  36. package/dist/esm/updateTheme.mjs +9 -10
  37. package/dist/esm/updateTheme.mjs.map +1 -1
  38. package/dist/esm/updateTheme.native.js +9 -10
  39. package/dist/esm/updateTheme.native.js.map +1 -1
  40. package/package.json +7 -6
  41. package/src/_mutateTheme.ts +17 -15
  42. package/types/_mutateTheme.d.ts +1 -1
  43. package/types/_mutateTheme.d.ts.map +1 -1
  44. package/types/addTheme.d.ts +1 -1
  45. package/types/replaceTheme.d.ts +1 -1
  46. package/types/updateTheme.d.ts +1 -1
  47. package/dist/esm/index.js.map +0 -1
  48. package/dist/esm/index.mjs.map +0 -1
  49. package/dist/esm/index.native.js.map +0 -1
@@ -3,139 +3,119 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
10
  };
11
11
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
19
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
21
  var mutateTheme_exports = {};
24
22
  __export(mutateTheme_exports, {
25
- _mutateTheme: () => _mutateTheme,
26
- mutateThemes: () => mutateThemes
23
+ _mutateTheme: () => _mutateTheme,
24
+ mutateThemes: () => mutateThemes
27
25
  });
28
26
  module.exports = __toCommonJS(mutateTheme_exports);
29
27
  var import_constants = require("@tamagui/constants");
30
28
  var import_start_transition = require("@tamagui/start-transition");
31
29
  var import_web = require("@tamagui/web");
32
- function mutateThemes({
33
- themes,
34
- batch,
35
- insertCSS = true,
36
- ...props
37
- }) {
38
- const allThemesProxied = {};
39
- const allThemesRaw = {};
40
- for (const {
41
- name,
42
- theme
43
- } of themes) {
44
- const res = _mutateTheme({
45
- ...props,
46
- name,
47
- theme,
48
- avoidUpdate: true,
49
- mutationType: "add"
50
- });
51
- if (res) {
52
- allThemesProxied[name] = res.theme;
53
- allThemesRaw[name] = res.themeRaw;
54
- }
55
- }
56
- const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
57
- (0, import_start_transition.startTransition)(() => {
58
- for (const themeName in allThemesProxied) {
59
- const theme = allThemesProxied[themeName];
60
- updateThemeConfig(themeName, theme);
61
- }
62
- updateThemeStates();
63
- });
64
- return {
65
- themes: allThemesProxied,
66
- themesRaw: allThemesRaw,
67
- cssRules
68
- };
30
+ var import_internal_runtime = require("@tamagui/web/internal-runtime");
31
+ function mutateThemes({ themes, batch, insertCSS = true, ...props }) {
32
+ const allThemesProxied = {};
33
+ const allThemesRaw = {};
34
+ for (const { name, theme } of themes) {
35
+ const res = _mutateTheme({
36
+ ...props,
37
+ name,
38
+ theme,
39
+ avoidUpdate: true,
40
+ mutationType: "add"
41
+ });
42
+ if (res) {
43
+ allThemesProxied[name] = res.theme;
44
+ allThemesRaw[name] = res.themeRaw;
45
+ }
46
+ }
47
+ const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
48
+ (0, import_start_transition.startTransition)(() => {
49
+ (0, import_web.updateConfig)("themes", allThemesProxied);
50
+ updateThemeStates();
51
+ });
52
+ return {
53
+ themes: allThemesProxied,
54
+ themesRaw: allThemesRaw,
55
+ cssRules
56
+ };
69
57
  }
70
58
  function _mutateTheme(props) {
71
- if (import_constants.isServer) {
72
- if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
73
- return;
74
- }
75
- const config = (0, import_web.getConfig)();
76
- const {
77
- name: themeName,
78
- theme: themeIn,
79
- insertCSS,
80
- mutationType
81
- } = props;
82
- if (process.env.NODE_ENV === "development") {
83
- if (!config) throw new Error("No config");
84
- const theme2 = config.themes[props.name];
85
- if (mutationType !== "add" && !theme2) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
86
- }
87
- const theme = {
88
- ...(mutationType === "update" ? config.themes[themeName] ?? {} : {}),
89
- ...themeIn
90
- };
91
- for (const key in theme) (0, import_web.ensureThemeVariable)(theme, key);
92
- const themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme);
93
- const response = {
94
- themeRaw: theme,
95
- theme: themeProxied,
96
- cssRules: []
97
- };
98
- if (props.avoidUpdate) return response;
99
- if (insertCSS) response.cssRules = insertThemeCSS({
100
- [themeName]: theme
101
- });
102
- updateThemeConfig(themeName, themeProxied);
103
- updateThemeStates();
104
- return response;
59
+ if (import_constants.isServer) {
60
+ if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
61
+ return;
62
+ }
63
+ const config = (0, import_web.getConfig)();
64
+ const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
65
+ if (process.env.NODE_ENV === "development") {
66
+ if (!config) throw new Error("No config");
67
+ const theme2 = config.themes[props.name];
68
+ if (mutationType !== "add" && !theme2) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
69
+ }
70
+ const theme = {
71
+ ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
72
+ ...themeIn
73
+ };
74
+ for (const key in theme) (0, import_internal_runtime.ensureThemeVariable)(theme, key);
75
+ const themeProxied = (0, import_internal_runtime.proxyThemeToParents)(themeName, theme);
76
+ const response = {
77
+ themeRaw: theme,
78
+ theme: themeProxied,
79
+ cssRules: []
80
+ };
81
+ if (props.avoidUpdate) return response;
82
+ if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme });
83
+ updateThemeConfig(themeName, themeProxied);
84
+ updateThemeStates();
85
+ return response;
105
86
  }
106
87
  function updateThemeConfig(themeName, theme) {
107
- const config = (0, import_web.getConfig)();
108
- config.themes[themeName] = theme;
109
- (0, import_web.updateConfig)("themes", config.themes);
88
+ (0, import_web.updateConfig)("themes", { [themeName]: theme });
110
89
  }
111
90
  function updateThemeStates() {
112
- (0, import_web.forceUpdateThemes)();
91
+ (0, import_web.forceUpdateThemes)();
113
92
  }
114
93
  function insertThemeCSS(themes, batch = false) {
115
- const config = (0, import_web.getConfig)();
116
- let cssRules = [];
117
- for (const themeName in themes) {
118
- const theme = themes[themeName];
119
- const rules = (0, import_web.getThemeCSSRules)({
120
- config,
121
- themeName,
122
- names: [themeName],
123
- hasDarkLight: true,
124
- theme,
125
- useMutatedVariables: true
126
- });
127
- cssRules = [...cssRules, ...rules];
128
- if (!batch) updateStyle(`t_theme_style_${themeName}`, rules);
129
- }
130
- if (import_web.mutatedAutoVariables.length > 0) updateStyle(`t_mutate_vars`, [`:root{${import_web.mutatedAutoVariables.map(v => `--${v.name}:${v.val}`).join(";")}}`]);
131
- if (batch) updateStyle(`t_theme_style_${typeof batch == "string" ? batch : (0, import_web.simpleHash)(Object.keys(themes).join(""))}`, cssRules);
132
- return cssRules;
94
+ const config = (0, import_web.getConfig)();
95
+ let cssRules = [];
96
+ for (const themeName in themes) {
97
+ const theme = themes[themeName];
98
+ const rules = (0, import_internal_runtime.getThemeCSSRules)({
99
+ config,
100
+ themeName,
101
+ names: [themeName],
102
+ hasDarkLight: true,
103
+ theme,
104
+ useMutatedVariables: true
105
+ });
106
+ cssRules = [...cssRules, ...rules];
107
+ if (!batch) updateStyle(`t_theme_style_${themeName}`, rules);
108
+ }
109
+ const mutatedAutoVariableCSS = (0, import_web.getMutatedAutoVariableCSS)();
110
+ if (mutatedAutoVariableCSS) updateStyle(`t_mutate_vars`, [`:root{${mutatedAutoVariableCSS}}`]);
111
+ if (batch) updateStyle(`t_theme_style_${typeof batch == "string" ? batch : (0, import_web.simpleHash)(Object.keys(themes).join(""))}`, cssRules);
112
+ return cssRules;
133
113
  }
134
114
  function updateStyle(id, rules) {
135
- const existing = document.querySelector(`#${id}`);
136
- const style = document.createElement("style");
137
- style.id = id;
138
- style.appendChild(document.createTextNode(rules.join("\n")));
139
- document.head.appendChild(style);
140
- if (existing) existing.parentElement?.removeChild(existing);
141
- }
115
+ const existing = document.querySelector(`#${id}`);
116
+ const style = document.createElement("style");
117
+ style.id = id;
118
+ style.appendChild(document.createTextNode(rules.join("\n")));
119
+ document.head.appendChild(style);
120
+ if (existing) existing.parentElement?.removeChild(existing);
121
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var mutateTheme_exports = {};
24
+ __export(mutateTheme_exports, {
25
+ _mutateTheme: () => _mutateTheme,
26
+ mutateThemes: () => mutateThemes
27
+ });
28
+ module.exports = __toCommonJS(mutateTheme_exports);
29
+ var import_constants = require("@tamagui/constants");
30
+ var import_start_transition = require("@tamagui/start-transition");
31
+ var import_web = require("@tamagui/web");
32
+ var import_internal_runtime = require("@tamagui/web/internal-runtime");
33
+ function mutateThemes(param) {
34
+ var { themes, batch, insertCSS = true, ...props } = param;
35
+ var allThemesProxied = {};
36
+ var allThemesRaw = {};
37
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
38
+ try {
39
+ for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
40
+ var { name, theme } = _step.value;
41
+ var res = _mutateTheme({
42
+ ...props,
43
+ name,
44
+ theme,
45
+ avoidUpdate: true,
46
+ mutationType: "add"
47
+ });
48
+ if (res) {
49
+ allThemesProxied[name] = res.theme;
50
+ allThemesRaw[name] = res.themeRaw;
51
+ }
52
+ }
53
+ } catch (err) {
54
+ _didIteratorError = true;
55
+ _iteratorError = err;
56
+ } finally {
57
+ try {
58
+ if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
59
+ } finally {
60
+ if (_didIteratorError) throw _iteratorError;
61
+ }
62
+ }
63
+ var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
64
+ (0, import_start_transition.startTransition)(function() {
65
+ (0, import_web.updateConfig)("themes", allThemesProxied);
66
+ updateThemeStates();
67
+ });
68
+ return {
69
+ themes: allThemesProxied,
70
+ themesRaw: allThemesRaw,
71
+ cssRules
72
+ };
73
+ }
74
+ function _mutateTheme(props) {
75
+ if (import_constants.isServer) {
76
+ if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
77
+ return;
78
+ }
79
+ var config = (0, import_web.getConfig)();
80
+ var { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
81
+ if (process.env.NODE_ENV === "development") {
82
+ if (!config) throw new Error("No config");
83
+ var theme = config.themes[props.name];
84
+ if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
85
+ }
86
+ var _config_themes_themeName;
87
+ var theme1 = {
88
+ ...mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {},
89
+ ...themeIn
90
+ };
91
+ for (var key in theme1) (0, import_internal_runtime.ensureThemeVariable)(theme1, key);
92
+ var themeProxied = (0, import_internal_runtime.proxyThemeToParents)(themeName, theme1);
93
+ var response = {
94
+ themeRaw: theme1,
95
+ theme: themeProxied,
96
+ cssRules: []
97
+ };
98
+ if (props.avoidUpdate) return response;
99
+ if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme1 });
100
+ updateThemeConfig(themeName, themeProxied);
101
+ updateThemeStates();
102
+ return response;
103
+ }
104
+ function updateThemeConfig(themeName, theme) {
105
+ (0, import_web.updateConfig)("themes", { [themeName]: theme });
106
+ }
107
+ function updateThemeStates() {
108
+ (0, import_web.forceUpdateThemes)();
109
+ }
110
+ function insertThemeCSS(themes) {
111
+ arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
112
+ return [];
113
+ }
@@ -5,133 +5,111 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
- value: true
24
- }), mod);
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
23
  var mutateTheme_exports = {};
26
24
  __export(mutateTheme_exports, {
27
- _mutateTheme: () => _mutateTheme,
28
- mutateThemes: () => mutateThemes
25
+ _mutateTheme: () => _mutateTheme,
26
+ mutateThemes: () => mutateThemes
29
27
  });
30
28
  module.exports = __toCommonJS(mutateTheme_exports);
31
29
  var import_constants = require("@tamagui/constants");
32
30
  var import_start_transition = require("@tamagui/start-transition");
33
31
  var import_web = require("@tamagui/web");
32
+ var import_internal_runtime = require("@tamagui/web/internal-runtime");
34
33
  function mutateThemes(param) {
35
- var {
36
- themes,
37
- batch,
38
- insertCSS = true,
39
- ...props
40
- } = param;
41
- var allThemesProxied = {};
42
- var allThemesRaw = {};
43
- var _iteratorNormalCompletion = true,
44
- _didIteratorError = false,
45
- _iteratorError = void 0;
46
- try {
47
- for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
48
- var {
49
- name,
50
- theme
51
- } = _step.value;
52
- var res = _mutateTheme({
53
- ...props,
54
- name,
55
- theme,
56
- avoidUpdate: true,
57
- mutationType: "add"
58
- });
59
- if (res) {
60
- allThemesProxied[name] = res.theme;
61
- allThemesRaw[name] = res.themeRaw;
62
- }
63
- }
64
- } catch (err) {
65
- _didIteratorError = true;
66
- _iteratorError = err;
67
- } finally {
68
- try {
69
- if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
70
- } finally {
71
- if (_didIteratorError) throw _iteratorError;
72
- }
73
- }
74
- var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
75
- (0, import_start_transition.startTransition)(function () {
76
- for (var themeName in allThemesProxied) {
77
- var theme2 = allThemesProxied[themeName];
78
- updateThemeConfig(themeName, theme2);
79
- }
80
- updateThemeStates();
81
- });
82
- return {
83
- themes: allThemesProxied,
84
- themesRaw: allThemesRaw,
85
- cssRules
86
- };
34
+ var { themes, batch, insertCSS = true, ...props } = param;
35
+ var allThemesProxied = {};
36
+ var allThemesRaw = {};
37
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
38
+ try {
39
+ for (var _iterator = themes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
40
+ var { name, theme } = _step.value;
41
+ var res = _mutateTheme({
42
+ ...props,
43
+ name,
44
+ theme,
45
+ avoidUpdate: true,
46
+ mutationType: "add"
47
+ });
48
+ if (res) {
49
+ allThemesProxied[name] = res.theme;
50
+ allThemesRaw[name] = res.themeRaw;
51
+ }
52
+ }
53
+ } catch (err) {
54
+ _didIteratorError = true;
55
+ _iteratorError = err;
56
+ } finally {
57
+ try {
58
+ if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
59
+ } finally {
60
+ if (_didIteratorError) throw _iteratorError;
61
+ }
62
+ }
63
+ var cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
64
+ (0, import_start_transition.startTransition)(function() {
65
+ (0, import_web.updateConfig)("themes", allThemesProxied);
66
+ updateThemeStates();
67
+ });
68
+ return {
69
+ themes: allThemesProxied,
70
+ themesRaw: allThemesRaw,
71
+ cssRules
72
+ };
87
73
  }
88
74
  function _mutateTheme(props) {
89
- if (import_constants.isServer) {
90
- if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
91
- return;
92
- }
93
- var config = (0, import_web.getConfig)();
94
- var {
95
- name: themeName,
96
- theme: themeIn,
97
- insertCSS,
98
- mutationType
99
- } = props;
100
- if (process.env.NODE_ENV === "development") {
101
- if (!config) throw new Error("No config");
102
- var theme = config.themes[props.name];
103
- if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
104
- }
105
- var _config_themes_themeName;
106
- var theme1 = {
107
- ...(mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {}),
108
- ...themeIn
109
- };
110
- for (var key in theme1) (0, import_web.ensureThemeVariable)(theme1, key);
111
- var themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme1);
112
- var response = {
113
- themeRaw: theme1,
114
- theme: themeProxied,
115
- cssRules: []
116
- };
117
- if (props.avoidUpdate) return response;
118
- if (insertCSS) response.cssRules = insertThemeCSS({
119
- [themeName]: theme1
120
- });
121
- updateThemeConfig(themeName, themeProxied);
122
- updateThemeStates();
123
- return response;
75
+ if (import_constants.isServer) {
76
+ if (process.env.NODE_ENV === "development") console.warn("Theme mutation is not supported on server side");
77
+ return;
78
+ }
79
+ var config = (0, import_web.getConfig)();
80
+ var { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
81
+ if (process.env.NODE_ENV === "development") {
82
+ if (!config) throw new Error("No config");
83
+ var theme = config.themes[props.name];
84
+ if (mutationType !== "add" && !theme) throw new Error(`${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`);
85
+ }
86
+ var _config_themes_themeName;
87
+ var theme1 = {
88
+ ...mutationType === "update" ? (_config_themes_themeName = config.themes[themeName]) !== null && _config_themes_themeName !== void 0 ? _config_themes_themeName : {} : {},
89
+ ...themeIn
90
+ };
91
+ for (var key in theme1) (0, import_internal_runtime.ensureThemeVariable)(theme1, key);
92
+ var themeProxied = (0, import_internal_runtime.proxyThemeToParents)(themeName, theme1);
93
+ var response = {
94
+ themeRaw: theme1,
95
+ theme: themeProxied,
96
+ cssRules: []
97
+ };
98
+ if (props.avoidUpdate) return response;
99
+ if (insertCSS) response.cssRules = insertThemeCSS({ [themeName]: theme1 });
100
+ updateThemeConfig(themeName, themeProxied);
101
+ updateThemeStates();
102
+ return response;
124
103
  }
125
104
  function updateThemeConfig(themeName, theme) {
126
- var config = (0, import_web.getConfig)();
127
- config.themes[themeName] = theme;
128
- (0, import_web.updateConfig)("themes", config.themes);
105
+ (0, import_web.updateConfig)("themes", { [themeName]: theme });
129
106
  }
130
107
  function updateThemeStates() {
131
- (0, import_web.forceUpdateThemes)();
108
+ (0, import_web.forceUpdateThemes)();
132
109
  }
133
110
  function insertThemeCSS(themes) {
134
- arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
135
- return [];
111
+ arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
112
+ return [];
136
113
  }
114
+
137
115
  //# sourceMappingURL=_mutateTheme.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["to","__toCommonJS","mod","__copyProps","__defProp","value","mutateTheme_exports","__export","_mutateTheme","mutateThemes","module","exports","import_constants","require","import_start_transition","import_web","param","themes","batch","insertCSS","props","allThemesProxied","allThemesRaw","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","name","theme","res","avoidUpdate","mutationType","themeRaw","err","return","cssRules","insertThemeCSS","startTransition","themeName","theme2","updateThemeConfig","updateThemeStates","themesRaw","isServer","process","env","NODE_ENV","console","warn","config","getConfig","themeIn","Error","_config_themes_themeName","theme1","key","ensureThemeVariable","themeProxied","proxyThemeToParents","response","updateConfig","forceUpdateThemes","arguments","length"],"sources":["../../src/_mutateTheme.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;EAAA;EAAA,OAAAA,EAAA;AAAA;AAAA,IAAAC,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,YAAA,EAAAA,CAAA,KAAAA,YAA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ACTpB,KAAA,CAAAe,WAAA,SAAA6B,QAAA;EAEA,IAAA7C,SAAI,EAAA6C,QAAW,CAAAxB,QAAA,GAAAC,cAAA;IAAA,CAAAE,SAAA,GAAAgB;EAAA;EACbd,iBAAS,CAAAF,SAAW,EAAAmB,YAAe;EAAAhB,iBACvB,CAAG;EAAA,OACdkB,QAAA;AAAA;AAGH,SAAAnB,iBAAkBA,CAAAF,SAAW,EAAAV,KAAY;EACzC,IAAAqB,MAAA,OAAAvC,UAAkB,CAAAwC,SAAA;EAElBD,MAAA,CAAArC,MAAO,CAAA0B,SAAA,IAAAV,KAAA;EACT,IAAAlB,UAAA,CAAAkD,YAAA,YAAAX,MAAA,CAAArC,MAAA;AAEA;AACE,SAAM6B,iBAASA,CAAA;EACf,IAAA/B,UAAO,CAAOmD,iBAAa;AAC3B;AACF,SAAAzB,eAAAxB,MAAA;EAEAkD,SAAS,CAAAC,MAAA,QAAAD,SAAoB,kBAAAA,SAAA;EAC3B;AACF","ignoreList":[]}
1
+ {"version":3,"file":"_mutateTheme.native.js","names":[],"sources":["cjs/_mutateTheme.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\tfor (var name in all) __defProp(target, name, {\n\t\tget: all[name],\n\t\tenumerable: true\n\t});\n};\nvar __copyProps = (to, from, except, desc) => {\n\tif (from && typeof from === \"object\" || typeof from === \"function\") {\n\t\tfor (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {\n\t\t\tget: () => from[key],\n\t\t\tenumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable\n\t\t});\n\t}\n\treturn to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar mutateTheme_exports = {};\n__export(mutateTheme_exports, {\n\t_mutateTheme: () => _mutateTheme,\n\tmutateThemes: () => mutateThemes\n});\nmodule.exports = __toCommonJS(mutateTheme_exports);\nvar import_constants = require(\"@tamagui/constants\");\nvar import_start_transition = require(\"@tamagui/start-transition\");\nvar import_web = require(\"@tamagui/web\");\nvar import_internal_runtime = require(\"@tamagui/web/internal-runtime\");\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\t(0, import_start_transition.startTransition)(function() {\n\t\t(0, import_web.updateConfig)(\"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 (import_constants.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 = (0, import_web.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) (0, import_internal_runtime.ensureThemeVariable)(theme1, key);\n\tvar themeProxied = (0, import_internal_runtime.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\t(0, import_web.updateConfig)(\"themes\", { [themeName]: theme });\n}\nfunction updateThemeStates() {\n\t(0, import_web.forceUpdateThemes)();\n}\nfunction insertThemeCSS(themes) {\n\targuments.length > 1 && arguments[1] !== void 0 && arguments[1];\n\treturn [];\n}\n//# sourceMappingURL=_mutateTheme.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;CAC/B,KAAK,IAAI,QAAQ,KAAK,UAAU,QAAQ,MAAM;EAC7C,KAAK,IAAI;EACT,YAAY;CACb,CAAC;AACF;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC7C,IAAI,QAAQ,OAAO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