@tamagui/core 1.0.1-beta.135 → 1.0.1-beta.138

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 (113) hide show
  1. package/dist/cjs/addTheme.js +74 -0
  2. package/dist/cjs/addTheme.js.map +7 -0
  3. package/dist/cjs/contexts/TextAncestorContext.js +44 -0
  4. package/dist/cjs/contexts/TextAncestorContext.js.map +7 -0
  5. package/dist/cjs/contexts/ThemeContext.js +30 -0
  6. package/dist/cjs/contexts/ThemeContext.js.map +7 -0
  7. package/dist/cjs/createComponent.js +2 -2
  8. package/dist/cjs/createComponent.js.map +2 -2
  9. package/dist/cjs/createTamagui.js +18 -118
  10. package/dist/cjs/createTamagui.js.map +2 -2
  11. package/dist/cjs/createTheme.js +2 -5
  12. package/dist/cjs/createTheme.js.map +2 -2
  13. package/dist/cjs/ensureThemeVariable.js +152 -0
  14. package/dist/cjs/ensureThemeVariable.js.map +7 -0
  15. package/dist/cjs/helpers/ThemeManager.js +209 -0
  16. package/dist/cjs/helpers/ThemeManager.js.map +7 -0
  17. package/dist/cjs/helpers/createTamaguiProvider.js +1 -1
  18. package/dist/cjs/helpers/createTamaguiProvider.js.map +2 -2
  19. package/dist/cjs/helpers/ensureThemeVariable.js +152 -0
  20. package/dist/cjs/helpers/ensureThemeVariable.js.map +7 -0
  21. package/dist/cjs/helpers/getThemeCSSRules.js +98 -0
  22. package/dist/cjs/helpers/getThemeCSSRules.js.map +7 -0
  23. package/dist/cjs/helpers/getThemeCSSRules.native.js +31 -0
  24. package/dist/cjs/helpers/getThemeCSSRules.native.js.map +7 -0
  25. package/dist/cjs/helpers/themes.js +79 -0
  26. package/dist/cjs/helpers/themes.js.map +7 -0
  27. package/dist/cjs/hooks/useTheme.js +20 -11
  28. package/dist/cjs/hooks/useTheme.js.map +2 -2
  29. package/dist/cjs/index.js +3 -1
  30. package/dist/cjs/index.js.map +2 -2
  31. package/dist/cjs/loadTheme.js +64 -0
  32. package/dist/cjs/loadTheme.js.map +7 -0
  33. package/dist/cjs/updateTheme.js +44 -0
  34. package/dist/cjs/updateTheme.js.map +7 -0
  35. package/dist/cjs/vendor/Pressability.js +32 -0
  36. package/dist/cjs/vendor/Pressability.js.map +7 -0
  37. package/dist/cjs/vendor/Pressability.native.js +32 -0
  38. package/dist/cjs/vendor/Pressability.native.js.map +7 -0
  39. package/dist/cjs/views/Theme.js +1 -1
  40. package/dist/cjs/views/Theme.js.map +2 -2
  41. package/dist/cjs/views/ThemeInverse.js +8 -12
  42. package/dist/cjs/views/ThemeInverse.js.map +2 -2
  43. package/dist/cjs/views/ThemeProvider.js +1 -1
  44. package/dist/cjs/views/ThemeProvider.js.map +1 -1
  45. package/dist/cjs/views/ThemeReset.js +1 -1
  46. package/dist/cjs/views/ThemeReset.js.map +1 -1
  47. package/dist/esm/addTheme.js +50 -0
  48. package/dist/esm/addTheme.js.map +7 -0
  49. package/dist/esm/contexts/TextAncestorContext.js +15 -0
  50. package/dist/esm/contexts/TextAncestorContext.js.map +7 -0
  51. package/dist/esm/contexts/ThemeContext.js +6 -0
  52. package/dist/esm/contexts/ThemeContext.js.map +7 -0
  53. package/dist/esm/createComponent.js +2 -2
  54. package/dist/esm/createComponent.js.map +1 -1
  55. package/dist/esm/createTamagui.js +17 -117
  56. package/dist/esm/createTamagui.js.map +2 -2
  57. package/dist/esm/createTheme.js +1 -3
  58. package/dist/esm/createTheme.js.map +2 -2
  59. package/dist/esm/ensureThemeVariable.js +125 -0
  60. package/dist/esm/ensureThemeVariable.js.map +7 -0
  61. package/dist/esm/helpers/ThemeManager.js +183 -0
  62. package/dist/esm/helpers/ThemeManager.js.map +7 -0
  63. package/dist/esm/helpers/createTamaguiProvider.js +1 -1
  64. package/dist/esm/helpers/createTamaguiProvider.js.map +2 -2
  65. package/dist/esm/helpers/ensureThemeVariable.js +125 -0
  66. package/dist/esm/helpers/ensureThemeVariable.js.map +7 -0
  67. package/dist/esm/helpers/getThemeCSSRules.js +74 -0
  68. package/dist/esm/helpers/getThemeCSSRules.js.map +7 -0
  69. package/dist/esm/helpers/getThemeCSSRules.native.js +7 -0
  70. package/dist/esm/helpers/getThemeCSSRules.native.js.map +7 -0
  71. package/dist/esm/helpers/themes.js +54 -0
  72. package/dist/esm/helpers/themes.js.map +7 -0
  73. package/dist/esm/hooks/useTheme.js +23 -11
  74. package/dist/esm/hooks/useTheme.js.map +2 -2
  75. package/dist/esm/index.js +3 -1
  76. package/dist/esm/index.js.map +2 -2
  77. package/dist/esm/loadTheme.js +40 -0
  78. package/dist/esm/loadTheme.js.map +7 -0
  79. package/dist/esm/updateTheme.js +20 -0
  80. package/dist/esm/updateTheme.js.map +7 -0
  81. package/dist/esm/vendor/Pressability.js +7 -0
  82. package/dist/esm/vendor/Pressability.js.map +7 -0
  83. package/dist/esm/vendor/Pressability.native.js +7 -0
  84. package/dist/esm/vendor/Pressability.native.js.map +7 -0
  85. package/dist/esm/views/Theme.js +1 -1
  86. package/dist/esm/views/Theme.js.map +1 -1
  87. package/dist/esm/views/ThemeInverse.js +7 -10
  88. package/dist/esm/views/ThemeInverse.js.map +2 -2
  89. package/dist/esm/views/ThemeProvider.js +1 -1
  90. package/dist/esm/views/ThemeProvider.js.map +1 -1
  91. package/dist/esm/views/ThemeReset.js +1 -1
  92. package/dist/esm/views/ThemeReset.js.map +1 -1
  93. package/package.json +8 -8
  94. package/types/addTheme.d.ts +11 -0
  95. package/types/{views → contexts}/TextAncestorContext.d.ts +0 -0
  96. package/types/{ThemeContext.d.ts → contexts/ThemeContext.d.ts} +1 -1
  97. package/types/createTheme.d.ts +0 -1
  98. package/types/{ThemeManager.d.ts → helpers/ThemeManager.d.ts} +5 -5
  99. package/types/helpers/createTamaguiProvider.d.ts +1 -0
  100. package/types/helpers/getThemeCSSRules.d.ts +8 -0
  101. package/types/helpers/getThemeCSSRules.native.d.ts +2 -0
  102. package/types/helpers/themes.d.ts +4 -0
  103. package/types/hooks/useTheme.d.ts +2 -1
  104. package/types/index.d.ts +3 -1
  105. package/types/updateTheme.d.ts +9 -0
  106. package/types/{Pressability.d.ts → vendor/Pressability.d.ts} +0 -0
  107. package/types/{Pressability.native.d.ts → vendor/Pressability.native.d.ts} +0 -0
  108. package/types/views/FontLanguage.d.ts +1 -0
  109. package/types/views/FontLanguage.native.d.ts +1 -0
  110. package/types/views/Theme.d.ts +1 -1
  111. package/types/views/ThemeInverse.d.ts +0 -5
  112. package/types/views/ThemeProvider.d.ts +1 -0
  113. package/types/defaultComponentState.d.ts +0 -1
