@tamagui/theme 1.15.25 → 1.15.26

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 (66) hide show
  1. package/dist/cjs/_mutateTheme.js +90 -0
  2. package/dist/cjs/_mutateTheme.js.map +6 -0
  3. package/dist/cjs/addTheme.js +2 -46
  4. package/dist/cjs/addTheme.js.map +2 -2
  5. package/dist/cjs/index.js +3 -1
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/replaceTheme.js +47 -0
  8. package/dist/cjs/replaceTheme.js.map +6 -0
  9. package/dist/cjs/updateTheme.js +3 -3
  10. package/dist/cjs/updateTheme.js.map +1 -1
  11. package/dist/esm/_mutateTheme.js +72 -0
  12. package/dist/esm/_mutateTheme.js.map +6 -0
  13. package/dist/esm/_mutateTheme.mjs +72 -0
  14. package/dist/esm/_mutateTheme.mjs.map +6 -0
  15. package/dist/esm/addTheme.js +2 -52
  16. package/dist/esm/addTheme.js.map +2 -2
  17. package/dist/esm/addTheme.mjs +2 -52
  18. package/dist/esm/addTheme.mjs.map +2 -2
  19. package/dist/esm/index.js +1 -0
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/index.mjs +1 -0
  22. package/dist/esm/index.mjs.map +1 -1
  23. package/dist/esm/replaceTheme.js +23 -0
  24. package/dist/esm/replaceTheme.js.map +6 -0
  25. package/dist/esm/replaceTheme.mjs +23 -0
  26. package/dist/esm/replaceTheme.mjs.map +6 -0
  27. package/dist/esm/updateTheme.js +3 -3
  28. package/dist/esm/updateTheme.js.map +1 -1
  29. package/dist/esm/updateTheme.mjs +3 -3
  30. package/dist/esm/updateTheme.mjs.map +1 -1
  31. package/dist/jsx/_mutateTheme.js +71 -0
  32. package/dist/jsx/_mutateTheme.js.map +6 -0
  33. package/dist/jsx/_mutateTheme.mjs +71 -0
  34. package/dist/jsx/_mutateTheme.mjs.map +6 -0
  35. package/dist/jsx/addTheme.js +2 -51
  36. package/dist/jsx/addTheme.js.map +2 -2
  37. package/dist/jsx/addTheme.mjs +2 -51
  38. package/dist/jsx/addTheme.mjs.map +2 -2
  39. package/dist/jsx/index.js +1 -0
  40. package/dist/jsx/index.js.map +1 -1
  41. package/dist/jsx/index.mjs +1 -0
  42. package/dist/jsx/index.mjs.map +1 -1
  43. package/dist/jsx/replaceTheme.js +23 -0
  44. package/dist/jsx/replaceTheme.js.map +6 -0
  45. package/dist/jsx/replaceTheme.mjs +23 -0
  46. package/dist/jsx/replaceTheme.mjs.map +6 -0
  47. package/dist/jsx/updateTheme.js +3 -3
  48. package/dist/jsx/updateTheme.js.map +1 -1
  49. package/dist/jsx/updateTheme.mjs +3 -3
  50. package/dist/jsx/updateTheme.mjs.map +1 -1
  51. package/package.json +4 -4
  52. package/src/_mutateTheme.ts +84 -0
  53. package/src/addTheme.ts +3 -60
  54. package/src/index.ts +1 -0
  55. package/src/replaceTheme.ts +27 -0
  56. package/src/updateTheme.ts +3 -3
  57. package/types/_mutateTheme.d.ts +32 -0
  58. package/types/_mutateTheme.d.ts.map +1 -0
  59. package/types/addTheme.d.ts +1 -2
  60. package/types/addTheme.d.ts.map +1 -1
  61. package/types/index.d.ts +1 -0
  62. package/types/index.d.ts.map +1 -1
  63. package/types/replaceTheme.d.ts +30 -0
  64. package/types/replaceTheme.d.ts.map +1 -0
  65. package/types/updateTheme.d.ts +1 -1
  66. package/types/updateTheme.d.ts.map +1 -1
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var mutateTheme_exports = {};
20
+ __export(mutateTheme_exports, {
21
+ _mutateTheme: () => _mutateTheme
22
+ });
23
+ module.exports = __toCommonJS(mutateTheme_exports);
24
+ var import_constants = require("@tamagui/constants");
25
+ var import_web = require("@tamagui/web");
26
+ function _mutateTheme(props) {
27
+ var _a;
28
+ if (import_constants.isServer) {
29
+ if (process.env.NODE_ENV === "development") {
30
+ console.warn("Theme mutation is not supported on server side");
31
+ }
32
+ return;
33
+ }
34
+ const config = (0, import_web.getConfig)();
35
+ const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
36
+ if (process.env.NODE_ENV === "development") {
37
+ if (!config) {
38
+ throw new Error("No config");
39
+ }
40
+ const theme2 = config.themes[props.name];
41
+ if (mutationType && !theme2) {
42
+ throw new Error(
43
+ `${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
44
+ );
45
+ }
46
+ if (!props.mutationType && theme2) {
47
+ return { theme: theme2 };
48
+ }
49
+ }
50
+ const theme = {
51
+ ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
52
+ ...themeIn
53
+ };
54
+ for (const key in theme) {
55
+ (0, import_web.ensureThemeVariable)(theme, key);
56
+ }
57
+ const themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme, config.themes);
58
+ config.themes[themeName] = themeProxied;
59
+ let cssRules = [];
60
+ if (import_constants.isWeb) {
61
+ if (insertCSS) {
62
+ cssRules = (0, import_web.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
+ (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
77
+ }
78
+ }
79
+ }
80
+ (0, import_web.updateConfig)("themes", { ...config.themes, [themeName]: themeProxied });
81
+ return {
82
+ theme: themeProxied,
83
+ cssRules
84
+ };
85
+ }
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ _mutateTheme
89
+ });
90
+ //# sourceMappingURL=_mutateTheme.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/_mutateTheme.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAgC;AAChC,iBAMO;AAGA,SAAS,aAAa,OAK1B;AAfH;AAgBE,MAAI,2BAAU;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,gDAAgD;AAAA,IAC/D;AACA;AAAA,EACF;AACA,QAAM,aAAS,sBAAU;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,gBAAgBA,QAAO;AAChC,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,QAAQ;AAAA,IACZ,GAAI,iBAAiB,WAAW,OAAO,OAAO,SAAS,KAAK,CAAC,IAAI,CAAC;AAAA,IAClE,GAAG;AAAA,EACL;AACA,aAAW,OAAO,OAAO;AACvB,wCAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,mBAAe,gCAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,wBAAO;AACT,QAAI,WAAW;AACb,qBAAW,6BAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,+BAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
5
+ "names": ["theme"]
6
+ }
@@ -21,53 +21,9 @@ __export(addTheme_exports, {
21
21
  addTheme: () => addTheme
22
22
  });
23
23
  module.exports = __toCommonJS(addTheme_exports);
24
- var import_constants = require("@tamagui/constants");
25
- var import_web = require("@tamagui/web");
24
+ var import_mutateTheme = require("./_mutateTheme");
26
25
  function addTheme(props) {
27
- var _a;
28
- const config = (0, import_web.getConfig)();
29
- if (process.env.NODE_ENV === "development") {
30
- if (!config) {
31
- throw new Error("No config");
32
- }
33
- const theme2 = config.themes[props.name];
34
- if (!props.update && theme2) {
35
- return { theme: theme2 };
36
- }
37
- }
38
- const { name: themeName, theme: themeIn, insertCSS } = props;
39
- const theme = { ...themeIn };
40
- for (const key in theme) {
41
- (0, import_web.ensureThemeVariable)(theme, key);
42
- }
43
- const themeProxied = (0, import_web.proxyThemeToParents)(themeName, theme, config.themes);
44
- config.themes[themeName] = themeProxied;
45
- let cssRules = [];
46
- if (import_constants.isWeb) {
47
- if (insertCSS) {
48
- cssRules = (0, import_web.getThemeCSSRules)({
49
- // @ts-ignore this works but should be fixed types
50
- config,
51
- themeName,
52
- names: [themeName],
53
- theme
54
- });
55
- const id = `t_theme_style_${themeName}`;
56
- const existing = document.querySelector(`#${id}`);
57
- const style = document.createElement("style");
58
- style.id = id;
59
- style.appendChild(document.createTextNode(cssRules.join("\n")));
60
- document.head.appendChild(style);
61
- if (existing) {
62
- (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
63
- }
64
- }
65
- }
66
- (0, import_web.updateConfig)("themes", { ...config.themes, [themeName]: themeProxied });
67
- return {
68
- theme: themeProxied,
69
- cssRules
70
- };
26
+ return (0, import_mutateTheme._mutateTheme)({ ...props });
71
27
  }
72
28
  // Annotate the CommonJS export names for ESM import in node:
73
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;AAAA,uBAAsB;AACtB,iBAMO;AAGA,SAAS,SAAS,OAKtB;AAfH;AAgBE,QAAM,aAAS,sBAAU;AAEzB,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,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wCAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,mBAAe,gCAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,wBAAO;AACT,QAAI,WAAW;AACb,qBAAW,6BAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,+BAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
5
- "names": ["theme"]
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAA6B;AAEtB,SAAS,SAAS,OAItB;AACD,aAAO,iCAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
5
+ "names": []
6
6
  }
package/dist/cjs/index.js CHANGED
@@ -17,9 +17,11 @@ var src_exports = {};
17
17
  module.exports = __toCommonJS(src_exports);
18
18
  __reExport(src_exports, require("./addTheme"), module.exports);
19
19
  __reExport(src_exports, require("./updateTheme"), module.exports);
20
+ __reExport(src_exports, require("./replaceTheme"), module.exports);
20
21
  // Annotate the CommonJS export names for ESM import in node:
21
22
  0 && (module.exports = {
22
23
  ...require("./addTheme"),
23
- ...require("./updateTheme")
24
+ ...require("./updateTheme"),
25
+ ...require("./replaceTheme")
24
26
  });
25
27
  //# sourceMappingURL=index.js.map
@@ -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;",
4
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,uBAAd;AACA,wBAAc,0BADd;AAEA,wBAAc,2BAFd;",
5
5
  "names": []
6
6
  }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var replaceTheme_exports = {};
