@tamagui/theme 1.15.25 → 1.15.27

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
package/src/addTheme.ts CHANGED
@@ -1,68 +1,11 @@
1
- import { isWeb } from '@tamagui/constants'
2
- import {
3
- ensureThemeVariable,
4
- getConfig,
5
- getThemeCSSRules,
6
- proxyThemeToParents,
7
- updateConfig,
8
- } from '@tamagui/web'
9
1
  import type { ThemeDefinition, ThemeParsed } from '@tamagui/web'
10
2
 
3
+ import { _mutateTheme } from './_mutateTheme'
4
+
11
5
  export function addTheme(props: {
12
6
  name: string
13
7
  theme: Partial<Record<keyof ThemeDefinition, any>>
14
8
  insertCSS?: boolean
15
- update?: boolean
16
9
  }) {
17
- const config = getConfig()
18
-
19
- if (process.env.NODE_ENV === 'development') {
20
- if (!config) {
21
- throw new Error('No config')
22
- }
23
- const theme = config.themes[props.name]
24
- if (!props.update && theme) {
25
- return { theme }
26
- }
27
- }
28
-
29
- const { name: themeName, theme: themeIn, insertCSS } = props
30
- const theme = { ...themeIn } as ThemeParsed
31
- for (const key in theme) {
32
- ensureThemeVariable(theme, key)
33
- }
34
-
35
- const themeProxied = proxyThemeToParents(themeName, theme, config.themes)
36
- config.themes[themeName] = themeProxied
37
-
38
- let cssRules: string[] = []
39
-
40
- if (isWeb) {
41
- if (insertCSS) {
42
- cssRules = getThemeCSSRules({
43
- // @ts-ignore this works but should be fixed types
44
- config,
45
- themeName,
46
- names: [themeName],
47
- theme,
48
- })
49
- const id = `t_theme_style_${themeName}`
50
- const existing = document.querySelector(`#${id}`)
51
- const style = document.createElement('style')
52
- style.id = id
53
- style.appendChild(document.createTextNode(cssRules.join('\n')))
54
- document.head.appendChild(style)
55
- if (existing) {
56
- existing.parentElement?.removeChild(existing)
57
- }
58
- }
59
- }
60
-
61
- updateConfig('themes', { ...config.themes, [themeName]: themeProxied })
62
-
63
- // trigger updates in components
64
- return {
65
- theme: themeProxied,
66
- cssRules,
67
- }
10
+ return _mutateTheme({ ...props })
68
11
  }
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './addTheme'
2
2
  export * from './updateTheme'
3
+ export * from './replaceTheme'
@@ -0,0 +1,27 @@
1
+ import { activeThemeManagers } from '@tamagui/web'
2
+ import type { ThemeDefinition } from '@tamagui/web'
3
+
4
+ import { _mutateTheme } from './_mutateTheme.js'
5
+
6
+ export function replaceTheme({
7
+ name,
8
+ theme,
9
+ }: {
10
+ name: string
11
+ theme: Partial<Record<keyof ThemeDefinition, any>>
12
+ }) {
13
+ const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: 'replace' })
14
+
15
+ if (process.env.TAMAGUI_TARGET === 'native') {
16
+ activeThemeManagers.forEach((manager) => {
17
+ if (manager.state.name === name) {
18
+ manager.updateState({
19
+ name,
20
+ forceTheme: next?.theme,
21
+ })
22
+ }
23
+ })
24
+ }
25
+
26
+ return next
27
+ }
@@ -1,7 +1,7 @@
1
1
  import { activeThemeManagers } from '@tamagui/web'
2
2
  import type { ThemeDefinition } from '@tamagui/web'
3
3
 
4
- import { addTheme } from './addTheme.js'
4
+ import { _mutateTheme } from './_mutateTheme.js'
5
5
 