@@ -0,0 +1,74 @@
1
+ import { THEME_CLASSNAME_PREFIX } from "../constants/constants";
2
+ import { tokensValueToVariable } from "./registerCSSVariable";
3
+ function getThemeCSSRules({
4
+ config,
5
+ themeName,
6
+ theme,
7
+ names
8
+ }) {
9
+ const cssRuleSets = [];
10
+ const hasDarkLight = "light" in config.themes && "dark" in config.themes;
11
+ const CNP = `.${THEME_CLASSNAME_PREFIX}`;
12
+ let vars = "";
13
+ for (const themeKey in theme) {
14
+ const variable = theme[themeKey];
15
+ let value = null;
16
+ if (variable.isFloating || !tokensValueToVariable.has(variable.val)) {
17
+ value = variable.val;
18
+ } else {
19
+ value = tokensValueToVariable.get(variable.val).variable;
20
+ }
21
+ vars += `--${themeKey}:${value};`;
22
+ }
23
+ const isDarkOrLightBase = themeName === "dark" || themeName === "light";
24
+ const selectors = names.map((name) => {
25
+ return `${CNP}${name}`;
26
+ });
27
+ if (hasDarkLight) {
28
+ for (const subName of names) {
29
+ const isDark = isDarkOrLightBase || subName.startsWith("dark_");
30
+ const max = config.maxDarkLightNesting ?? 3;
31
+ if (!isDark && !subName.startsWith("light_")) {
32
+ selectors.push(`:root:root ${CNP}${subName}`);
33
+ continue;
34
+ }
35
+ const childSelector = `${CNP}${subName.replace(isDark ? "dark_" : "light_", "")}`;
36
+ const order = isDark ? ["dark", "light"] : ["light", "dark"];
37
+ if (isDarkOrLightBase) {
38
+ order.reverse();
39
+ }
40
+ const [stronger, weaker] = order;
41
+ const numSelectors = Math.round(max * 1.5);
42
+ for (let pi = 0; pi < numSelectors; pi++) {
43
+ const isOdd = pi % 2 === 1;
44
+ if (isOdd && pi < 3)
45
+ continue;
46
+ const parents = new Array(pi + 1).fill(void 0).map((_, psi) => {
47
+ return `${CNP}${psi % 2 === 0 ? stronger : weaker}`;
48
+ });
49
+ let parentSelectors = parents.length > 1 ? parents.slice(1) : parents;
50
+ if (isOdd) {
51
+ const [_first, second, ...rest] = parentSelectors;
52
+ parentSelectors = [second, ...rest, second];
53
+ }
54
+ const lastParentSelector = parentSelectors[parentSelectors.length - 1];
55
+ selectors.push(`${parentSelectors.join(" ")} ${childSelector === lastParentSelector ? "" : childSelector}`);
56
+ }
57
+ }
58
+ }
59
+ const rootSep = config.themeClassNameOnRoot ? "" : " ";
60
+ const css = `${selectors.map((x) => `:root${rootSep}${x}`).join(", ")} {${vars}}`;
61
+ cssRuleSets.push(css);
62
+ if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {
63
+ const isDark = themeName.startsWith("dark");
64
+ cssRuleSets.push(`@media(prefers-color-scheme: ${isDark ? "dark" : "light"}) {
65
+ body { background:${theme.background}; color: ${theme.color} }
66
+ :root {${vars} }
67
+ }`);
68
+ }
69
+ return cssRuleSets;
70
+ }
71
+ export {
72
+ getThemeCSSRules
73
+ };
74
+ //# sourceMappingURL=getThemeCSSRules.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/getThemeCSSRules.ts"],
4
+ "sourcesContent": ["import { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { Variable } from '../createVariable'\nimport { CreateTamaguiProps, ThemeObject } from '../types'\nimport { tokensValueToVariable } from './registerCSSVariable'\n\nexport function getThemeCSSRules({\n config,\n themeName,\n theme,\n names,\n}: {\n config: CreateTamaguiProps\n themeName: string\n theme: ThemeObject\n names: string[]\n}) {\n const cssRuleSets: string[] = []\n\n // special case for SSR\n const hasDarkLight = 'light' in config.themes && 'dark' in config.themes\n const CNP = `.${THEME_CLASSNAME_PREFIX}`\n let vars = ''\n\n // themeToVariableToValueMap.set(theme, {})\n // const varToValMap = themeToVariableToValueMap.get(theme)\n for (const themeKey in theme) {\n const variable = theme[themeKey] as Variable\n let value: any = null\n // if (varToValMap) {\n // varToValMap[variable.variable] = variable.val\n // }\n if (variable.isFloating || !tokensValueToVariable.has(variable.val)) {\n value = variable.val\n } else {\n value = tokensValueToVariable.get(variable.val)!.variable\n }\n vars += `--${themeKey}:${value};`\n }\n\n const isDarkOrLightBase = themeName === 'dark' || themeName === 'light'\n const selectors = names.map((name) => {\n return `${CNP}${name}`\n })\n\n // since we dont specify dark/light in classnames we have to do an awkward specificity war\n // use config.maxDarkLightNesting to determine how deep you can nest until it breaks\n if (hasDarkLight) {\n for (const subName of names) {\n const isDark = isDarkOrLightBase || subName.startsWith('dark_')\n const max = config.maxDarkLightNesting ?? 3\n\n if (!isDark && !subName.startsWith('light_')) {\n // neither light nor dark subtheme, just generate one selector with :root:root which\n // will override all :root light/dark selectors generated below\n selectors.push(`:root:root ${CNP}${subName}`)\n continue\n }\n\n const childSelector = `${CNP}${subName.replace(isDark ? 'dark_' : 'light_', '')}`\n const order = isDark ? ['dark', 'light'] : ['light', 'dark']\n if (isDarkOrLightBase) {\n order.reverse()\n }\n const [stronger, weaker] = order\n const numSelectors = Math.round(max * 1.5)\n\n for (let pi = 0; pi < numSelectors; pi++) {\n const isOdd = pi % 2 === 1\n if (isOdd && pi < 3) continue\n const parents = new Array(pi + 1).fill(undefined).map((_, psi) => {\n return `${CNP}${psi % 2 === 0 ? stronger : weaker}`\n })\n let parentSelectors = parents.length > 1 ? parents.slice(1) : parents\n if (isOdd) {\n const [_first, second, ...rest] = parentSelectors\n parentSelectors = [second, ...rest, second]\n }\n // avoid .t_light .t_light at the end (make sure child is unique from last parent)\n const lastParentSelector = parentSelectors[parentSelectors.length - 1]\n selectors.push(\n `${parentSelectors.join(' ')} ${\n childSelector === lastParentSelector ? '' : childSelector\n }`\n )\n }\n }\n }\n\n const rootSep = config.themeClassNameOnRoot ? '' : ' '\n const css = `${selectors.map((x) => `:root${rootSep}${x}`).join(', ')} {${vars}}`\n cssRuleSets.push(css)\n\n if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {\n // add media prefers for dark/light base\n const isDark = themeName.startsWith('dark')\n cssRuleSets.push(\n `@media(prefers-color-scheme: ${isDark ? 'dark' : 'light'}) {\nbody { background:${theme.background}; color: ${theme.color} }\n:root {${vars} } \n}`\n )\n }\n\n return cssRuleSets\n}\n"],
5
+ "mappings": "AAAA;AAGA;AAEO,0BAA0B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAMC;AACD,QAAM,cAAwB,CAAC;AAG/B,QAAM,eAAe,WAAW,OAAO,UAAU,UAAU,OAAO;AAClE,QAAM,MAAM,IAAI;AAChB,MAAI,OAAO;AAIX,aAAW,YAAY,OAAO;AAC5B,UAAM,WAAW,MAAM;AACvB,QAAI,QAAa;AAIjB,QAAI,SAAS,cAAc,CAAC,sBAAsB,IAAI,SAAS,GAAG,GAAG;AACnE,cAAQ,SAAS;AAAA,IACnB,OAAO;AACL,cAAQ,sBAAsB,IAAI,SAAS,GAAG,EAAG;AAAA,IACnD;AACA,YAAQ,KAAK,YAAY;AAAA,EAC3B;AAEA,QAAM,oBAAoB,cAAc,UAAU,cAAc;AAChE,QAAM,YAAY,MAAM,IAAI,CAAC,SAAS;AACpC,WAAO,GAAG,MAAM;AAAA,EAClB,CAAC;AAID,MAAI,cAAc;AAChB,eAAW,WAAW,OAAO;AAC3B,YAAM,SAAS,qBAAqB,QAAQ,WAAW,OAAO;AAC9D,YAAM,MAAM,OAAO,uBAAuB;AAE1C,UAAI,CAAC,UAAU,CAAC,QAAQ,WAAW,QAAQ,GAAG;AAG5C,kBAAU,KAAK,cAAc,MAAM,SAAS;AAC5C;AAAA,MACF;AAEA,YAAM,gBAAgB,GAAG,MAAM,QAAQ,QAAQ,SAAS,UAAU,UA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
+ }
4
+ export {
5
+ getThemeCSSRules
6
+ };
7
+ //# sourceMappingURL=getThemeCSSRules.native.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/getThemeCSSRules.native.ts"],
4
+ "sourcesContent": ["export function getThemeCSSRules() {\n return []\n}\n"],
5
+ "mappings": "AAAO,4BAA4B;AACjC,SAAO,CAAC;AACV;",
6
+ "names": []
7
+ }
@@ -0,0 +1,54 @@
1
+ import { createVariable, isVariable } from "../createVariable";
2
+ import { GetThemeUnwrapped } from "../hooks/getThemeUnwrapped";
3
+ function ensureThemeVariable(theme, key) {
4
+ const val = theme[key];
5
+ const themeKey = key;
6
+ if (!isVariable(val)) {
7
+ theme[key] = createVariable({
8
+ key: themeKey,
9
+ name: themeKey,
10
+ val
11
+ });
12
+ } else {
13
+ if (val.name !== themeKey) {
14
+ theme[key] = createVariable({
15
+ key: val.name,
16
+ name: themeKey,
17
+ val: val.val
18
+ });
19
+ }
20
+ }
21
+ }
22
+ function proxyThemeToParents(themeName, theme, themes) {
23
+ const cur = [];
24
+ const parents = themeName.split("_").slice(0, -1).map((part) => {
25
+ cur.push(part);
26
+ return cur.join("_");
27
+ });
28
+ const hasParents = parents.length;
29
+ return new Proxy(theme, {
30
+ get(target, key) {
31
+ if (key === GetThemeUnwrapped) {
32
+ return theme;
33
+ }
34
+ if (!hasParents || Reflect.has(target, key)) {
35
+ return Reflect.get(target, key);
36
+ }
37
+ for (let i = parents.length - 1; i >= 0; i--) {
38
+ const parent = themes[parents[i]];
39
+ if (!parent) {
40
+ continue;
41
+ }
42
+ if (Reflect.has(parent, key)) {
43
+ return Reflect.get(parent, key);
44
+ }
45
+ }
46
+ return Reflect.get(target, key);
47
+ }
48
+ });
49
+ }
50
+ export {
51
+ ensureThemeVariable,
52
+ proxyThemeToParents
53
+ };
54
+ //# sourceMappingURL=themes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/themes.ts"],
4
+ "sourcesContent": ["import { createVariable, isVariable } from '../createVariable'\nimport { GetThemeUnwrapped } from '../hooks/getThemeUnwrapped'\nimport { CreateTamaguiProps } from '../types'\n\n// mutates, freeze after\n// shared by createTamagui so extracted here\nexport function ensureThemeVariable(theme: any, key: string) {\n const val = theme[key]\n const themeKey = key\n if (!isVariable(val)) {\n theme[key] = createVariable({\n key: themeKey,\n name: themeKey,\n val,\n })\n } else {\n if (val.name !== themeKey) {\n // rename to theme name\n theme[key] = createVariable({\n key: val.name,\n name: themeKey,\n val: val.val,\n })\n }\n }\n}\n\nexport function proxyThemeToParents(\n themeName: string,\n theme: any,\n themes: CreateTamaguiProps['themes']\n) {\n // we could test if this is better as just a straight object spread or fancier proxy\n const cur: string[] = []\n // if theme is dark_blue_alt1_Button\n // this will be the parent names in order: ['dark', 'dark_blue', 'dark_blue_alt1\"]\n const parents = themeName\n .split('_')\n .slice(0, -1)\n .map((part) => {\n cur.push(part)\n return cur.join('_')\n })\n\n const hasParents = parents.length\n\n // proxy fallback values to parent theme values\n return new Proxy(theme, {\n get(target, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (!hasParents || Reflect.has(target, key)) {\n return Reflect.get(target, key)\n }\n // check parents\n for (let i = parents.length - 1; i >= 0; i--) {\n const parent = themes[parents[i]]\n if (!parent) {\n continue\n }\n if (Reflect.has(parent, key)) {\n return Reflect.get(parent, key)\n }\n }\n return Reflect.get(target, key)\n },\n })\n}\n"],
5
+ "mappings": "AAAA;AACA;AAKO,6BAA6B,OAAY,KAAa;AAC3D,QAAM,MAAM,MAAM;AAClB,QAAM,WAAW;AACjB,MAAI,CAAC,WAAW,GAAG,GAAG;AACpB,UAAM,OAAO,eAAe;AAAA,MAC1B,KAAK;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,QAAI,IAAI,SAAS,UAAU;AAEzB,YAAM,OAAO,eAAe;AAAA,QAC1B,KAAK,IAAI;AAAA,QACT,MAAM;AAAA,QACN,KAAK,IAAI;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,6BACL,WACA,OACA,QACA;AAEA,QAAM,MAAgB,CAAC;AAGvB,QAAM,UAAU,UACb,MAAM,GAAG,EACT,MAAM,GAAG,EAAE,EACX,IAAI,CAAC,SAAS;AACb,QAAI,KAAK,IAAI;AACb,WAAO,IAAI,KAAK,GAAG;AAAA,EACrB,CAAC;AAEH,QAAM,aAAa,QAAQ;AAG3B,SAAO,IAAI,MAAM,OAAO;AAAA,IACtB,IAAI,QAAQ,KAAK;AACf,UAAI,QAAQ,mBAAmB;AAC7B,eAAO;AAAA,MACT;AACA,UAAI,CAAC,cAAc,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAC3C,eAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,MAChC;AAEA,eAAS,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;AAC5C,cAAM,SAAS,OAAO,QAAQ;AAC9B,YAAI,CAAC,QAAQ;AACX;AAAA,QACF;AACA,YAAI,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAC5B,iBAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,QAChC;AAAA,MACF;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -2,9 +2,13 @@ import { useForceUpdate } from "@tamagui/use-force-update";
2
2
  import { useContext, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { getConfig } from "../conf";
4
4
  import { isWeb, useIsomorphicLayoutEffect } from "../constants/platform";
5
+ import { ThemeContext } from "../contexts/ThemeContext";
5
6
  import { areEqualSets } from "../helpers/areEqualSets";
6
- import { ThemeContext } from "../ThemeContext";
7
- import { ThemeManager, ThemeManagerContext, emptyManager } from "../ThemeManager";
7
+ import {
8
+ ThemeManager,
9
+ ThemeManagerContext,
10
+ emptyManager
11
+ } from "../helpers/ThemeManager";
8
12
  import { GetThemeUnwrapped } from "./getThemeUnwrapped";
9
13
  import { useConstant } from "./useConstant";
10
14
  const useTheme = (themeName, componentName, props, forceUpdate) => {
@@ -31,13 +35,14 @@ const useTheme = (themeName, componentName, props, forceUpdate) => {
31
35
  themeManager == null ? void 0 : themeManager.track(st.uuid, st.keys);
32
36
  }
33
37
  });