20
+ __export(replaceTheme_exports, {
21
+ replaceTheme: () => replaceTheme
22
+ });
23
+ module.exports = __toCommonJS(replaceTheme_exports);
24
+ var import_web = require("@tamagui/web");
25
+ var import_mutateTheme = require("./_mutateTheme.js");
26
+ function replaceTheme({
27
+ name,
28
+ theme
29
+ }) {
30
+ const next = (0, import_mutateTheme._mutateTheme)({ name, theme, insertCSS: true, mutationType: "replace" });
31
+ if (process.env.TAMAGUI_TARGET === "native") {
32
+ import_web.activeThemeManagers.forEach((manager) => {
33
+ if (manager.state.name === name) {
34
+ manager.updateState({
35
+ name,
36
+ forceTheme: next == null ? void 0 : next.theme
37
+ });
38
+ }
39
+ });
40
+ }
41
+ return next;
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ replaceTheme
46
+ });
47
+ //# sourceMappingURL=replaceTheme.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/replaceTheme.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AAGpC,yBAA6B;AAEtB,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,QAAM,WAAO,iCAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,UAAU,CAAC;AAEnF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,mCAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,6BAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
5
+ "names": []
6
+ }
@@ -22,18 +22,18 @@ __export(updateTheme_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(updateTheme_exports);
24
24
  var import_web = require("@tamagui/web");
25
- var import_addTheme = require("./addTheme.js");
25
+ var import_mutateTheme = require("./_mutateTheme.js");
26
26
  function updateTheme({
27
27
  name,
28
28
  theme
29
29
  }) {
30
- const next = (0, import_addTheme.addTheme)({ name, theme, insertCSS: true, update: true });
30
+ const next = (0, import_mutateTheme._mutateTheme)({ name, theme, insertCSS: true, mutationType: "update" });
31
31
  if (process.env.TAMAGUI_TARGET === "native") {
32
32
  import_web.activeThemeManagers.forEach((manager) => {
33
33
  if (manager.state.name === name) {
34
34
  manager.updateState({
35
35
  name,
36
- forceTheme: next.theme
36
+ forceTheme: next == null ? void 0 : next.theme
37
37
  });
38
38
  }
39
39
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/updateTheme.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AAGpC,sBAAyB;AAElB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,WAAO,0BAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,mCAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,KAAK;AAAA,QACnB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AAGpC,yBAA6B;AAEtB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AACF,GAGG;AACD,QAAM,WAAO,iCAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,SAAS,CAAC;AAElF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,mCAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,6BAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
5
5
  "names": []
6
6
  }
@@ -0,0 +1,72 @@
1
+ import { isServer, isWeb } from "@tamagui/constants";
2
+ import {
3
+ ensureThemeVariable,
4
+ getConfig,
5
+ getThemeCSSRules,
6
+ proxyThemeToParents,
7
+ updateConfig
8
+ } from "@tamagui/web";
9
+ function _mutateTheme(props) {
10
+ var _a;
11
+ if (isServer) {
12
+ if (process.env.NODE_ENV === "development") {
13
+ console.warn("Theme mutation is not supported on server side");
14
+ }
15
+ return;
16
+ }
17
+ const config = getConfig();
18
+ const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
19
+ if (process.env.NODE_ENV === "development") {
20
+ if (!config) {
21
+ throw new Error("No config");
22
+ }
23
+ const theme2 = config.themes[props.name];
24
+ if (mutationType && !theme2) {
25
+ throw new Error(
26
+ `${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
27
+ );
28
+ }
29
+ if (!props.mutationType && theme2) {
30
+ return { theme: theme2 };
31
+ }
32
+ }
33
+ const theme = {
34
+ ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
35
+ ...themeIn
36
+ };
37
+ for (const key in theme) {
38
+ ensureThemeVariable(theme, key);
39
+ }
40
+ const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
41
+ config.themes[themeName] = themeProxied;
42
+ let cssRules = [];
43
+ if (isWeb) {
44
+ if (insertCSS) {
45
+ cssRules = getThemeCSSRules({
46
+ // @ts-ignore this works but should be fixed types
47
+ config,
48
+ themeName,
49
+ names: [themeName],
50
+ theme
51
+ });
52
+ const id = `t_theme_style_${themeName}`;
53
+ const existing = document.querySelector(`#${id}`);
54
+ const style = document.createElement("style");
55
+ style.id = id;
56
+ style.appendChild(document.createTextNode(cssRules.join("\n")));
57
+ document.head.appendChild(style);
58
+ if (existing) {
59
+ (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
60
+ }
61
+ }
62
+ }
63
+ updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
64
+ return {
65
+ theme: themeProxied,
66
+ cssRules
67
+ };
68
+ }
69
+ export {
70
+ _mutateTheme
71
+ };
72
+ //# sourceMappingURL=_mutateTheme.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/_mutateTheme.ts"],
4
+ "mappings": "AAAA,SAAS,UAAU,aAAa;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,aAAa,OAK1B;AAfH;AAgBE,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,gBAAgBA,QAAO;AAChC,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,QAAQ;AAAA,IACZ,GAAI,iBAAiB,WAAW,OAAO,OAAO,SAAS,KAAK,CAAC,IAAI,CAAC;AAAA,IAClE,GAAG;AAAA,EACL;AACA,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
5
+ "names": ["theme"]
6
+ }
@@ -0,0 +1,72 @@
1
+ import { isServer, isWeb } from "@tamagui/constants";
2
+ import {
3
+ ensureThemeVariable,
4
+ getConfig,
5
+ getThemeCSSRules,
6
+ proxyThemeToParents,
7
+ updateConfig
8
+ } from "@tamagui/web";
9
+ function _mutateTheme(props) {
10
+ var _a;
11
+ if (isServer) {
12
+ if (process.env.NODE_ENV === "development") {
13
+ console.warn("Theme mutation is not supported on server side");
14
+ }
15
+ return;
16
+ }
17
+ const config = getConfig();
18
+ const { name: themeName, theme: themeIn, insertCSS, mutationType } = props;
19
+ if (process.env.NODE_ENV === "development") {
20
+ if (!config) {
21
+ throw new Error("No config");
22
+ }
23
+ const theme2 = config.themes[props.name];
24
+ if (mutationType && !theme2) {
25
+ throw new Error(
26
+ `${mutationType === "replace" ? "Replace" : "Update"} theme failed! Theme ${props.name} does not exist`
27
+ );
28
+ }
29
+ if (!props.mutationType && theme2) {
30
+ return { theme: theme2 };
31
+ }
32
+ }
33
+ const theme = {
34
+ ...mutationType === "update" ? config.themes[themeName] ?? {} : {},
35
+ ...themeIn
36
+ };
37
+ for (const key in theme) {
38
+ ensureThemeVariable(theme, key);
39
+ }
40
+ const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
41
+ config.themes[themeName] = themeProxied;
42
+ let cssRules = [];
43
+ if (isWeb) {
44
+ if (insertCSS) {
45
+ cssRules = getThemeCSSRules({
46
+ // @ts-ignore this works but should be fixed types
47
+ config,
48
+ themeName,
49
+ names: [themeName],
50
+ theme
51
+ });
52
+ const id = `t_theme_style_${themeName}`;
53
+ const existing = document.querySelector(`#${id}`);
54
+ const style = document.createElement("style");
55
+ style.id = id;
56
+ style.appendChild(document.createTextNode(cssRules.join("\n")));
57
+ document.head.appendChild(style);
58
+ if (existing) {
59
+ (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
60
+ }
61
+ }
62
+ }
63
+ updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
64
+ return {
65
+ theme: themeProxied,
66
+ cssRules
67
+ };
68
+ }
69
+ export {
70
+ _mutateTheme
71
+ };
72
+ //# sourceMappingURL=_mutateTheme.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/_mutateTheme.ts"],
4
+ "mappings": "AAAA,SAAS,UAAU,aAAa;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,aAAa,OAK1B;AAfH;AAgBE,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,gBAAgBA,QAAO;AAChC,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,QAAQ;AAAA,IACZ,GAAI,iBAAiB,WAAW,OAAO,OAAO,SAAS,KAAK,CAAC,IAAI,CAAC;AAAA,IAClE,GAAG;AAAA,EACL;AACA,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
5
+ "names": ["theme"]
6
+ }
@@ -1,56 +1,6 @@
1
- import { isWeb } from "@tamagui/constants";
2
- import {
3
- ensureThemeVariable,
4
- getConfig,
5
- getThemeCSSRules,
6
- proxyThemeToParents,
7
- updateConfig
8
- } from "@tamagui/web";
1
+ import { _mutateTheme } from "./_mutateTheme";
9
2
  function addTheme(props) {
10
- var _a;
11
- const config = getConfig();
12
- if (process.env.NODE_ENV === "development") {
13
- if (!config) {
14
- throw new Error("No config");
15
- }
16
- const theme2 = config.themes[props.name];
17
- if (!props.update && theme2) {
18
- return { theme: theme2 };
19
- }
20
- }
21
- const { name: themeName, theme: themeIn, insertCSS } = props;
22
- const theme = { ...themeIn };
23
- for (const key in theme) {
24
- ensureThemeVariable(theme, key);
25
- }
26
- const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
27
- config.themes[themeName] = themeProxied;
28
- let cssRules = [];
29
- if (isWeb) {
30
- if (insertCSS) {
31
- cssRules = getThemeCSSRules({
32
- // @ts-ignore this works but should be fixed types
33
- config,
34
- themeName,
35
- names: [themeName],
36
- theme
37
- });
38
- const id = `t_theme_style_${themeName}`;
39
- const existing = document.querySelector(`#${id}`);
40
- const style = document.createElement("style");
41
- style.id = id;
42
- style.appendChild(document.createTextNode(cssRules.join("\n")));
43
- document.head.appendChild(style);
44
- if (existing) {
45
- (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
46
- }
47
- }
48
- }
49
- updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
50
- return {
51
- theme: themeProxied,
52
- cssRules
53
- };
3
+ return _mutateTheme({ ...props });
54
4
  }
55
5
  export {
56
6
  addTheme
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/addTheme.ts"],
4
- "mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,SAAS,OAKtB;AAfH;AAgBE,QAAM,SAAS,UAAU;AAEzB,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,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
5
- "names": ["theme"]
4
+ "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
5
+ "names": []
6
6
  }
@@ -1,56 +1,6 @@
1
- import { isWeb } from "@tamagui/constants";
2
- import {
3
- ensureThemeVariable,
4
- getConfig,
5
- getThemeCSSRules,
6
- proxyThemeToParents,
7
- updateConfig
8
- } from "@tamagui/web";
1
+ import { _mutateTheme } from "./_mutateTheme";
9
2
  function addTheme(props) {
10
- var _a;
11
- const config = getConfig();
12
- if (process.env.NODE_ENV === "development") {
13
- if (!config) {
14
- throw new Error("No config");
15
- }
16
- const theme2 = config.themes[props.name];
17
- if (!props.update && theme2) {
18
- return { theme: theme2 };
19
- }
20
- }
21
- const { name: themeName, theme: themeIn, insertCSS } = props;
22
- const theme = { ...themeIn };
23
- for (const key in theme) {
24
- ensureThemeVariable(theme, key);
25
- }
26
- const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
27
- config.themes[themeName] = themeProxied;
28
- let cssRules = [];
29
- if (isWeb) {
30
- if (insertCSS) {
31
- cssRules = getThemeCSSRules({
32
- // @ts-ignore this works but should be fixed types
33
- config,
34
- themeName,
35
- names: [themeName],
36
- theme
37
- });
38
- const id = `t_theme_style_${themeName}`;
39
- const existing = document.querySelector(`#${id}`);
40
- const style = document.createElement("style");
41
- style.id = id;
42
- style.appendChild(document.createTextNode(cssRules.join("\n")));
43
- document.head.appendChild(style);
44
- if (existing) {
45
- (_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
46
- }
47
- }
48
- }
49
- updateConfig("themes", { ...config.themes, [themeName]: themeProxied });
50
- return {
51
- theme: themeProxied,
52
- cssRules
53
- };
3
+ return _mutateTheme({ ...props });
54
4
  }
55
5
  export {
56
6
  addTheme
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/addTheme.ts"],
4
- "mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,SAAS,OAKtB;AAfH;AAgBE,QAAM,SAAS,UAAU;AAEzB,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,CAAC,MAAM,UAAUA,QAAO;AAC1B,aAAO,EAAE,OAAAA,OAAM;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI;AACvD,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,SAAS,IAAI;AAE3B,MAAI,WAAqB,CAAC;AAE1B,MAAI,OAAO;AACT,QAAI,WAAW;AACb,iBAAW,iBAAiB;AAAA;AAAA,QAE1B;AAAA,QACA;AAAA,QACA,OAAO,CAAC,SAAS;AAAA,QACjB;AAAA,MACF,CAAC;AACD,YAAM,KAAK,iBAAiB;AAC5B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAEA,eAAa,UAAU,EAAE,GAAG,OAAO,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC;AAGtE,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
5
- "names": ["theme"]
4
+ "mappings": "AAEA,SAAS,oBAAoB;AAEtB,SAAS,SAAS,OAItB;AACD,SAAO,aAAa,EAAE,GAAG,MAAM,CAAC;AAClC;",
5
+ "names": []
6
6
  }
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./addTheme";
2
2
  export * from "./updateTheme";
3
+ export * from "./replaceTheme";
3
4
  //# 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;",
4
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
5
5
  "names": []
6
6
  }
@@ -1,3 +1,4 @@
1
1
  export * from "./addTheme";
2
2
  export * from "./updateTheme";
3
+ export * from "./replaceTheme";
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "mappings": "AAAA,cAAc;AACd,cAAc;",
4
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
5
5
  "names": []
6
6
  }
@@ -0,0 +1,23 @@
1
+ import { activeThemeManagers } from "@tamagui/web";
2
+ import { _mutateTheme } from "./_mutateTheme.js";
3
+ function replaceTheme({
4
+ name,
5
+ theme
6
+ }) {
7
+ const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: "replace" });
8
+ if (process.env.TAMAGUI_TARGET === "native") {
9
+ activeThemeManagers.forEach((manager) => {
10
+ if (manager.state.name === name) {
11
+ manager.updateState({
12
+ name,
13
+ forceTheme: next == null ? void 0 : next.theme
14
+ });
15
+ }
16
+ });
17
+ }
18
+ return next;
19
+ }
20
+ export {
21
+ replaceTheme
22
+ };
23
+ //# sourceMappingURL=replaceTheme.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/replaceTheme.ts"],
4
+ "mappings": "AAAA,SAAS,2BAA2B;AAGpC,SAAS,oBAAoB;AAEtB,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,QAAM,OAAO,aAAa,EAAE,MAAM,OAAO,WAAW,MAAM,cAAc,UAAU,CAAC;AAEnF,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,MAAM,SAAS,MAAM;AAC/B,gBAAQ,YAAY;AAAA,UAClB;AAAA,UACA,YAAY,6BAAM;AAAA,QACpB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
5
+ "names": []
6
+ }