@tamagui/theme 1.52.0 → 1.52.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.
@@ -18,13 +18,51 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var mutateTheme_exports = {};
20
20
  __export(mutateTheme_exports, {
21
- _mutateTheme: () => _mutateTheme
21
+ _mutateTheme: () => _mutateTheme,
22
+ mutateThemes: () => mutateThemes
22
23
  });
23
24
  module.exports = __toCommonJS(mutateTheme_exports);
24
25
  var import_constants = require("@tamagui/constants");
25
26
  var import_web = require("@tamagui/web");
27
+ var import_react = require("react");
28
+ function mutateThemes({
29
+ themes,
30
+ batch,
31
+ insertCSS = true,
32
+ ...props
33
+ }) {
34
+ const allThemesProxied = {};
35
+ const allThemesRaw = {};
36
+ for (const { name, theme } of themes) {
37
+ const res = _mutateTheme({
38
+ ...props,
39
+ name,
40
+ theme,
41
+ // we'll do one update at the end
42
+ avoidUpdate: true,
43
+ // always add which also replaces but doesnt fail first time
44
+ mutationType: "add"
45
+ });
46
+ if (res) {
47
+ allThemesProxied[name] = res.theme;
48
+ allThemesRaw[name] = res.themeRaw;
49
+ }
50
+ }
51
+ const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
52
+ (0, import_react.startTransition)(() => {
53
+ for (const themeName in allThemesProxied) {
54
+ const theme = allThemesProxied[themeName];
55
+ updateThemeConfig(themeName, theme);
56
+ notifyThemeManagersOfUpdate(themeName, theme);
57
+ }
58
+ });
59
+ return {
60
+ themes: allThemesProxied,
61
+ themesRaw: allThemesRaw,
62
+ cssRules
63
+ };
64
+ }
26
65
  function _mutateTheme(props) {
27
- var _a;
28
66
  if (import_constants.isServer) {
29
67
  if (process.env.NODE_ENV === "development") {
30
68
  console.warn("Theme mutation is not supported on server side");
@@ -38,14 +76,11 @@ function _mutateTheme(props) {
38
76
  throw new Error("No config");
39
77
  }
40
78
  const theme2 = config.themes[props.name];
41
- if (mutationType && !theme2) {
79
+ if (mutationType !== "add" && !theme2) {
42
80
  throw new Error(
43
81
  `${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
44
82
  );
45
83
  }
46
- if (!props.mutationType && theme2) {
47
- return { theme: theme2 };
48
- }
49
84
  }
50
85
  const theme = {
51
86
  ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
@@ -55,47 +90,81 @@ function _mutateTheme(props) {
55
90
  (0, import_web.ensureThemeVariable)(theme, key);
56
91
  }
57
92
  const themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme);
58
- config.themes[themeName] = themeProxied;
59
- let cssRules = [];
60
- (0, import_web.updateConfig)("themes", { ...config.themes, [themeName]: themeProxied });
61
- if (process.env.TAMAGUI_TARGET === "web") {
62
- if (insertCSS) {
63
- cssRules = (0, import_web.getThemeCSSRules)({
64
- // @ts-ignore this works but should be fixed types
65
- config,
66
- themeName,
67
- names: [themeName],
68
- theme
69
- });
70
- const id = `t_theme_style_${themeName}`;
71
- const existing = document.querySelector(`#${id}`);
72
- const style = document.createElement("style");
73
- style.id = id;
74
- style.appendChild(document.createTextNode(cssRules.join("\n")));
75
- document.head.appendChild(style);
76
- if (existing) {
77
- (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
78
- }
79
- }
93
+ const response = {
94
+ themeRaw: theme,
95
+ theme: themeProxied,
96
+ cssRules: []
97
+ };
98
+ if (props.avoidUpdate) {
99
+ return response;
80
100
  }
101
+ if (insertCSS) {
102
+ response.cssRules = insertThemeCSS({
103
+ [themeName]: theme
104
+ });
105
+ }
106
+ updateThemeConfig(themeName, themeProxied);
107
+ notifyThemeManagersOfUpdate(themeName, themeProxied);
108
+ return response;
109
+ }
110
+ function updateThemeConfig(themeName, theme) {
111
+ const config = (0, import_web.getConfig)();
112
+ config.themes[themeName] = theme;
113
+ (0, import_web.updateConfig)("themes", config.themes);
114
+ }
115
+ function notifyThemeManagersOfUpdate(themeName, theme) {
81
116
  import_web.activeThemeManagers.forEach((manager) => {
82
- if (manager.state.name === props.name) {
117
+ if (manager.state.name === themeName) {
83
118
  manager.updateState(
84
119
  {
85
- name: props.name,
86
- forceTheme: themeProxied
120
+ name: themeName,
121
+ forceTheme: theme
87
122
  },
88
123
  true
89
124
  );
90
125
  }
91
126
  });
92
- return {
93
- theme: themeProxied,
94
- cssRules
95
- };
127
+ }
128
+ function insertThemeCSS(themes, batch = false) {
129
+ if (process.env.TAMAGUI_TARGET !== "web") {
130
+ return [];
131
+ }
132
+ const config = (0, import_web.getConfig)();
133
+ let cssRules = [];
134
+ for (const themeName in themes) {
135
+ const theme = themes[themeName];
136
+ const rules = (0, import_web.getThemeCSSRules)({
137
+ // @ts-ignore this works but should be fixed types
138
+ config,
139
+ themeName,
140
+ names: [themeName],
141
+ theme
142
+ });
143
+ cssRules = [...cssRules, ...rules];
144
+ if (!batch) {
145
+ updateStyle(`t_theme_style_${themeName}`, rules);
146
+ }
147
+ }
148
+ if (batch) {
149
+ const id = (0, import_web.simpleHash)(Object.keys(themes).join(","));
150
+ updateStyle(`t_theme_style_${id}`, cssRules);
151
+ }
152
+ return cssRules;
153
+ }
154
+ function updateStyle(id, rules) {
155
+ var _a;
156
+ const existing = document.querySelector(`#${id}`);
157
+ const style = document.createElement("style");
158
+ style.id = id;
159
+ style.appendChild(document.createTextNode(rules.join("\n")));
160
+ document.head.appendChild(style);
161
+ if (existing) {
162
+ (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
163
+ }
96
164
  }
97
165
  // Annotate the CommonJS export names for ESM import in node:
98
166
  0 && (module.exports = {
99
- _mutateTheme
167
+ _mutateTheme,
168
+ mutateThemes
100
169
  });
101
170
  //# sourceMappingURL=_mutateTheme.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/_mutateTheme.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAA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23
23
  module.exports = __toCommonJS(addTheme_exports);
24
24
  var import_mutateTheme = require("./_mutateTheme");
25
25
  function addTheme(props) {
26
- return (0, import_mutateTheme._mutateTheme)({ ...props });
26
+ return (0, import_mutateTheme._mutateTheme)({ ...props, insertCSS: true, mutationType: "add" });
27
27
  }
28
28
  // Annotate the CommonJS export names for ESM import in node:
29
29
  0 && (module.exports = {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/addTheme.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAA6B;AAEtB,SAAS,SAAS,OAItB;AACD,aAAO,iCAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAA6B;AAEtB,SAAS,SAAS,OAItB;AACD,aAAO,iCAAa,EAAE,GAAG,OAAO,WAAW,MAAM,cAAc,MAAM,CAAC;AACxE;",
5
5
  "names": []
6
6
  }
package/dist/cjs/index.js CHANGED
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -14,12 +18,17 @@ var __copyProps = (to, from, except, desc) => {
14
18
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
20
  var src_exports = {};
21
+ __export(src_exports, {
22
+ mutateThemes: () => import_mutateTheme.mutateThemes
23
+ });
17
24
  module.exports = __toCommonJS(src_exports);
18
25
  __reExport(src_exports, require("./addTheme"), module.exports);
19
26
  __reExport(src_exports, require("./updateTheme"), module.exports);
20
27
  __reExport(src_exports, require("./replaceTheme"), module.exports);
28
+ var import_mutateTheme = require("./_mutateTheme");
21
29
  // Annotate the CommonJS export names for ESM import in node:
22
30
  0 && (module.exports = {
31
+ mutateThemes,
23
32
  ...require("./addTheme"),
24
33
  ...require("./updateTheme"),
25
34
  ...require("./replaceTheme")
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,uBAAd;AACA,wBAAc,0BADd;AAEA,wBAAc,2BAFd;",
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,uBAAd;AACA,wBAAc,0BADd;AAEA,wBAAc,2BAFd;AAGA,yBAA6B;",
5
5
  "names": []
6
6
  }
@@ -28,7 +28,6 @@ function updateTheme({
28
28
  }) {
29
29
  return (0, import_mutateTheme._mutateTheme)({ name, theme, insertCSS: true, mutationType: "update" });
30
30
  }
31
- globalThis["updateTheme"] = updateTheme;
32
31
  // Annotate the CommonJS export names for ESM import in node:
33
32
  0 && (module.exports = {
34
33
  updateTheme
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/updateTheme.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAA6B;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,aAAO,iCAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAC9E;AAEA,WAAW,aAAa,IAAI;",
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAA6B;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,aAAO,iCAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAC9E;",
5
5
  "names": []
6
6
  }
@@ -5,10 +5,48 @@ import {
5
5
  getConfig,
6
6
  getThemeCSSRules,
7
7
  proxyThemeToParents,
8
+ simpleHash,
8
9
  updateConfig
9
10
  } from "@tamagui/web";
11
+ import { startTransition } from "react";
12
+ function mutateThemes({
13
+ themes,
14
+ batch,
15
+ insertCSS = true,
16
+ ...props
17
+ }) {
18
+ const allThemesProxied = {};
19
+ const allThemesRaw = {};
20
+ for (const { name, theme } of themes) {
21
+ const res = _mutateTheme({
22
+ ...props,
23
+ name,
24
+ theme,
25
+ // we'll do one update at the end
26
+ avoidUpdate: true,
27
+ // always add which also replaces but doesnt fail first time
28
+ mutationType: "add"
29
+ });
30
+ if (res) {
31
+ allThemesProxied[name] = res.theme;
32
+ allThemesRaw[name] = res.themeRaw;
33
+ }
34
+ }
35
+ const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
36
+ startTransition(() => {
37
+ for (const themeName in allThemesProxied) {
38
+ const theme = allThemesProxied[themeName];
39
+ updateThemeConfig(themeName, theme);
40
+ notifyThemeManagersOfUpdate(themeName, theme);
41
+ }
42
+ });
43
+ return {
44
+ themes: allThemesProxied,
45
+ themesRaw: allThemesRaw,
46
+ cssRules
47
+ };
48
+ }
10
49
  function _mutateTheme(props) {
11
- var _a;
12
50
  if (isServer) {
13
51
  if (process.env.NODE_ENV === "development") {
14
52
  console.warn("Theme mutation is not supported on server side");
@@ -22,14 +60,11 @@ function _mutateTheme(props) {
22
60
  throw new Error("No config");
23
61
  }
24
62
  const theme2 = config.themes[props.name];
25
- if (mutationType && !theme2) {
63
+ if (mutationType !== "add" && !theme2) {
26
64
  throw new Error(
27
65
  `${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
28
66
  );
29
67
  }
30
- if (!props.mutationType && theme2) {
31
- return { theme: theme2 };
32
- }
33
68
  }
34
69
  const theme = {
35
70
  ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
@@ -39,46 +74,80 @@ function _mutateTheme(props) {
39
74
  ensureThemeVariable(theme, key);
40
75
  }
41
76
  const themeProxied = proxyThemeToParents(themeName, theme);
42
- config.themes[themeName] = themeProxied;
43
- let cssRules = [];
44
- updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
45
- if (process.env.TAMAGUI_TARGET === "web") {
46
- if (insertCSS) {
47
- cssRules = getThemeCSSRules({
48
- // @ts-ignore this works but should be fixed types
49
- config,
50
- themeName,
51
- names: [themeName],
52
- theme
53
- });
54
- const id = `t_theme_style_${themeName}`;
55
- const existing = document.querySelector(`#${id}`);
56
- const style = document.createElement("style");
57
- style.id = id;
58
- style.appendChild(document.createTextNode(cssRules.join("\n")));
59
- document.head.appendChild(style);
60
- if (existing) {
61
- (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
62
- }
63
- }
77
+ const response = {
78
+ themeRaw: theme,
79
+ theme: themeProxied,
80
+ cssRules: []
81
+ };
82
+ if (props.avoidUpdate) {
83
+ return response;
64
84
  }
85
+ if (insertCSS) {
86
+ response.cssRules = insertThemeCSS({
87
+ [themeName]: theme
88
+ });
89
+ }
90
+ updateThemeConfig(themeName, themeProxied);
91
+ notifyThemeManagersOfUpdate(themeName, themeProxied);
92
+ return response;
93
+ }
94
+ function updateThemeConfig(themeName, theme) {
95
+ const config = getConfig();
96
+ config.themes[themeName] = theme;
97
+ updateConfig("themes", config.themes);
98
+ }
99
+ function notifyThemeManagersOfUpdate(themeName, theme) {
65
100
  activeThemeManagers.forEach((manager) => {
66
- if (manager.state.name === props.name) {
101
+ if (manager.state.name === themeName) {
67
102
  manager.updateState(
68
103
  {
69
- name: props.name,
70
- forceTheme: themeProxied
104
+ name: themeName,
105
+ forceTheme: theme
71
106
  },
72
107
  true
73
108
  );
74
109
  }
75
110
  });
76
- return {
77
- theme: themeProxied,
78
- cssRules
79
- };
111
+ }
112
+ function insertThemeCSS(themes, batch = false) {
113
+ if (process.env.TAMAGUI_TARGET !== "web") {
114
+ return [];
115
+ }
116
+ const config = getConfig();
117
+ let cssRules = [];
118
+ for (const themeName in themes) {
119
+ const theme = themes[themeName];
120
+ const rules = getThemeCSSRules({
121
+ // @ts-ignore this works but should be fixed types
122
+ config,
123
+ themeName,
124
+ names: [themeName],
125
+ theme
126
+ });
127
+ cssRules = [...cssRules, ...rules];
128
+ if (!batch) {
129
+ updateStyle(`t_theme_style_${themeName}`, rules);
130
+ }
131
+ }
132
+ if (batch) {
133
+ const id = simpleHash(Object.keys(themes).join(","));
134
+ updateStyle(`t_theme_style_${id}`, cssRules);
135
+ }
136
+ return cssRules;
137
+ }
138
+ function updateStyle(id, rules) {
139
+ var _a;
140
+ const existing = document.querySelector(`#${id}`);
141
+ const style = document.createElement("style");
142
+ style.id = id;
143
+ style.appendChild(document.createTextNode(rules.join("\n")));
144
+ document.head.appendChild(style);
145
+ if (existing) {
146
+ (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
147
+ }
80
148
  }
81
149
  export {
82
- _mutateTheme
150
+ _mutateTheme,
151
+ mutateThemes
83
152
  };
84
153
  //# sourceMappingURL=_mutateTheme.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
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,OACK;AAEA,SAAS,aAAa,OAK1B;AAhBH;AAiBE,MAAI,UAAU;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,gDAAgD;AAAA,IAC/D;AACA;AAAA,EACF;AACA,QAAM,SAAS,UAAU;AACzB,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,WAAW,aAAa,IA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EACF,CAAC;AACH;AAEA,SAAS,eAAe,QAAsC,QAAQ,OAAO;AAC3E,MAAI,QAAQ,IAAI,mBAAmB,OAAO;AACxC,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,SAAS,UAAU;AACzB,MAAI,WAAqB,CAAC;AAE1B,aAAW,aAAa,QAAQ;AAC9B,UAAM,QAAQ,OAAO,SAAS;AAE9B,UAAM,QAAQ,iBAAiB;AAAA;AAAA,MAE7B;AAAA,MACA;AAAA,MACA,OAAO,CAAC,SAAS;AAAA,MACjB;AAAA,IACF,CAAC;AAED,eAAW,CAAC,GAAG,UAAU,GAAG,KAAK;AAEjC,QAAI,CAAC,OAAO;AACV,kBAAY,iBAAiB,aAAa,KAAK;AAAA,IACjD;AAAA,EACF;AAEA,MAAI,OAAO;AACT,UAAM,KAAK,WAAW,OAAO,KAAK,MAAM,EAAE,KAAK,GAAG,CAAC;AACnD,gBAAY,iBAAiB,MAAM,QAAQ;AAAA,EAC7C;AAEA,SAAO;AACT;AAEA,SAAS,YAAY,IAAY,OAAiB;AA3LlD;AA4LE,QAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,KAAK;AACX,QAAM,YAAY,SAAS,eAAe,MAAM,KAAK,IAAI,CAAC,CAAC;AAC3D,WAAS,KAAK,YAAY,KAAK;AAC/B,MAAI,UAAU;AACZ,mBAAS,kBAAT,mBAAwB,YAAY;AAAA,EACtC;AACF;",
5
5
  "names": ["theme"]
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import { _mutateTheme } from "./_mutateTheme";
2
2
  function addTheme(props) {
3
- return _mutateTheme({ ...props });
3
+ return _mutateTheme({ ...props, insertCSS: true, mutationType: "add" });
4
4
  }
5
5
  export {
6
6
  addTheme
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/addTheme.ts"],
4
- "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
4
+ "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,OAAO,WAAW,MAAM,cAAc,MAAM,CAAC;AACxE;",
5
5
  "names": []
6
6
  }
package/dist/esm/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  export * from "./addTheme";
2
2
  export * from "./updateTheme";
3
3
  export * from "./replaceTheme";
4
+ import { mutateThemes } from "./_mutateTheme";
5
+ export {
6
+ mutateThemes
7
+ };
4
8
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,oBAAoB;",
5
5
  "names": []
6
6
  }
@@ -5,7 +5,6 @@ function updateTheme({
5
5
  }) {
6
6
  return _mutateTheme({ name, theme, insertCSS: true, mutationType: "update" });
7
7
  }
8
- globalThis["updateTheme"] = updateTheme;
9
8
  export {
10
9
  updateTheme
11
10
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/updateTheme.ts"],
4
- "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,SAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAC9E;AAEA,WAAW,aAAa,IAAI;",
4
+ "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,SAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAC9E;",
5
5
  "names": []
6
6
  }
@@ -5,8 +5,47 @@ import {
5
5
  getConfig,
6
6
  getThemeCSSRules,
7
7
  proxyThemeToParents,
8
+ simpleHash,
8
9
  updateConfig
9
10
  } from "@tamagui/web";
11
+ import { startTransition } from "react";
12
+ function mutateThemes({
13
+ themes,
14
+ batch,
15
+ insertCSS = true,
16
+ ...props
17
+ }) {
18
+ const allThemesProxied = {};
19
+ const allThemesRaw = {};
20
+ for (const { name, theme } of themes) {
21
+ const res = _mutateTheme({
22
+ ...props,
23
+ name,
24
+ theme,
25
+ // we'll do one update at the end
26
+ avoidUpdate: true,
27
+ // always add which also replaces but doesnt fail first time
28
+ mutationType: "add"
29
+ });
30
+ if (res) {
31
+ allThemesProxied[name] = res.theme;
32
+ allThemesRaw[name] = res.themeRaw;
33
+ }
34
+ }
35
+ const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : [];
36
+ startTransition(() => {
37
+ for (const themeName in allThemesProxied) {
38
+ const theme = allThemesProxied[themeName];
39
+ updateThemeConfig(themeName, theme);
40
+ notifyThemeManagersOfUpdate(themeName, theme);
41
+ }
42
+ });
43
+ return {
44
+ themes: allThemesProxied,
45
+ themesRaw: allThemesRaw,
46
+ cssRules
47
+ };
48
+ }
10
49
  function _mutateTheme(props) {
11
50
  if (isServer) {
12
51
  if (process.env.NODE_ENV === "development") {
@@ -21,14 +60,11 @@ function _mutateTheme(props) {
21
60
  throw new Error("No config");
22
61
  }
23
62
  const theme2 = config.themes[props.name];
24
- if (mutationType && !theme2) {
63
+ if (mutationType !== "add" && !theme2) {
25
64
  throw new Error(
26
65
  `${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
27
66
  );
28
67
  }
29
- if (!props.mutationType && theme2) {
30
- return { theme: theme2 };
31
- }
32
68
  }
33
69
  const theme = {
34
70
  ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
@@ -38,46 +74,79 @@ function _mutateTheme(props) {
38
74
  ensureThemeVariable(theme, key);
39
75
  }
40
76
  const themeProxied = proxyThemeToParents(themeName, theme);
41
- config.themes[themeName] = themeProxied;
42
- let cssRules = [];
43
- updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
44
- if (process.env.TAMAGUI_TARGET === "web") {
45
- if (insertCSS) {
46
- cssRules = getThemeCSSRules({
47
- // @ts-ignore this works but should be fixed types
48
- config,
49
- themeName,
50
- names: [themeName],
51
- theme
52
- });
53
- const id = `t_theme_style_${themeName}`;
54
- const existing = document.querySelector(`#${id}`);
55
- const style = document.createElement("style");
56
- style.id = id;
57
- style.appendChild(document.createTextNode(cssRules.join("\n")));
58
- document.head.appendChild(style);
59
- if (existing) {
60
- existing.parentElement?.removeChild(existing);
61
- }
62
- }
77
+ const response = {
78
+ themeRaw: theme,
79
+ theme: themeProxied,
80
+ cssRules: []
81
+ };
82
+ if (props.avoidUpdate) {
83
+ return response;
84
+ }
85
+ if (insertCSS) {
86
+ response.cssRules = insertThemeCSS({
87
+ [themeName]: theme
88
+ });
63
89
  }
90
+ updateThemeConfig(themeName, themeProxied);
91
+ notifyThemeManagersOfUpdate(themeName, themeProxied);
92
+ return response;
93
+ }
94
+ function updateThemeConfig(themeName, theme) {
95
+ const config = getConfig();
96
+ config.themes[themeName] = theme;
97
+ updateConfig("themes", config.themes);
98
+ }
99
+ function notifyThemeManagersOfUpdate(themeName, theme) {
64
100
  activeThemeManagers.forEach((manager) => {
65
- if (manager.state.name === props.name) {
101
+ if (manager.state.name === themeName) {
66
102
  manager.updateState(
67
103
  {
68
- name: props.name,
69
- forceTheme: themeProxied
104
+ name: themeName,
105
+ forceTheme: theme
70
106
  },
71
107
  true
72
108
  );
73
109
  }
74
110
  });
75
- return {
76
- theme: themeProxied,
77
- cssRules
78
- };
111
+ }
112
+ function insertThemeCSS(themes, batch = false) {
113
+ if (process.env.TAMAGUI_TARGET !== "web") {
114
+ return [];
115
+ }
116
+ const config = getConfig();
117
+ let cssRules = [];
118
+ for (const themeName in themes) {
119
+ const theme = themes[themeName];
120
+ const rules = getThemeCSSRules({
121
+ // @ts-ignore this works but should be fixed types
122
+ config,
123
+ themeName,
124
+ names: [themeName],
125
+ theme
126
+ });
127
+ cssRules = [...cssRules, ...rules];
128
+ if (!batch) {
129
+ updateStyle(`t_theme_style_${themeName}`, rules);
130
+ }
131
+ }
132
+ if (batch) {
133
+ const id = simpleHash(Object.keys(themes).join(","));
134
+ updateStyle(`t_theme_style_${id}`, cssRules);
135
+ }
136
+ return cssRules;
137
+ }
138
+ function updateStyle(id, rules) {
139
+ const existing = document.querySelector(`#${id}`);
140
+ const style = document.createElement("style");
141
+ style.id = id;
142
+ style.appendChild(document.createTextNode(rules.join("\n")));
143
+ document.head.appendChild(style);
144
+ if (existing) {
145
+ existing.parentElement?.removeChild(existing);
146
+ }
79
147
  }
80
148
  export {
81
- _mutateTheme
149
+ _mutateTheme,
150
+ mutateThemes
82
151
  };
83
152
  //# sourceMappingURL=_mutateTheme.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
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,OACK;AAEA,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,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,WAAW,aAAa,IAAI;AAErE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAMA,SAAQ,OAAO,OAAO,MAAM,IAAI;AACtC,QAAI,gBAAgB,CAACA,QAAO;AAC1B,YAAM,IAAI;AAAA,QACR,GAAG,iBAAiB,YAAY,YAAY,gCAC1C,MAAM;AAAA,MAEV;AAAA,IACF;AACA,QAAI,CAAC,MAAM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OAAO,CAAC,SAAS;AAAA,MACjB;AAAA,IACF,CAAC;AAED,eAAW,CAAC,GAAG,UAAU,GAAG,KAAK;AAEjC,QAAI,CAAC,OAAO;AACV,kBAAY,iBAAiB,aAAa,KAAK;AAAA,IACjD;AAAA,EACF;AAEA,MAAI,OAAO;AACT,UAAM,KAAK,WAAW,OAAO,KAAK,MAAM,EAAE,KAAK,GAAG,CAAC;AACnD,gBAAY,iBAAiB,MAAM,QAAQ;AAAA,EAC7C;AAEA,SAAO;AACT;AAEA,SAAS,YAAY,IAAY,OAAiB;AAChD,QAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,KAAK;AACX,QAAM,YAAY,SAAS,eAAe,MAAM,KAAK,IAAI,CAAC,CAAC;AAC3D,WAAS,KAAK,YAAY,KAAK;AAC/B,MAAI,UAAU;AACZ,aAAS,eAAe,YAAY,QAAQ;AAAA,EAC9C;AACF;",
5
5
  "names": ["theme"]
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import { _mutateTheme } from "./_mutateTheme";
2
2
  function addTheme(props) {
3
- return _mutateTheme({ ...props });
3
+ return _mutateTheme({ ...props, insertCSS: true, mutationType: "add" });
4
4
  }
5
5
  export {
6
6
  addTheme
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/addTheme.ts"],
4
- "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
4
+ "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,OAAO,WAAW,MAAM,cAAc,MAAM,CAAC;AACxE;",
5
5
  "names": []
6
6
  }
package/dist/jsx/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  export * from "./addTheme";
2
2
  export * from "./updateTheme";
3
3
  export * from "./replaceTheme";
4
+ import { mutateThemes } from "./_mutateTheme";
5
+ export {
6
+ mutateThemes
7
+ };
4
8
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,oBAAoB;",
5
5
  "names": []
6
6
  }
@@ -5,7 +5,6 @@ function updateTheme({
5
5
  }) {
6
6
  return _mutateTheme({ name, theme, insertCSS: true, mutationType: "update" });
7
7
  }
8
- globalThis["updateTheme"] = updateTheme;
9
8
  export {
10
9
  updateTheme
11
10
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/updateTheme.ts"],
4
- "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,SAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAC9E;AAEA,WAAW,aAAa,IAAI;",
4
+ "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,SAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAC9E;",
5
5
  "names": []
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/theme",
3
- "version": "1.52.0",
3
+ "version": "1.52.2",
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.52.0",
21
- "@tamagui/web": "1.52.0"
20
+ "@tamagui/constants": "1.52.2",
21
+ "@tamagui/web": "1.52.2"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": "*"
25
25
  },
26
26
  "devDependencies": {
27
- "@tamagui/build": "1.52.0",
27
+ "@tamagui/build": "1.52.2",
28
28
  "react": "^18.2.0"
29
29
  },
30
30
  "publishConfig": {
@@ -6,15 +6,74 @@ import {
6
6
  getConfig,
7
7
  getThemeCSSRules,
8
8
  proxyThemeToParents,
9
+ simpleHash,
9
10
  updateConfig,
10
11
  } from '@tamagui/web'
12
+ import { startTransition } from 'react'
11
13
 
12
- export function _mutateTheme(props: {
13
- name: string
14
- theme: Partial<Record<keyof ThemeDefinition, any>>
14
+ type MutateThemeOptions = {
15
+ mutationType: 'replace' | 'update' | 'add'
15
16
  insertCSS?: boolean
16
- mutationType?: 'replace' | 'update'
17
+ avoidUpdate?: boolean
18
+ }
19
+
20
+ type PartialTheme = Partial<Record<keyof ThemeDefinition, any>>
21
+
22
+ export type MutateOneThemeProps = {
23
+ name: string
24
+ theme: PartialTheme
25
+ }
26
+
27
+ // more advanced helper used only internally in studio for now
28
+ export function mutateThemes({
29
+ themes,
30
+ batch,
31
+ insertCSS = true,
32
+ ...props
33
+ }: Omit<MutateThemeOptions, 'mutationType'> & {
34
+ themes: MutateOneThemeProps[]
35
+ // if using batch, know that if you later on do addTheme/etc it will break things
36
+ // batch is only useful if you know youre only ever going to change these themes using batch
37
+ // aka only in studio as a preview mode
38
+ batch?: boolean
17
39
  }) {
40
+ const allThemesProxied: Record<string, ThemeParsed> = {}
41
+ const allThemesRaw: Record<string, ThemeParsed> = {}
42
+
43
+ for (const { name, theme } of themes) {
44
+ const res = _mutateTheme({
45
+ ...props,
46
+ name,
47
+ theme,
48
+ // we'll do one update at the end
49
+ avoidUpdate: true,
50
+ // always add which also replaces but doesnt fail first time
51
+ mutationType: 'add',
52
+ })
53
+ if (res) {
54
+ allThemesProxied[name] = res.theme
55
+ allThemesRaw[name] = res.themeRaw
56
+ }
57
+ }
58
+
59
+ const cssRules = insertCSS ? insertThemeCSS(allThemesRaw, batch) : []
60
+
61
+ startTransition(() => {
62
+ for (const themeName in allThemesProxied) {
63
+ const theme = allThemesProxied[themeName]
64
+ updateThemeConfig(themeName, theme)
65
+ notifyThemeManagersOfUpdate(themeName, theme)
66
+ }
67
+ })
68
+
69
+ return {
70
+ themes: allThemesProxied,
71
+ themesRaw: allThemesRaw,
72
+ cssRules,
73
+ }
74
+ }
75
+
76
+ export function _mutateTheme(props: MutateThemeOptions & MutateOneThemeProps) {
18
77
  if (isServer) {
19
78
  if (process.env.NODE_ENV === 'development') {
20
79
  console.warn('Theme mutation is not supported on server side')
@@ -29,16 +88,14 @@ export function _mutateTheme(props: {
29
88
  throw new Error('No config')
30
89
  }
31
90
  const theme = config.themes[props.name]
32
- if (mutationType && !theme) {
91
+
92
+ if (mutationType !== 'add' && !theme) {
33
93
  throw new Error(
34
94
  `${mutationType === 'replace' ? 'Replace' : 'Update'} theme failed! Theme ${
35
95
  props.name
36
96
  } does not exist`
37
97
  )
38
98
  }
39
- if (!props.mutationType && theme) {
40
- return { theme }
41
- }
42
99
  }
43
100
 
44
101
  const theme = {
@@ -51,48 +108,90 @@ export function _mutateTheme(props: {
51
108
  }
52
109
 
53
110
  const themeProxied = proxyThemeToParents(themeName, theme)
54
- config.themes[themeName] = themeProxied
55
111
 
56
- let cssRules: string[] = []
112
+ const response = {
113
+ themeRaw: theme,
114
+ theme: themeProxied,
115
+ cssRules: [] as string[],
116
+ }
57
117
 
58
- updateConfig('themes', { ...config.themes, [themeName]: themeProxied })
59
-
60
- if (process.env.TAMAGUI_TARGET === 'web') {
61
- if (insertCSS) {
62
- cssRules = getThemeCSSRules({
63
- // @ts-ignore this works but should be fixed types
64
- config,
65
- themeName,
66
- names: [themeName],
67
- theme,
68
- })
69
- const id = `t_theme_style_${themeName}`
70
- const existing = document.querySelector(`#${id}`)
71
- const style = document.createElement('style')
72
- style.id = id
73
- style.appendChild(document.createTextNode(cssRules.join('\n')))
74
- document.head.appendChild(style)
75
- if (existing) {
76
- existing.parentElement?.removeChild(existing)
77
- }
78
- }
118
+ if (props.avoidUpdate) {
119
+ return response
79
120
  }
80
121
 
122
+ if (insertCSS) {
123
+ response.cssRules = insertThemeCSS({
124
+ [themeName]: theme,
125
+ })
126
+ }
127
+
128
+ updateThemeConfig(themeName, themeProxied)
129
+ notifyThemeManagersOfUpdate(themeName, themeProxied)
130
+
131
+ return response
132
+ }
133
+
134
+ function updateThemeConfig(themeName: string, theme: ThemeParsed) {
135
+ const config = getConfig()
136
+ config.themes[themeName] = theme
137
+ updateConfig('themes', config.themes)
138
+ }
139
+
140
+ function notifyThemeManagersOfUpdate(themeName: string, theme: ThemeParsed) {
81
141
  activeThemeManagers.forEach((manager) => {
82
- if (manager.state.name === props.name) {
142
+ if (manager.state.name === themeName) {
83
143
  manager.updateState(
84
144
  {
85
- name: props.name,
86
- forceTheme: themeProxied,
145
+ name: themeName,
146
+ forceTheme: theme,
87
147
  },
88
148
  true
89
149
  )
90
150
  }
91
151
  })
152
+ }
92
153
 
93
- // trigger updates in components
94
- return {
95
- theme: themeProxied,
96
- cssRules,
154
+ function insertThemeCSS(themes: Record<string, PartialTheme>, batch = false) {
155
+ if (process.env.TAMAGUI_TARGET !== 'web') {
156
+ return []
157
+ }
158
+
159
+ const config = getConfig()
160
+ let cssRules: string[] = []
161
+
162
+ for (const themeName in themes) {
163
+ const theme = themes[themeName]
164
+
165
+ const rules = getThemeCSSRules({
166
+ // @ts-ignore this works but should be fixed types
167
+ config,
168
+ themeName,
169
+ names: [themeName],
170
+ theme,
171
+ })
172
+
173
+ cssRules = [...cssRules, ...rules]
174
+
175
+ if (!batch) {
176
+ updateStyle(`t_theme_style_${themeName}`, rules)
177
+ }
178
+ }
179
+
180
+ if (batch) {
181
+ const id = simpleHash(Object.keys(themes).join(','))
182
+ updateStyle(`t_theme_style_${id}`, cssRules)
183
+ }
184
+
185
+ return cssRules
186
+ }
187
+
188
+ function updateStyle(id: string, rules: string[]) {
189
+ const existing = document.querySelector(`#${id}`)
190
+ const style = document.createElement('style')
191
+ style.id = id
192
+ style.appendChild(document.createTextNode(rules.join('\n')))
193
+ document.head.appendChild(style)
194
+ if (existing) {
195
+ existing.parentElement?.removeChild(existing)
97
196
  }
98
197
  }
package/src/addTheme.ts CHANGED
@@ -7,5 +7,5 @@ export function addTheme(props: {
7
7
  theme: Partial<Record<keyof ThemeDefinition, any>>
8
8
  insertCSS?: boolean
9
9
  }) {
10
- return _mutateTheme({ ...props })
10
+ return _mutateTheme({ ...props, insertCSS: true, mutationType: 'add' })
11
11
  }
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './addTheme'
2
2
  export * from './updateTheme'
3
3
  export * from './replaceTheme'
4
+ export { mutateThemes } from './_mutateTheme'
5
+ export type { MutateOneThemeProps } from './_mutateTheme'
@@ -11,5 +11,3 @@ export function updateTheme({
11
11
  }) {
12
12
  return _mutateTheme({ name, theme, insertCSS: true, mutationType: 'update' })
13
13
  }
14
-
15
- globalThis['updateTheme'] = updateTheme
@@ -1,32 +1,26 @@
1
1
  import type { ThemeDefinition, ThemeParsed } from '@tamagui/web';
2
- export declare function _mutateTheme(props: {
3
- name: string;
4
- theme: Partial<Record<keyof ThemeDefinition, any>>;
2
+ type MutateThemeOptions = {
3
+ mutationType: 'replace' | 'update' | 'add';
5
4
  insertCSS?: boolean;
6
- mutationType?: 'replace' | 'update';
5
+ avoidUpdate?: boolean;
6
+ };
7
+ type PartialTheme = Partial<Record<keyof ThemeDefinition, any>>;
8
+ export type MutateOneThemeProps = {
9
+ name: string;
10
+ theme: PartialTheme;
11
+ };
12
+ export declare function mutateThemes({ themes, batch, insertCSS, ...props }: Omit<MutateThemeOptions, 'mutationType'> & {
13
+ themes: MutateOneThemeProps[];
14
+ batch?: boolean;
7
15
  }): {
8
- theme: {
9
- [x: string]: import("@tamagui/web").Variable<any>;
10
- background?: import("@tamagui/web").Variable<any> | undefined;
11
- backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
12
- backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
13
- backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
14
- color?: import("@tamagui/web").Variable<any> | undefined;
15
- colorHover?: import("@tamagui/web").Variable<any> | undefined;
16
- colorPress?: import("@tamagui/web").Variable<any> | undefined;
17
- colorFocus?: import("@tamagui/web").Variable<any> | undefined;
18
- borderColor?: import("@tamagui/web").Variable<any> | undefined;
19
- borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
20
- borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
21
- borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
22
- shadowColor?: import("@tamagui/web").Variable<any> | undefined;
23
- shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
24
- shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
25
- shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
26
- };
27
- cssRules?: undefined;
28
- } | {
16
+ themes: Record<string, ThemeParsed>;
17
+ themesRaw: Record<string, ThemeParsed>;
18
+ cssRules: string[];
19
+ };
20
+ export declare function _mutateTheme(props: MutateThemeOptions & MutateOneThemeProps): {
21
+ themeRaw: ThemeParsed;
29
22
  theme: ThemeParsed;
30
23
  cssRules: string[];
31
24
  } | undefined;
25
+ export {};
32
26
  //# sourceMappingURL=_mutateTheme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_mutateTheme.d.ts","sourceRoot":"","sources":["../src/_mutateTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAUhE,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;CACpC;;;;;;;;;;;;;;;;;;;;;;;;cAiFA"}
1
+ {"version":3,"file":"_mutateTheme.d.ts","sourceRoot":"","sources":["../src/_mutateTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAYhE,KAAK,kBAAkB,GAAG;IACxB,YAAY,EAAE,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAA;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;AAE/D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,YAAY,CAAA;CACpB,CAAA;AAGD,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EACN,KAAK,EACL,SAAgB,EAChB,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,GAAG;IAC5C,MAAM,EAAE,mBAAmB,EAAE,CAAA;IAI7B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;;;;EAmCA;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB;;;;cAwD3E"}
@@ -4,27 +4,7 @@ export declare function addTheme(props: {
4
4
  theme: Partial<Record<keyof ThemeDefinition, any>>;
5
5
  insertCSS?: boolean;
6
6
  }): {
7
- theme: {
8
- [x: string]: import("@tamagui/web").Variable<any>;
9
- background?: import("@tamagui/web").Variable<any> | undefined;
10
- backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
11
- backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
12
- backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
13
- color?: import("@tamagui/web").Variable<any> | undefined;
14
- colorHover?: import("@tamagui/web").Variable<any> | undefined;
15
- colorPress?: import("@tamagui/web").Variable<any> | undefined;
16
- colorFocus?: import("@tamagui/web").Variable<any> | undefined;
17
- borderColor?: import("@tamagui/web").Variable<any> | undefined;
18
- borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
19
- borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
20
- borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
21
- shadowColor?: import("@tamagui/web").Variable<any> | undefined;
22
- shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
23
- shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
24
- shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
25
- };
26
- cssRules?: undefined;
27
- } | {
7
+ themeRaw: ThemeParsed;
28
8
  theme: ThemeParsed;
29
9
  cssRules: string[];
30
10
  } | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"addTheme.d.ts","sourceRoot":"","sources":["../src/addTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAIhE,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;;;;;;;;;;;;;;;;;;;;;;;;cAEA"}
1
+ {"version":3,"file":"addTheme.d.ts","sourceRoot":"","sources":["../src/addTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAIhE,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;;;;cAEA"}
package/types/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './addTheme';
2
2
  export * from './updateTheme';
3
3
  export * from './replaceTheme';
4
+ export { mutateThemes } from './_mutateTheme';
5
+ export type { MutateOneThemeProps } from './_mutateTheme';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA"}
@@ -3,27 +3,7 @@ export declare function replaceTheme({ name, theme, }: {
3
3
  name: string;
4
4
  theme: Partial<Record<keyof ThemeDefinition, any>>;
5
5
  }): {
6
- theme: {
7
- [x: string]: import("@tamagui/web").Variable<any>;
8
- background?: import("@tamagui/web").Variable<any> | undefined;
9
- backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
10
- backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
11
- backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
12
- color?: import("@tamagui/web").Variable<any> | undefined;
13
- colorHover?: import("@tamagui/web").Variable<any> | undefined;
14
- colorPress?: import("@tamagui/web").Variable<any> | undefined;
15
- colorFocus?: import("@tamagui/web").Variable<any> | undefined;
16
- borderColor?: import("@tamagui/web").Variable<any> | undefined;
17
- borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
18
- borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
19
- borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
20
- shadowColor?: import("@tamagui/web").Variable<any> | undefined;
21
- shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
22
- shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
23
- shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
24
- };
25
- cssRules?: undefined;
26
- } | {
6
+ themeRaw: import("@tamagui/web").ThemeParsed;
27
7
  theme: import("@tamagui/web").ThemeParsed;
28
8
  cssRules: string[];
29
9
  } | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"replaceTheme.d.ts","sourceRoot":"","sources":["../src/replaceTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;cAGA"}
1
+ {"version":3,"file":"replaceTheme.d.ts","sourceRoot":"","sources":["../src/replaceTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;cAGA"}
@@ -3,27 +3,7 @@ export declare function updateTheme({ name, theme, }: {
3
3
  name: ThemeName | (string & {});
4
4
  theme: Partial<Record<keyof ThemeDefinition, any>>;
5
5
  }): {
6
- theme: {
7
- [x: string]: import("@tamagui/web").Variable<any>;
8
- background?: import("@tamagui/web").Variable<any> | undefined;
9
- backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
10
- backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
11
- backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
12
- color?: import("@tamagui/web").Variable<any> | undefined;
13
- colorHover?: import("@tamagui/web").Variable<any> | undefined;
14
- colorPress?: import("@tamagui/web").Variable<any> | undefined;
15
- colorFocus?: import("@tamagui/web").Variable<any> | undefined;
16
- borderColor?: import("@tamagui/web").Variable<any> | undefined;
17
- borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
18
- borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
19
- borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
20
- shadowColor?: import("@tamagui/web").Variable<any> | undefined;
21
- shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
22
- shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
23
- shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
24
- };
25
- cssRules?: undefined;
26
- } | {
6
+ themeRaw: import("@tamagui/web").ThemeParsed;
27
7
  theme: import("@tamagui/web").ThemeParsed;
28
8
  cssRules: string[];
29
9
  } | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"updateTheme.d.ts","sourceRoot":"","sources":["../src/updateTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAI9D,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IAC/B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;cAEA"}
1
+ {"version":3,"file":"updateTheme.d.ts","sourceRoot":"","sources":["../src/updateTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAI9D,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IAC/B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;cAEA"}