34
- return useMemo(() => {
35
- if (!theme) {
36
- if (process.env.NODE_ENV === "development") {
37
- console.warn("No theme", { themeName, theme, componentName, className });
38
- }
39
- return themes[getConfig().defaultTheme || "light"];
38
+ const debugProp = props && props["debug"];
39
+ if (!theme) {
40
+ if (process.env.NODE_ENV === "development") {
41
+ console.warn("No theme", { themeName, theme, componentName, className });
40
42
  }
43
+ return themes[getConfig().defaultTheme || Object.keys(themes)[0]];
44
+ }
45
+ return useMemo(() => {
41
46
  return new Proxy(theme, {
42
47
  has(_, key) {
43
48
  if (typeof key === "string") {
@@ -72,14 +77,14 @@ const useTheme = (themeName, componentName, props, forceUpdate) => {
72
77
  }
73
78
  if (state.current.isRendering && !state.current.keys.has(key)) {
74
79
  state.current.keys.add(key);
75
- if (process.env.NODE_ENV === "development" && (props == null ? void 0 : props["debug"]) === "verbose") {
80
+ if (process.env.NODE_ENV === "development" && debugProp === "verbose") {
76
81
  console.log(" \u{1F538} tracking theme", key);
77
82
  }
78
83
  }
79
84
  return themeManager.getValue(key);
80
85
  }
81
86
  });
82
- }, [name, theme, className]);
87
+ }, [name, theme, componentName, className, debugProp]);
83
88
  };
84
89
  const GetThemeManager = Symbol();
85
90
  const getThemeManager = (theme) => {
@@ -106,6 +111,7 @@ const useDefaultThemeName = () => {
106
111
  var _a;
107
112
  return (_a = useContext(ThemeContext)) == null ? void 0 : _a.defaultTheme;
108
113
  };
114
+ const activeThemeManagers = /* @__PURE__ */ new Set();
109
115
  const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
110
116
  const debug = props && props["debug"];
111
117
  const parentManager = useContext(ThemeManagerContext) || emptyManager;
@@ -123,10 +129,11 @@ const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
123
129
  useLayoutEffect(() => {
124
130
  if (!themeManager)
125
131
  return;
132
+ activeThemeManagers.add(themeManager);
126
133
  if (next == null ? void 0 : next.name) {
127
134
  themeManager.update(next);
128
135
  }
129
- return parentManager.onChangeTheme(() => {
136
+ const disposeParentOnChange = parentManager.onChangeTheme(() => {
130
137
  const next2 = parentManager.getNextTheme(getThemeProps, debug);
131
138
  if (!next2)
132
139
  return;
@@ -134,6 +141,10 @@ const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
134
141
  forceUpdate();
135
142
  }
136
143
  });
144
+ return () => {
145
+ activeThemeManagers.delete(themeManager);
146
+ disposeParentOnChange();
147
+ };
137
148
  }, [themes, name, componentName, debug, next == null ? void 0 : next.name]);
138
149
  }
139
150
  return {
@@ -147,6 +158,7 @@ const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
147
158
  };
148
159
  };
149
160
  export {
161
+ activeThemeManagers,
150
162
  getThemeManager,
151
163
  useChangeThemeEffect,
152
164
  useDefaultThemeName,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useTheme.tsx"],
4
- "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../conf'\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport { ThemeContext } from '../ThemeContext'\nimport { GetNextThemeProps, ThemeManager, ThemeManagerContext, emptyManager } from '../ThemeManager'\nimport { ThemeName, ThemeObject } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useConstant } from './useConstant'\n\nexport type ThemeProps = {\n className?: string\n disableThemeClass?: boolean\n name: Exclude<ThemeName, number> | null\n componentName?: string\n children?: any\n reset?: boolean\n debug?: boolean | 'verbose'\n}\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nexport const useTheme = (\n themeName?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdate?: any\n): ThemeObject => {\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n console.log(' \uD83D\uDD39 useTheme', { themeName, componentName, name, className })\n }\n }\n\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = themeManager?.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n themeManager?.track(st.uuid, st.keys)\n }\n })\n\n return useMemo(() => {\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme', { themeName, theme, componentName, className })\n }\n return themes[getConfig().defaultTheme || 'light' || Object.keys(themes)[0]]\n }\n return new Proxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') {\n key = key.slice(1)\n }\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (key === GetThemeManager) {\n return themeManager\n }\n if (key === 'name') {\n return name\n }\n if (key === 'className') {\n return className\n }\n if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {\n return Reflect.get(_, key)\n }\n if (!themeManager) {\n console.error('No themeManager')\n return\n }\n // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (state.current.isRendering && !state.current.keys.has(key)) {\n state.current.keys.add(key)\n if (process.env.NODE_ENV === 'development' && props?.['debug'] === 'verbose') {\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n return themeManager.getValue(key)\n },\n })\n }, [name, theme, className])\n}\n\nconst GetThemeManager = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => {\n if (!theme) return\n return theme[GetThemeManager]\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent?.name || '')\n\n useIsomorphicLayoutEffect(() => {\n if (!parent) return\n return parent.onChangeTheme((next, manager) => {\n const name = opts?.parent ? manager.parentName || next : next\n if (!name) return\n setName(name)\n })\n }, [parent])\n\n return name\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)?.defaultTheme\n}\n\nexport const useChangeThemeEffect = (\n name?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdateProp?: any\n) => {\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const { themes } = useContext(ThemeContext)!\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = { name, componentName, themes, reset }\n const next = parentManager.getNextTheme(getThemeProps, debug)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const forceUpdate = forceUpdateProp || useForceUpdate()\n const themeManager = useConstant<ThemeManager | null>(() => {\n if (!next) return null\n return new ThemeManager(next.name, next.theme, parentManager, reset)\n })\n\n if (!isWeb || typeof document !== 'undefined') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n if (!themeManager) return\n if (next?.name) {\n themeManager.update(next)\n }\n return parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n forceUpdate()\n }\n })\n }, [themes, name, componentName, debug, next?.name])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n themes,\n themeManager,\n }\n}\n"],
5
- "mappings": "AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAkBO,MAAM,WAAW,CACtB,WACA,eACA,OACA,gBACgB;AAChB,QAAM,EAAE,MAAM,OAAO,QAAQ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EO,MAAM,uBAAuB,CAClC,MACA,eACA,OACA,oBACG;AACH,QAAM,QAAQ,SAAS,MAAM;AAC7B,QAAM,gBAAgB,WAAW,mBAAmB,KAAK;AACzD,QAAM,EAAE,WAAW,WAAW,YAAY;AAC1C,QAAM,QAAQ,gCAAO,UAAS;AAC9B,QAAM,gBAAmC,EAAE,MAAM,eAAe,QAAQ,MAAM;AAC9E,QAAM,OAAO,cAAc,aAAa,eAAe,KAAK;AAE5D,QAAM,cAAc,mBAAmB,eAAe;AACtD,QAAM,eAAe,YAAiC,MAAM;AAC1D,QAAI,CAAC;AAAM,aAAO;AAClB,WAAO,IAAI,aAAa,KAAK,MAAM,KAAK,OAAO,eAAe,KAAK;AAAA,EACrE,CAAC;AAED,MAAI,CAAC,SAAS,OAAO,aAAa,aAAa;AAE7C,oBAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,UAAI,6BAAM,MAAM;AACd,qBAAa,OAAO,IAAI;AAAA,MAC1B;AACA,aAAO,cAAc,cAAc,MAAM;AACvC,cAAM,QAAO,cAAc,aAAa,eAAe,KAAK;AAC5D,YAAI,CAAC;AAAM;AACX,YAAI,aAAa,OAAO,KAAI,GAAG;AAC7B,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAAA,IACH,GAAG,CAAC,QAAQ,MAAM,eAAe,OAAO,6BAAM,IAAI,CAAC;AAAA,EACrD;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../conf'\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport {\n GetNextThemeProps,\n ThemeManager,\n ThemeManagerContext,\n emptyManager,\n} from '../helpers/ThemeManager'\nimport { ThemeName, ThemeObject } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useConstant } from './useConstant'\n\nexport type ThemeProps = {\n className?: string\n disableThemeClass?: boolean\n name: Exclude<ThemeName, number> | null\n componentName?: string\n children?: any\n reset?: boolean\n debug?: boolean | 'verbose'\n}\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nexport const useTheme = (\n themeName?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdate?: any\n): ThemeObject => {\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n console.log(' \uD83D\uDD39 useTheme', { themeName, componentName, name, className })\n }\n }\n\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = themeManager?.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n themeManager?.track(st.uuid, st.keys)\n }\n })\n\n const debugProp = props && props['debug']\n\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme', { themeName, theme, componentName, className })\n }\n return themes[getConfig().defaultTheme || Object.keys(themes)[0]]\n }\n\n return useMemo(() => {\n return new Proxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') {\n key = key.slice(1)\n }\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (key === GetThemeManager) {\n return themeManager\n }\n if (key === 'name') {\n return name\n }\n if (key === 'className') {\n return className\n }\n if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {\n return Reflect.get(_, key)\n }\n if (!themeManager) {\n console.error('No themeManager')\n return\n }\n // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (state.current.isRendering && !state.current.keys.has(key)) {\n state.current.keys.add(key)\n if (process.env.NODE_ENV === 'development' && debugProp === 'verbose') {\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n return themeManager.getValue(key)\n },\n })\n }, [name, theme, componentName, className, debugProp])\n}\n\nconst GetThemeManager = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => {\n if (!theme) return\n return theme[GetThemeManager]\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent?.name || '')\n\n useIsomorphicLayoutEffect(() => {\n if (!parent) return\n return parent.onChangeTheme((next, manager) => {\n const name = opts?.parent ? manager.parentName || next : next\n if (!name) return\n setName(name)\n })\n }, [parent])\n\n return name\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)?.defaultTheme\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n name?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdateProp?: any\n) => {\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const { themes } = useContext(ThemeContext)!\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = { name, componentName, themes, reset }\n const next = parentManager.getNextTheme(getThemeProps, debug)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const forceUpdate = forceUpdateProp || useForceUpdate()\n\n const themeManager = useConstant<ThemeManager | null>(() => {\n if (!next) return null\n return new ThemeManager(next.name, next.theme, parentManager, reset)\n })\n\n // if not SSR\n if (!isWeb || typeof document !== 'undefined') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n if (next?.name) {\n themeManager.update(next)\n }\n\n const disposeParentOnChange = parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n forceUpdate()\n }\n })\n\n return () => {\n activeThemeManagers.delete(themeManager)\n disposeParentOnChange()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [themes, name, componentName, debug, next?.name])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n themes,\n themeManager,\n }\n}\n"],
5
+ "mappings": "AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAOA;AACA;AAkBO,MAAM,WAAW,CACtB,WACA,eACA,OACA,gBACgB;AAChB,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,cAAc,qBACvD,WACA,eACA,OACA,WACF;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,gCAAO,WAAU,WAAW;AAC9B,cAAQ,IAAI,wBAAiB,EAAE,WAAW,eAAe,MAAM,UAAU,CAAC;AAAA,IAC5E;AAAA,EACF;AAEA,QAAM,QAAQ,OAAO;AACrB,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AAAA,IACf;AAAA,EACF;AACA,QAAM,QAAQ,cAAc;AAG5B,4BAA0B,MAAM;AAC9B,UAAM,KAAK,MAAM;AACjB,OAAG,cAAc;AACjB,UAAM,MAAM,6CAAc,KAAK,IAAI,GAAG;AACtC,QAAI,CAAC,OAAO,CAAC,aAAa,GAAG,MAAM,GAAG,GAAG;AACvC,mDAAc,MAAM,GAAG,MAAM,GAAG;AAAA,IAClC;AAAA,EACF,CAAC;AAED,QAAM,YAAY,SAAS,MAAM;AAEjC,MAAI,CAAC,OAAO;AACV,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,YAAY,EAAE,W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,cAAc,cAAc,MAAM;AAC9D,cAAM,QAAO,cAAc,aAAa,eAAe,KAAK;AAC5D,YAAI,CAAC;AAAM;AACX,YAAI,aAAa,OAAO,KAAI,GAAG;AAC7B,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,aAAO,MAAM;AACX,4BAAoB,OAAO,YAAY;AACvC,8BAAsB;AAAA,MACxB;AAAA,IAEF,GAAG,CAAC,QAAQ,MAAM,eAAe,OAAO,6BAAM,IAAI,CAAC;AAAA,EACrD;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -8,6 +8,8 @@ export * from "./createTokens";
8
8
  export * from "./createVariable";
9
9
  export * from "./createVariables";
10
10
  export * from "./insertFont";
11
+ export * from "./addTheme";
12
+ export * from "./updateTheme";
11
13
  export * from "./styled";
12
14
  export * from "./types";
13
15
  import { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from "./conf";
@@ -46,7 +48,7 @@ export * from "./hooks/useUnmountEffect";
46
48
  export * from "./views/Slot";
47
49
  export * from "./views/Stack";
48
50
  export * from "./views/Text";
49
- import { TextAncestorProvider, TextAncestorContext } from "./views/TextAncestorContext";
51
+ import { TextAncestorProvider, TextAncestorContext } from "./contexts/TextAncestorContext";
50
52
  export * from "./views/Theme";
51
53
  export * from "./views/ThemeInverse";
52
54
  export * from "./views/ThemeProvider";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './styled'\nexport * from './types'\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './conf'\n\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport { createDOMProps } from '@tamagui/rnw'\n\nexport * from './helpers/calc'\nexport * from './helpers/createShallowUpdate'\nexport * from './helpers/getStackSize'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSize'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/pseudoDescriptors'\nexport * from './helpers/mergeProps'\nexport * from './helpers/expandStyles'\nexport * from './helpers/getFont'\nexport * from './helpers/isObj'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/startTransition'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonInsideButtonContext'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useId'\nexport * from './hooks/useIsMounted'\nexport * from './hooks/useIsTouchDevice'\nexport * from './hooks/useMedia'\nexport * from './hooks/usePressable'\nexport * from './hooks/useTheme'\nexport * from './hooks/useIsSSR'\nexport * from './hooks/useUnmountEffect'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport { TextAncestorProvider, TextAncestorContext } from './views/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/ThemeReset'\nexport * from './views/FontLanguage'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/helpers'\n"],
5
- "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;",
4
+ "sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './addTheme'\nexport * from './updateTheme'\nexport * from './styled'\nexport * from './types'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './conf'\n\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport { createDOMProps } from '@tamagui/rnw'\n\nexport * from './helpers/calc'\nexport * from './helpers/createShallowUpdate'\nexport * from './helpers/getStackSize'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSize'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/pseudoDescriptors'\nexport * from './helpers/mergeProps'\nexport * from './helpers/expandStyles'\nexport * from './helpers/getFont'\nexport * from './helpers/isObj'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/startTransition'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonInsideButtonContext'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useId'\nexport * from './hooks/useIsMounted'\nexport * from './hooks/useIsTouchDevice'\nexport * from './hooks/useMedia'\nexport * from './hooks/usePressable'\nexport * from './hooks/useTheme'\nexport * from './hooks/useIsSSR'\nexport * from './hooks/useUnmountEffect'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport { TextAncestorProvider, TextAncestorContext } from './contexts/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/ThemeReset'\nexport * from './views/FontLanguage'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/helpers'\n"],
5
+ "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,40 @@
1
+ import { getConfig } from "./conf";
2
+ import { ensureThemeVariable, getThemeCSSRules, proxyThemeToParents } from "./helpers/themes";
3
+ const loadTheme = ({
4
+ name: themeName,
5
+ theme: themeIn,
6
+ insertCSS
7
+ }) => {
8
+ const config = getConfig();
9
+ if (!config) {
10
+ throw new Error(`Must run createTamagui once before loading theme`);
11
+ }
12
+ if (config.themes[themeName]) {
13
+ throw new Error(`Already defined theme "${themeName}", use updateTheme to change values`);
14
+ }
15
+ const theme = { ...themeIn };
16
+ for (const key in theme) {
17
+ ensureThemeVariable(theme, key);
18
+ }
19
+ const cssRules = getThemeCSSRules({
20
+ config,
21
+ themeName,
22
+ names: [themeName],
23
+ theme
24
+ });
25
+ const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
26
+ config.themes[themeName] = themeProxied;
27
+ if (insertCSS && typeof document !== "undefined") {
28
+ const style = document.createElement("style");
29
+ style.appendChild(document.createTextNode(cssRules.join("\n")));
30
+ document.head.appendChild(style);
31
+ }
32
+ return {
33
+ theme: themeProxied,
34
+ cssRules
35
+ };
36
+ };
37
+ export {
38
+ loadTheme
39
+ };
40
+ //# sourceMappingURL=loadTheme.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/loadTheme.ts"],
4
+ "sourcesContent": ["import { getConfig } from './conf'\nimport { ensureThemeVariable, getThemeCSSRules, proxyThemeToParents } from './helpers/themes'\nimport { ThemeObject } from './types'\n\nexport const loadTheme = ({\n name: themeName,\n theme: themeIn,\n insertCSS,\n}: {\n name: string\n theme: ThemeObject\n insertCSS?: boolean\n}) => {\n const config = getConfig()\n if (!config) {\n throw new Error(`Must run createTamagui once before loading theme`)\n }\n if (config.themes[themeName]) {\n throw new Error(`Already defined theme \"${themeName}\", use updateTheme to change values`)\n }\n const theme = { ...themeIn }\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n const cssRules = getThemeCSSRules({\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n if (insertCSS && typeof document !== 'undefined') {\n const style = document.createElement('style')\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n }\n\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
5
+ "mappings": "AAAA;AACA;AAGO,MAAM,YAAY,CAAC;AAAA,EACxB,MAAM;AAAA,EACN,OAAO;AAAA,EACP;AAAA,MAKI;AACJ,QAAM,SAAS,UAAU;AACzB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AACA,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,IAAI,MAAM,0BAA0B,8CAA8C;AAAA,EAC1F;AACA,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AACA,QAAM,WAAW,iBAAiB;AAAA,IAChC;AAAA,IACA;AAAA,IACA,OAAO,CAAC,SAAS;AAAA,IACjB;AAAA,EACF,CAAC;AACD,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,aAAa;AAE3B,MAAI,aAAa,OAAO,aAAa,aAAa;AAChD,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,aAAS,KAAK,YAAY,KAAK;AAAA,EACjC;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,20 @@
1
+ import { addTheme } from "./addTheme";
2
+ import { activeThemeManagers } from "./hooks/useTheme";
3
+ function updateTheme({ name, theme }) {
4
+ const next = addTheme({ name, theme, insertCSS: true, update: true });
5
+ if (process.env.TAMAGUI_TARGET === "native") {
6
+ activeThemeManagers.forEach((manager) => {
7
+ if (manager.name === name) {
8
+ manager.update({
9
+ name,
10
+ theme: next.theme
11
+ }, true);
12
+ }
13
+ });
14
+ }
15
+ return next;
16
+ }
17
+ export {
18
+ updateTheme
19
+ };
20
+ //# sourceMappingURL=updateTheme.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/updateTheme.ts"],
4
+ "sourcesContent": ["import { addTheme } from './addTheme'\nimport { activeThemeManagers } from './hooks/useTheme'\nimport { ThemeObject } from './types'\n\nexport function updateTheme({ name, theme }: { name: string; theme: ThemeObject }) {\n const next = addTheme({ name, theme, insertCSS: true, update: true })\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n activeThemeManagers.forEach((manager) => {\n if (manager.name === name) {\n manager.update(\n {\n name,\n theme: next.theme,\n },\n true\n )\n }\n })\n }\n\n return next\n}\n"],
5
+ "mappings": "AAAA;AACA;AAGO,qBAAqB,EAAE,MAAM,SAA+C;AACjF,QAAM,OAAO,SAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,SAAS,MAAM;AACzB,gBAAQ,OACN;AAAA,UACE;AAAA,UACA,OAAO,KAAK;AAAA,QACd,GACA,IACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ const Pressability = {};
2
+ const usePressability = {};
3
+ export {
4
+ Pressability,
5
+ usePressability
6
+ };
7
+ //# sourceMappingURL=Pressability.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/vendor/Pressability.tsx"],
4
+ "sourcesContent": ["export const Pressability = {} as any\nexport const usePressability = {} as Function\n"],
5
+ "mappings": "AAAO,MAAM,eAAe,CAAC;AACtB,MAAM,kBAAkB,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ const Pressability = require("react-native/Libraries/Pressability/Pressability").default;
2
+ const usePressability = require("react-native/Libraries/Pressability/usePressability").default;
3
+ export {
4
+ Pressability,
5
+ usePressability
6
+ };
7
+ //# sourceMappingURL=Pressability.native.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/vendor/Pressability.native.tsx"],
4
+ "sourcesContent": ["export const Pressability = require('react-native/Libraries/Pressability/Pressability').default\nexport const usePressability =\n require('react-native/Libraries/Pressability/usePressability').default\n"],
5
+ "mappings": "AAAO,MAAM,eAAe,QAAQ,kDAAkD,EAAE;AACjF,MAAM,kBACX,QAAQ,qDAAqD,EAAE;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  import React, { memo, useMemo } from "react";
2
2
  import { isWeb } from "../constants/platform";
3
+ import { ThemeManagerContext } from "../helpers/ThemeManager";
3
4
  import { useChangeThemeEffect } from "../hooks/useTheme";
4
- import { ThemeManagerContext } from "../ThemeManager";
5
5
  React["createElement"];
6
6
  const Theme = memo(function Theme2(props) {
7
7
  var _a, _b;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/Theme.tsx"],
4
- "sourcesContent": ["import React, { memo, useMemo } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeProps, useChangeThemeEffect } from '../hooks/useTheme'\nimport { ThemeManager, ThemeManagerContext } from '../ThemeManager'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport const Theme = memo(function Theme(props: ThemeProps) {\n const { name, theme, themeManager, themes, className } = useChangeThemeEffect(\n props.name,\n props.componentName,\n props\n )\n\n const missingTheme = !themes || !name || !theme\n\n // memo here, changing theme without re-rendering all children is a critical optimization\n // may require some effort of end user to memoize but without this memo they'd have no option\n const contents = useMemo(\n () => (missingTheme ? null : wrapThemeManagerContext(props.children, themeManager)),\n [props.children, themeManager]\n )\n\n if (missingTheme) {\n if (name && !theme && process.env.NODE_ENV === 'development') {\n console.warn(`No theme found by name ${name}`)\n }\n return props.children\n }\n\n if (isWeb) {\n return (\n <span\n className={(!props.disableThemeClass\n ? [props.className, className].filter(Boolean)\n : []\n ).join(' ')}\n style={{\n display: 'contents',\n // in order to provide currentColor, set color by default\n color: themes[name]?.color?.toString(),\n }}\n >\n {contents}\n </span>\n )\n }\n\n return contents\n})\n\nexport function wrapThemeManagerContext(\n children: any,\n themeManager?: ThemeManager | null,\n shouldSetChildrenThemeToParent?: boolean\n) {\n return themeManager ? (\n <ThemeManagerContext.Provider value={themeManager}>\n {shouldSetChildrenThemeToParent ? (\n <Theme name={themeManager.parentName}>{children}</Theme>\n ) : (\n children\n )}\n </ThemeManagerContext.Provider>\n ) : (\n children\n )\n}\n"],
4
+ "sourcesContent": ["import React, { memo, useMemo } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManager, ThemeManagerContext } from '../helpers/ThemeManager'\nimport { ThemeProps, useChangeThemeEffect } from '../hooks/useTheme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport const Theme = memo(function Theme(props: ThemeProps) {\n const { name, theme, themeManager, themes, className } = useChangeThemeEffect(\n props.name,\n props.componentName,\n props\n )\n\n const missingTheme = !themes || !name || !theme\n\n // memo here, changing theme without re-rendering all children is a critical optimization\n // may require some effort of end user to memoize but without this memo they'd have no option\n const contents = useMemo(\n () => (missingTheme ? null : wrapThemeManagerContext(props.children, themeManager)),\n [props.children, themeManager]\n )\n\n if (missingTheme) {\n if (name && !theme && process.env.NODE_ENV === 'development') {\n console.warn(`No theme found by name ${name}`)\n }\n return props.children\n }\n\n if (isWeb) {\n return (\n <span\n className={(!props.disableThemeClass\n ? [props.className, className].filter(Boolean)\n : []\n ).join(' ')}\n style={{\n display: 'contents',\n // in order to provide currentColor, set color by default\n color: themes[name]?.color?.toString(),\n }}\n >\n {contents}\n </span>\n )\n }\n\n return contents\n})\n\nexport function wrapThemeManagerContext(\n children: any,\n themeManager?: ThemeManager | null,\n shouldSetChildrenThemeToParent?: boolean\n) {\n return themeManager ? (\n <ThemeManagerContext.Provider value={themeManager}>\n {shouldSetChildrenThemeToParent ? (\n <Theme name={themeManager.parentName}>{children}</Theme>\n ) : (\n children\n )}\n </ThemeManagerContext.Provider>\n ) : (\n children\n )\n}\n"],
5
5
  "mappings": "AAAA;AAEA;AACA;AACA;AAGA,MAAM;AAEC,MAAM,QAAQ,KAAK,gBAAe,OAAmB;AAT5D;AAUE,QAAM,EAAE,MAAM,OAAO,cAAc,QAAQ,cAAc,qBACvD,MAAM,MACN,MAAM,eACN,KACF;AAEA,QAAM,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC;AAI1C,QAAM,WAAW,QACf,MAAO,eAAe,OAAO,wBAAwB,MAAM,UAAU,YAAY,GACjF,CAAC,MAAM,UAAU,YAAY,CAC/B;AAEA,MAAI,cAAc;AAChB,QAAI,QAAQ,CAAC,SAAS,QAAQ,IAAI,aAAa,eAAe;AAC5D,cAAQ,KAAK,0BAA0B,MAAM;AAAA,IAC/C;AACA,WAAO,MAAM;AAAA,EACf;AAEA,MAAI,OAAO;AACT,WACE,oCAAC;AAAA,MACC,WAAY,EAAC,MAAM,oBACf,CAAC,MAAM,WAAW,SAAS,EAAE,OAAO,OAAO,IAC3C,CAAC,GACH,KAAK,GAAG;AAAA,MACV,OAAO;AAAA,QACL,SAAS;AAAA,QAET,OAAO,mBAAO,UAAP,mBAAc,UAAd,mBAAqB;AAAA,MAC9B;AAAA,OAEC,QACH;AAAA,EAEJ;AAEA,SAAO;AACT,CAAC;AAEM,iCACL,UACA,cACA,gCACA;AACA,SAAO,eACL,oCAAC,oBAAoB,UAApB;AAAA,IAA6B,OAAO;AAAA,KAClC,iCACC,oCAAC;AAAA,IAAM,MAAM,aAAa;AAAA,KAAa,QAAS,IAEhD,QAEJ,IAEA;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -2,13 +2,6 @@ import React, { useState } from "react";
2
2
  import { useIsomorphicLayoutEffect } from "../constants/platform";
3
3
  import { useDefaultThemeName, useThemeName } from "../hooks/useTheme";
4
4
  import { Theme } from "./Theme";
5
- let inversions = {
6
- light: "dark",
7
- dark: "light"
8
- };
9
- function setThemeInversions(next) {
10
- inversions = next;
11
- }
12
5
  const ThemeInverse = ({
13
6
  children,
14
7
  disable
@@ -17,7 +10,12 @@ const ThemeInverse = ({
17
10
  const defaultTheme = useDefaultThemeName();
18
11
  const [name, setName] = useState(null);
19
12
  useIsomorphicLayoutEffect(() => {
20
- setName(inversions[themeName] || inversions[defaultTheme || ""] || null);
13
+ if (themeName.startsWith("dark")) {
14
+ setName("light");
15
+ }
16
+ if (themeName.startsWith("light")) {
17
+ setName("dark");
18
+ }
21
19
  }, [defaultTheme, themeName]);
22
20
  if (disable) {
23
21
  return children;
@@ -27,7 +25,6 @@ const ThemeInverse = ({
27
25
  }, children);
28
26
  };
29
27
  export {
30
- ThemeInverse,
31
- setThemeInversions
28
+ ThemeInverse
32
29
  };
33
30
  //# sourceMappingURL=ThemeInverse.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeInverse.tsx"],
4
- "sourcesContent": ["import React, { useState } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\ntype StringRecord = { [key: string]: string }\n\nlet inversions: StringRecord = {\n light: 'dark',\n dark: 'light',\n}\n\nexport function setThemeInversions(next: StringRecord) {\n inversions = next\n}\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n setName(inversions[themeName] || inversions[defaultTheme || ''] || null)\n }, [defaultTheme, themeName])\n\n if (disable) {\n return children as JSX.Element\n }\n\n return <Theme name={name}>{children}</Theme>\n}\n"],
5
- "mappings": "AAAA;AAEA;AACA;AACA;AAIA,IAAI,aAA2B;AAAA,EAC7B,OAAO;AAAA,EACP,MAAM;AACR;AAEO,4BAA4B,MAAoB;AACrD,eAAa;AACf;AAEO,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,MAII;AACJ,QAAM,YAAY,aAAa;AAC/B,QAAM,eAAe,oBAAoB;AACzC,QAAM,CAAC,MAAM,WAAW,SAAwB,IAAI;AAGpD,4BAA0B,MAAM;AAC9B,YAAQ,WAAW,cAAc,WAAW,gBAAgB,OAAO,IAAI;AAAA,EACzE,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AAEA,SAAO,oCAAC;AAAA,IAAM;AAAA,KAAa,QAAS;AACtC;",
4
+ "sourcesContent": ["import React, { useState } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n if (themeName.startsWith('dark')) {\n setName('light')\n }\n if (themeName.startsWith('light')) {\n setName('dark')\n }\n }, [defaultTheme, themeName])\n\n if (disable) {\n return children as JSX.Element\n }\n\n return <Theme name={name}>{children}</Theme>\n}\n"],
5
+ "mappings": "AAAA;AAEA;AACA;AACA;AAEO,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,MAII;AACJ,QAAM,YAAY,aAAa;AAC/B,QAAM,eAAe,oBAAoB;AACzC,QAAM,CAAC,MAAM,WAAW,SAAwB,IAAI;AAGpD,4BAA0B,MAAM;AAC9B,QAAI,UAAU,WAAW,MAAM,GAAG;AAChC,cAAQ,OAAO;AAAA,IACjB;AACA,QAAI,UAAU,WAAW,OAAO,GAAG;AACjC,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AAEA,SAAO,oCAAC;AAAA,IAAM;AAAA,KAAa,QAAS;AACtC;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import React, { useLayoutEffect, useMemo } from "react";
2
2
  import { getHasConfigured } from "../conf";
3
3
  import { THEME_CLASSNAME_PREFIX } from "../constants/constants";
4
- import { ThemeContext } from "../ThemeContext";
4
+ import { ThemeContext } from "../contexts/ThemeContext";
5
5
  import { Theme } from "./Theme";
6
6
  React["createElement"];
7
7
  const ThemeProvider = (props) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeProvider.tsx"],
4
- "sourcesContent": ["import React, { useLayoutEffect, useMemo } from 'react'\n\nimport { getHasConfigured } from '../conf'\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { ThemeContext } from '../ThemeContext'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport type ThemeProviderProps = {\n className?: string\n themes: any\n defaultTheme: string\n disableRootThemeClass?: boolean\n themeClassNameOnRoot?: boolean\n children?: any\n reset?: boolean\n}\n\nexport const ThemeProvider = (props: ThemeProviderProps) => {\n if (!getHasConfigured()) {\n throw new Error(`Missing configureThemes() call, add to your root file`)\n }\n\n // ensure theme is attached to root body node as well to work with modals by default\n if (typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (props.disableRootThemeClass) {\n return\n }\n const cn = `${THEME_CLASSNAME_PREFIX}${props.defaultTheme}`\n const target = props.themeClassNameOnRoot ? document.documentElement : document.body\n target.classList.add(cn)\n return () => {\n target.classList.remove(cn)\n }\n }, [props.defaultTheme, props.disableRootThemeClass])\n }\n\n const themeContext = useMemo(() => {\n return {\n themes: props.themes,\n defaultTheme: props.defaultTheme,\n }\n }, [props.themes])\n\n return (\n <ThemeContext.Provider value={themeContext}>\n <Theme\n className={props.className}\n name={props.defaultTheme}\n disableThemeClass={props.disableRootThemeClass}\n >\n {props.children}\n </Theme>\n </ThemeContext.Provider>\n )\n}\n"],
4
+ "sourcesContent": ["import React, { useLayoutEffect, useMemo } from 'react'\n\nimport { getHasConfigured } from '../conf'\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport type ThemeProviderProps = {\n className?: string\n themes: any\n defaultTheme: string\n disableRootThemeClass?: boolean\n themeClassNameOnRoot?: boolean\n children?: any\n reset?: boolean\n}\n\nexport const ThemeProvider = (props: ThemeProviderProps) => {\n if (!getHasConfigured()) {\n throw new Error(`Missing configureThemes() call, add to your root file`)\n }\n\n // ensure theme is attached to root body node as well to work with modals by default\n if (typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (props.disableRootThemeClass) {\n return\n }\n const cn = `${THEME_CLASSNAME_PREFIX}${props.defaultTheme}`\n const target = props.themeClassNameOnRoot ? document.documentElement : document.body\n target.classList.add(cn)\n return () => {\n target.classList.remove(cn)\n }\n }, [props.defaultTheme, props.disableRootThemeClass])\n }\n\n const themeContext = useMemo(() => {\n return {\n themes: props.themes,\n defaultTheme: props.defaultTheme,\n }\n }, [props.themes])\n\n return (\n <ThemeContext.Provider value={themeContext}>\n <Theme\n className={props.className}\n name={props.defaultTheme}\n disableThemeClass={props.disableRootThemeClass}\n >\n {props.children}\n </Theme>\n </ThemeContext.Provider>\n )\n}\n"],
5
5
  "mappings": "AAAA;AAEA;AACA;AACA;AACA;AAGA,MAAM;AAYC,MAAM,gBAAgB,CAAC,UAA8B;AAC1D,MAAI,CAAC,iBAAiB,GAAG;AACvB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAGA,MAAI,OAAO,aAAa,aAAa;AACnC,oBAAgB,MAAM;AACpB,UAAI,MAAM,uBAAuB;AAC/B;AAAA,MACF;AACA,YAAM,KAAK,GAAG,yBAAyB,MAAM;AAC7C,YAAM,SAAS,MAAM,uBAAuB,SAAS,kBAAkB,SAAS;AAChF,aAAO,UAAU,IAAI,EAAE;AACvB,aAAO,MAAM;AACX,eAAO,UAAU,OAAO,EAAE;AAAA,MAC5B;AAAA,IACF,GAAG,CAAC,MAAM,cAAc,MAAM,qBAAqB,CAAC;AAAA,EACtD;AAEA,QAAM,eAAe,QAAQ,MAAM;AACjC,WAAO;AAAA,MACL,QAAQ,MAAM;AAAA,MACd,cAAc,MAAM;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,CAAC;AAEjB,SACE,oCAAC,aAAa,UAAb;AAAA,IAAsB,OAAO;AAAA,KAC5B,oCAAC;AAAA,IACC,WAAW,MAAM;AAAA,IACjB,MAAM,MAAM;AAAA,IACZ,mBAAmB,MAAM;AAAA,KAExB,MAAM,QACT,CACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import React, { useContext, useLayoutEffect, useState } from "react";
2
2
  import { isWeb } from "../constants/platform";
3
- import { ThemeManagerContext } from "../ThemeManager";
3
+ import { ThemeManagerContext } from "../helpers/ThemeManager";
4
4
  import { Theme } from "./Theme";
5
5
  React["createElement"];
6
6
  const ThemeReset = (props) => {