6
6
  export function updateTheme({
7
7
  name,
@@ -10,14 +10,14 @@ export function updateTheme({
10
10
  name: string
11
11
  theme: Partial<Record<keyof ThemeDefinition, any>>
12
12
  }) {
13
- const next = addTheme({ name, theme, insertCSS: true, update: true })
13
+ const next = _mutateTheme({ name, theme, insertCSS: true, mutationType: 'update' })
14
14
 
15
15
  if (process.env.TAMAGUI_TARGET === 'native') {
16
16
  activeThemeManagers.forEach((manager) => {
17
17
  if (manager.state.name === name) {
18
18
  manager.updateState({
19
19
  name,
20
- forceTheme: next.theme,
20
+ forceTheme: next?.theme,
21
21
  })
22
22
  }
23
23
  })
@@ -0,0 +1,32 @@
1
+ import type { ThemeDefinition } from '@tamagui/web';
2
+ export declare function _mutateTheme(props: {
3
+ name: string;
4
+ theme: Partial<Record<keyof ThemeDefinition, any>>;
5
+ insertCSS?: boolean;
6
+ mutationType?: 'replace' | 'update';
7
+ }): {
8
+ theme: {
9
+ [x: string]: import("@tamagui/web").Variable<any>;
10
+ background?: import("@tamagui/web").Variable<any> | undefined;
11
+ backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
12
+ backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
13
+ backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
14
+ color?: import("@tamagui/web").Variable<any> | undefined;
15
+ colorHover?: import("@tamagui/web").Variable<any> | undefined;
16
+ colorPress?: import("@tamagui/web").Variable<any> | undefined;
17
+ colorFocus?: import("@tamagui/web").Variable<any> | undefined;
18
+ borderColor?: import("@tamagui/web").Variable<any> | undefined;
19
+ borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
20
+ borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
21
+ borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
22
+ shadowColor?: import("@tamagui/web").Variable<any> | undefined;
23
+ shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
24
+ shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
25
+ shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
26
+ };
27
+ cssRules?: undefined;
28
+ } | {
29
+ theme: any;
30
+ cssRules: string[];
31
+ } | undefined;
32
+ //# sourceMappingURL=_mutateTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_mutateTheme.d.ts","sourceRoot":"","sources":["../src/_mutateTheme.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAA;AAEhE,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;CACpC;;;;;;;;;;;;;;;;;;;;;;;;cAoEA"}
@@ -3,7 +3,6 @@ export declare function addTheme(props: {
3
3
  name: string;
4
4
  theme: Partial<Record<keyof ThemeDefinition, any>>;
5
5
  insertCSS?: boolean;
6
- update?: boolean;
7
6
  }): {
8
7
  theme: {
9
8
  [x: string]: import("@tamagui/web").Variable<any>;
@@ -28,5 +27,5 @@ export declare function addTheme(props: {
28
27
  } | {
29
28
  theme: any;
30
29
  cssRules: string[];
31
- };
30
+ } | undefined;
32
31
  //# sourceMappingURL=addTheme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addTheme.d.ts","sourceRoot":"","sources":["../src/addTheme.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAA;AAEhE,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;;;;;;;;;;;;;;;;;;;;;;;;EAoDA"}
1
+ {"version":3,"file":"addTheme.d.ts","sourceRoot":"","sources":["../src/addTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAA;AAIhE,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;;;;;;;;;;;;;;;;;;;;;;;;cAEA"}
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './addTheme';
2
2
  export * from './updateTheme';
3
+ export * from './replaceTheme';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,30 @@
1
+ import type { ThemeDefinition } from '@tamagui/web';
2
+ export declare function replaceTheme({ name, theme, }: {
3
+ name: string;
4
+ theme: Partial<Record<keyof ThemeDefinition, any>>;
5
+ }): {
6
+ theme: {
7
+ [x: string]: import("@tamagui/web").Variable<any>;
8
+ background?: import("@tamagui/web").Variable<any> | undefined;
9
+ backgroundHover?: import("@tamagui/web").Variable<any> | undefined;
10
+ backgroundPress?: import("@tamagui/web").Variable<any> | undefined;
11
+ backgroundFocus?: import("@tamagui/web").Variable<any> | undefined;
12
+ color?: import("@tamagui/web").Variable<any> | undefined;
13
+ colorHover?: import("@tamagui/web").Variable<any> | undefined;
14
+ colorPress?: import("@tamagui/web").Variable<any> | undefined;
15
+ colorFocus?: import("@tamagui/web").Variable<any> | undefined;
16
+ borderColor?: import("@tamagui/web").Variable<any> | undefined;
17
+ borderColorHover?: import("@tamagui/web").Variable<any> | undefined;
18
+ borderColorPress?: import("@tamagui/web").Variable<any> | undefined;
19
+ borderColorFocus?: import("@tamagui/web").Variable<any> | undefined;
20
+ shadowColor?: import("@tamagui/web").Variable<any> | undefined;
21
+ shadowColorHover?: import("@tamagui/web").Variable<any> | undefined;
22
+ shadowColorPress?: import("@tamagui/web").Variable<any> | undefined;
23
+ shadowColorFocus?: import("@tamagui/web").Variable<any> | undefined;
24
+ };
25
+ cssRules?: undefined;
26
+ } | {
27
+ theme: any;
28
+ cssRules: string[];
29
+ } | undefined;
30
+ //# sourceMappingURL=replaceTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceTheme.d.ts","sourceRoot":"","sources":["../src/replaceTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;cAeA"}
@@ -26,5 +26,5 @@ export declare function updateTheme({ name, theme, }: {
26
26
  } | {
27
27
  theme: any;
28
28
  cssRules: string[];
29
- };
29
+ } | undefined;
30
30
  //# sourceMappingURL=updateTheme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateTheme.d.ts","sourceRoot":"","sources":["../src/updateTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;EAeA"}
1
+ {"version":3,"file":"updateTheme.d.ts","sourceRoot":"","sources":["../src/updateTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAInD,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,GAAG,CAAC,CAAC,CAAA;CACnD;;;;;;;;;;;;;;;;;;;;;;;;cAeA"}