@tamagui/core 1.0.1-beta.167 → 1.0.1-beta.169

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 (94) hide show
  1. package/dist/cjs/addTheme.js.map +1 -1
  2. package/dist/cjs/config.js.map +1 -1
  3. package/dist/cjs/constants/platform.js +4 -4
  4. package/dist/cjs/constants/platform.js.map +2 -2
  5. package/dist/cjs/constants/platform.native.js +3 -3
  6. package/dist/cjs/constants/platform.native.js.map +2 -2
  7. package/dist/cjs/createComponent.js +39 -17
  8. package/dist/cjs/createComponent.js.map +2 -2
  9. package/dist/cjs/createTamagui.js +1 -4
  10. package/dist/cjs/createTamagui.js.map +2 -2
  11. package/dist/cjs/helpers/ThemeManager.js.map +1 -1
  12. package/dist/cjs/helpers/getSplitStyles.js +18 -10
  13. package/dist/cjs/helpers/getSplitStyles.js.map +3 -3
  14. package/dist/cjs/helpers/getThemeCSSRules.js.map +1 -1
  15. package/dist/cjs/hooks/useIsSSR.js +11 -7
  16. package/dist/cjs/hooks/useIsSSR.js.map +2 -2
  17. package/dist/cjs/hooks/useIsTouchDevice.js +1 -1
  18. package/dist/cjs/hooks/useIsTouchDevice.js.map +2 -2
  19. package/dist/cjs/hooks/useMedia.js +51 -29
  20. package/dist/cjs/hooks/useMedia.js.map +2 -2
  21. package/dist/cjs/hooks/useTheme.js +1 -1
  22. package/dist/cjs/hooks/useTheme.js.map +2 -2
  23. package/dist/cjs/styled.js +11 -8
  24. package/dist/cjs/styled.js.map +2 -2
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/updateTheme.js.map +2 -2
  27. package/dist/cjs/views/TamaguiProvider.js +2 -2
  28. package/dist/cjs/views/TamaguiProvider.js.map +2 -2
  29. package/dist/esm/addTheme.js.map +1 -1
  30. package/dist/esm/config.js.map +1 -1
  31. package/dist/esm/constants/platform.js +3 -3
  32. package/dist/esm/constants/platform.js.map +2 -2
  33. package/dist/esm/constants/platform.native.js +2 -2
  34. package/dist/esm/constants/platform.native.js.map +2 -2
  35. package/dist/esm/createComponent.js +43 -18
  36. package/dist/esm/createComponent.js.map +2 -2
  37. package/dist/esm/createTamagui.js +1 -4
  38. package/dist/esm/createTamagui.js.map +2 -2
  39. package/dist/esm/helpers/ThemeManager.js.map +1 -1
  40. package/dist/esm/helpers/getSplitStyles.js +18 -10
  41. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  42. package/dist/esm/helpers/getThemeCSSRules.js.map +1 -1
  43. package/dist/esm/hooks/useIsSSR.js +12 -8
  44. package/dist/esm/hooks/useIsSSR.js.map +2 -2
  45. package/dist/esm/hooks/useIsTouchDevice.js +2 -2
  46. package/dist/esm/hooks/useIsTouchDevice.js.map +2 -2
  47. package/dist/esm/hooks/useMedia.js +51 -30
  48. package/dist/esm/hooks/useMedia.js.map +2 -2
  49. package/dist/esm/hooks/useTheme.js +2 -2
  50. package/dist/esm/hooks/useTheme.js.map +2 -2
  51. package/dist/esm/styled.js +11 -8
  52. package/dist/esm/styled.js.map +2 -2
  53. package/dist/esm/updateTheme.js.map +2 -2
  54. package/dist/esm/views/TamaguiProvider.js +3 -3
  55. package/dist/esm/views/TamaguiProvider.js.map +2 -2
  56. package/package.json +10 -10
  57. package/src/addTheme.ts +3 -3
  58. package/src/config.ts +1 -1
  59. package/src/constants/platform.native.ts +1 -1
  60. package/src/constants/platform.ts +2 -2
  61. package/src/createComponent.tsx +51 -23
  62. package/src/createTamagui.ts +7 -10
  63. package/src/helpers/ThemeManager.tsx +4 -4
  64. package/src/helpers/getSplitStyles.tsx +27 -13
  65. package/src/helpers/getThemeCSSRules.ts +2 -2
  66. package/src/hooks/useIsSSR.tsx +13 -8
  67. package/src/hooks/useIsTouchDevice.tsx +2 -2
  68. package/src/hooks/useMedia.tsx +72 -39
  69. package/src/hooks/useTheme.tsx +6 -7
  70. package/src/styled.tsx +14 -8
  71. package/src/types.tsx +41 -12
  72. package/src/updateTheme.ts +2 -2
  73. package/src/views/TamaguiProvider.tsx +3 -4
  74. package/types/addTheme.d.ts +2 -2
  75. package/types/config.d.ts +18 -2
  76. package/types/constants/platform.d.ts +1 -1
  77. package/types/constants/platform.native.d.ts +1 -1
  78. package/types/createVariable.d.ts +4 -0
  79. package/types/helpers/ThemeManager.d.ts +5 -5
  80. package/types/helpers/calc.d.ts +5 -0
  81. package/types/helpers/expandStyle.d.ts +4 -0
  82. package/types/helpers/expandStyles.d.ts +7 -0
  83. package/types/helpers/getSplitStyles.d.ts +3 -3
  84. package/types/helpers/getStylesAtomic.d.ts +4 -0
  85. package/types/helpers/getThemeCSSRules.d.ts +2 -2
  86. package/types/helpers/mergeProps.d.ts +13 -0
  87. package/types/helpers/normalizeValueWithProperty.d.ts +4 -0
  88. package/types/hooks/useIsSSR.d.ts +3 -1
  89. package/types/hooks/useMedia.d.ts +8 -5
  90. package/types/hooks/useTheme.d.ts +4 -4
  91. package/types/insertFont.d.ts +3 -0
  92. package/types/styled.d.ts +1 -0
  93. package/types/types.d.ts +111 -11
  94. package/types/updateTheme.d.ts +2 -2
@@ -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 '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { isRSC, isSSR, 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'\nimport { useServerRef } from './useServerHooks'\n\nexport interface 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\ninterface 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 // TODO this can use useChangeThemeEffect almost ready\n if (isRSC) {\n const config = getConfig()\n // @ts-ignore\n return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate,\n state.current.uuid\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { themeName, componentName, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(' ', key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n // track usage\n state.current.isRendering = true\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 // eslint-disable-next-line no-console\n console.warn('No theme with name', themeName)\n }\n return themes[getConfig().defaultTheme || 'light']\n }\n\n return useMemo(() => {\n return getThemeProxied(theme, name, className, themeManager, state, debugProp)\n }, [theme, name, className, themeManager, state, debugProp])\n}\n\nfunction getThemeProxied(\n theme: any,\n name: string,\n className?: string,\n themeManager?: ThemeManager | null,\n state?: React.MutableRefObject<UseThemeState>,\n debugProp?: boolean | 'verbose'\n) {\n return new Proxy(theme, {\n has(_, key) {\n if (typeof key === 'string' && key[0] === '$') {\n key = key.slice(1)\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 // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (!themeManager) {\n return theme[key]\n }\n if (state) {\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 // eslint-disable-next-line no-console\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n }\n return themeManager.getValue(key)\n },\n })\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 if (isRSC) {\n const config = getConfig()\n return config.defaultTheme || 'light'\n }\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 uuid?: Object\n): {\n themes: Record<string, ThemeObject>\n themeManager: ThemeManager | null\n name: string\n theme: ThemeObject | null\n className?: string\n} => {\n const { themes } = getConfig()\n\n if (isRSC) {\n // we need context working for this to work well\n const parentManager = new ThemeManager('light', 'light', themes.light)\n const next = parentManager.getNextTheme({\n name,\n componentName,\n themes,\n reset: props?.reset,\n })\n return {\n ...next,\n themes,\n themeManager: null,\n }\n }\n\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = {\n name,\n componentName,\n themes,\n reset,\n }\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(() => {\n return new ThemeManager(next.name, next.className, next.theme, parentManager, reset)\n })\n\n if (!isSSR) {\n useLayoutEffect(() => {\n themeManager.update(next)\n\n activeThemeManagers.add(themeManager)\n\n const disposeParentOnChange = parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n if (uuid && !themeManager.isTracking(uuid)) {\n // no need to re-render if not tracking any keys\n return\n }\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.log('Changed theme', componentName, next, { props })\n }\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, next?.name, next?.className, componentName, debug])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n className: next.className === parentManager.className ? undefined : next.className,\n themes,\n themeManager,\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,sBAAsB;AAC/B,SAAgB,YAAY,iBAAiB,SAAiB,gBAAgB;AAE9E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,OAAO,OAAO,iCAAiC;AACxD,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAkBtB,MAAM,WAAW,CACtB,WAC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MAAM;AACrC,WAAO,IAAI,aAAa,KAAK,MAAM,KAAK,WAAW,KAAK,OAAO,eAAe,KAAK;AAAA,EACrF,CAAC;AAED,MAAI,CAAC,OAAO;AACV,oBAAgB,MAAM;AACpB,mBAAa,OAAO,IAAI;AAExB,0BAAoB,IAAI,YAAY;AAEpC,YAAM,wBAAwB,cAAc,cAAc,MAAM;AAC9D,cAAMA,QAAO,cAAc,aAAa,eAAe,KAAK;AAC5D,YAAI,CAACA;AAAM;AACX,YAAI,aAAa,OAAOA,KAAI,GAAG;AAC7B,cAAI,QAAQ,CAAC,aAAa,WAAW,IAAI,GAAG;AAE1C;AAAA,UACF;AACA,cAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO;AAEnD,oBAAQ,IAAI,iBAAiB,eAAeA,OAAM,EAAE,MAAM,CAAC;AAAA,UAC7D;AACA,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,aAAO,MAAM;AACX,4BAAoB,OAAO,YAAY;AACvC,8BAAsB;AAAA,MACxB;AAAA,IAEF,GAAG,CAAC,QAAQ,6BAAM,MAAM,6BAAM,WAAW,eAAe,KAAK,CAAC;AAAA,EAChE;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH,WAAW,KAAK,cAAc,cAAc,YAAY,SAAY,KAAK;AAAA,IACzE;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 '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { isRSC, isServer, 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, ThemeParsed } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useConstant } from './useConstant'\nimport { useServerRef } from './useServerHooks'\n\nexport interface 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\ninterface 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): ThemeParsed => {\n // TODO this can use useChangeThemeEffect almost ready\n if (isRSC) {\n const config = getConfig()\n // @ts-ignore\n return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate,\n state.current.uuid\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { themeName, componentName, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(' ', key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n // track usage\n state.current.isRendering = true\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 // eslint-disable-next-line no-console\n console.warn('No theme with name', themeName)\n }\n return themes[getConfig().defaultTheme || 'light']\n }\n\n return useMemo(() => {\n return getThemeProxied(theme, name, className, themeManager, state, debugProp)\n }, [theme, name, className, themeManager, state, debugProp])\n}\n\nfunction getThemeProxied(\n theme: any,\n name: string,\n className?: string,\n themeManager?: ThemeManager | null,\n state?: React.MutableRefObject<UseThemeState>,\n debugProp?: boolean | 'verbose'\n) {\n return new Proxy(theme, {\n has(_, key) {\n if (typeof key === 'string' && key[0] === '$') {\n key = key.slice(1)\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 // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (!themeManager) {\n return theme[key]\n }\n if (state) {\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 // eslint-disable-next-line no-console\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n }\n return themeManager.getValue(key)\n },\n })\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 if (isRSC) {\n const config = getConfig()\n return config.defaultTheme || 'light'\n }\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 uuid?: Object\n): {\n themes: Record<string, ThemeParsed>\n themeManager: ThemeManager | null\n name: string\n theme: ThemeParsed | null\n className?: string\n} => {\n const { themes } = getConfig()\n\n if (isRSC) {\n // we need context working for this to work well\n const parentManager = new ThemeManager('light', 'light', themes.light)\n const next = parentManager.getNextTheme({\n name,\n componentName,\n themes,\n reset: props?.reset,\n })\n return {\n ...next,\n themes,\n themeManager: null,\n }\n }\n\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = {\n name,\n componentName,\n themes,\n reset,\n }\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(() => {\n return new ThemeManager(next.name, next.className, next.theme, parentManager, reset)\n })\n\n if (!isServer) {\n useLayoutEffect(() => {\n themeManager.update(next)\n activeThemeManagers.add(themeManager)\n\n const disposeParentOnChange = parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n if (uuid && !themeManager.isTracking(uuid)) {\n // no need to re-render if not tracking any keys\n return\n }\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.log('Changed theme', componentName, next, { props })\n }\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, next?.name, next?.className, componentName, debug])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n className: next.className === parentManager.className ? undefined : next.className,\n themes,\n themeManager,\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,sBAAsB;AAC/B,SAAgB,YAAY,iBAAiB,SAAiB,gBAAgB;AAE9E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,OAAO,UAAU,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AQ,+BAAO,UAAS;AAC9B,QAAM,gBAAmC;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,OAAO,cAAc,aAAa,eAAe,KAAK;AAE5D,QAAM,cAAc,mBAAmB,eAAe;AAEtD,QAAM,eAAe,YAAY,MAAM;AACrC,WAAO,IAAI,aAAa,KAAK,MAAM,KAAK,WAAW,KAAK,OAAO,eAAe,KAAK;AAAA,EACrF,CAAC;AAED,MAAI,CAAC,UAAU;AACb,oBAAgB,MAAM;AACpB,mBAAa,OAAO,IAAI;AACxB,0BAAoB,IAAI,YAAY;AAEpC,YAAM,wBAAwB,cAAc,cAAc,MAAM;AAC9D,cAAMA,QAAO,cAAc,aAAa,eAAe,KAAK;AAC5D,YAAI,CAACA;AAAM;AACX,YAAI,aAAa,OAAOA,KAAI,GAAG;AAC7B,cAAI,QAAQ,CAAC,aAAa,WAAW,IAAI,GAAG;AAE1C;AAAA,UACF;AACA,cAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO;AAEnD,oBAAQ,IAAI,iBAAiB,eAAeA,OAAM,EAAE,MAAM,CAAC;AAAA,UAC7D;AACA,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,aAAO,MAAM;AACX,4BAAoB,OAAO,YAAY;AACvC,8BAAsB;AAAA,MACxB;AAAA,IAEF,GAAG,CAAC,QAAQ,6BAAM,MAAM,6BAAM,WAAW,eAAe,KAAK,CAAC;AAAA,EAChE;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH,WAAW,KAAK,cAAc,cAAc,YAAY,SAAY,KAAK;AAAA,IACzE;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": ["name", "parentManager", "next"]
7
7
  }
@@ -12,7 +12,13 @@ function styled(Component, options, staticExtractionOptions) {
12
12
  }
13
13
  }
14
14
  if (options) {
15
- const { variants, name, defaultVariants, ...defaultProps } = options;
15
+ const {
16
+ variants,
17
+ name,
18
+ defaultVariants,
19
+ acceptsClassName: acceptsClassNameProp,
20
+ ...defaultProps
21
+ } = options;
16
22
  if (defaultVariants) {
17
23
  Object.assign(defaultProps, defaultVariants);
18
24
  }
@@ -22,11 +28,6 @@ function styled(Component, options, staticExtractionOptions) {
22
28
  RNComponents.add(Component);
23
29
  isReactNativeWeb = true;
24
30
  } else {
25
- if (process.env.NODE_ENV === "development") {
26
- console.warn(
27
- `Invalid styled() component: Tamagui only accepts react-native Text, View, Image, TextInput, or another styled Tamagui view`
28
- );
29
- }
30
31
  }
31
32
  }
32
33
  const reactNativeWebComponent = isReactNativeWeb ? (parentStaticConfig == null ? void 0 : parentStaticConfig.reactNativeWebComponent) || Component : null;
@@ -41,6 +42,7 @@ function styled(Component, options, staticExtractionOptions) {
41
42
  const isText = Boolean(
42
43
  isInput || (staticExtractionOptions == null ? void 0 : staticExtractionOptions.isText) || (parentStaticConfig == null ? void 0 : parentStaticConfig.isText) || Comp === Text
43
44
  );
45
+ const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNativeWeb);
44
46
  const conf = {
45
47
  ...staticExtractionOptions,
46
48
  ...!isTamagui && {
@@ -55,9 +57,10 @@ function styled(Component, options, staticExtractionOptions) {
55
57
  reactNativeWebComponent,
56
58
  isInput,
57
59
  isText,
58
- isImage
60
+ isImage,
61
+ acceptsClassName
59
62
  };
60
- if (defaultProps.children) {
63
+ if (defaultProps.children || !acceptsClassName) {
61
64
  conf.neverFlatten = true;
62
65
  }
63
66
  return conf;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/styled.tsx"],
4
- "sourcesContent": ["import { Image, Text, TextInput } from 'react-native'\n\nimport { createComponent } from './createComponent'\nimport { TamaguiReactElement, isTamaguiElement } from './helpers/isTamaguiElement'\nimport { RNComponents } from './helpers/RNComponents'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> = GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n}\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // * excessively deep type instantiation\n // if (isTamaguiElement(Component)) {\n // const props = Component.props\n // // @ts-ignore\n // Component = Component.type\n // options = options ? { ...props, ...options } : props\n // }\n\n const staticConfigProps = (() => {\n const parentStaticConfig =\n 'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null\n\n if (process.env.NODE_ENV === 'development') {\n if (parentStaticConfig?.isHOC) {\n // eslint-disable-next-line no-console\n console.warn(\n `Warning: Parent component is a functional component, not a Tamagui styled() component. Extending with styled() will break and lead to incorrect styles.`\n )\n }\n }\n\n if (options) {\n const { variants, name, defaultVariants, ...defaultProps } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n let isReactNativeWeb = parentStaticConfig?.isReactNativeWeb || RNComponents.has(Component)\n // this can happen due to smart-ness in fake-react-native, rough heuristic here to ensure we match (could be better..)\n if (!('staticConfig' in Component) && !isReactNativeWeb) {\n if (RNComponents.has(Component['displayName'])) {\n RNComponents.add(Component)\n isReactNativeWeb = true\n } else {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid styled() component: Tamagui only accepts react-native Text, View, Image, TextInput, or another styled Tamagui view`\n )\n }\n }\n }\n const reactNativeWebComponent = isReactNativeWeb\n ? parentStaticConfig?.reactNativeWebComponent || Component\n : null\n const isTamagui = !isReactNativeWeb && !!parentStaticConfig\n const Comp = reactNativeWebComponent || (Component as any)\n const isImage = Boolean(\n staticExtractionOptions?.isImage || parentStaticConfig?.isImage || Comp === Image\n )\n const isInput = Boolean(\n staticExtractionOptions?.isInput || parentStaticConfig?.isInput || Comp === TextInput\n )\n const isText = Boolean(\n isInput || staticExtractionOptions?.isText || parentStaticConfig?.isText || Comp === Text\n )\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isTamagui && {\n Component: Comp,\n }),\n isTamagui,\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name,\n isReactNativeWeb,\n // for nesting multiple levels of rnw styled() need keep use the OG component\n reactNativeWebComponent,\n isInput,\n isText,\n isImage,\n }\n\n // TODO compiler doesn't have logic to include children, de-opt (see EnsureFlexed for test usage)\n if (defaultProps.children) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n return {}\n })()\n\n const component = createComponent(staticConfigProps, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<any, infer Val>\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n return component as TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n}\n\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {}\n// }\n// },\n// disabled: {\n// true: {\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
5
- "mappings": "AAAA,SAAS,OAAO,MAAM,iBAAiB;AAEvC,SAAS,uBAAuB;AAEhC,SAAS,oBAAoB;AAmCtB,SAAS,OAId,WAEA,SAMA,yBACA;AASA,QAAM,qBAAqB,MAAM;AAC/B,UAAM,qBACJ,kBAAkB,YAAa,UAAU,eAAgC;AAE3E,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UAAI,yDAAoB,OAAO;AAE7B,gBAAQ;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,SAAS;AACX,YAAM,EAAE,UAAU,MAAM,oBAAoB,aAAa,IAAI;AAC7D,UAAI,iBAAiB;AACnB,eAAO,OAAO,cAAc,eAAe;AAAA,MAC7C;AACA,UAAI,oBAAmB,yDAAoB,qBAAoB,aAAa,IAAI,SAAS;AAEzF,UAAI,EAAE,kBAAkB,cAAc,CAAC,kBAAkB;AACvD,YAAI,aAAa,IAAI,UAAU,cAAc,GAAG;AAC9C,uBAAa,IAAI,SAAS;AAC1B,6BAAmB;AAAA,QACrB,OAAO;AACL,cAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,oBAAQ;AAAA,cACN;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AACA,YAAM,0BAA0B,oBAC5B,yDAAoB,4BAA2B,YAC/C;AACJ,YAAM,YAAY,CAAC,oBAAoB,CAAC,CAAC;AACzC,YAAM,OAAO,2BAA4B;AACzC,YAAM,UAAU;AAAA,SACd,mEAAyB,aAAW,yDAAoB,YAAW,SAAS;AAAA,MAC9E;AACA,YAAM,UAAU;AAAA,SACd,mEAAyB,aAAW,yDAAoB,YAAW,SAAS;AAAA,MAC9E;AACA,YAAM,SAAS;AAAA,QACb,YAAW,mEAAyB,YAAU,yDAAoB,WAAU,SAAS;AAAA,MACvF;AAEA,YAAM,OAA8B;AAAA,QAClC,GAAG;AAAA,QACH,GAAI,CAAC,aAAa;AAAA,UAChB,WAAW;AAAA,QACb;AAAA,QACA;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe;AAAA,QACf;AAAA,QAEA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAGA,UAAI,aAAa,UAAU;AACzB,aAAK,eAAe;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AACA,WAAO,CAAC;AAAA,EACV,GAAG;AAEH,QAAM,YAAY,gBAAgB,mBAAmB,SAAS;AA2B9D,SAAO;AAMT;",
4
+ "sourcesContent": ["import { Image, Text, TextInput } from 'react-native'\n\nimport { createComponent } from './createComponent'\nimport { TamaguiReactElement, isTamaguiElement } from './helpers/isTamaguiElement'\nimport { RNComponents } from './helpers/RNComponents'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> = GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n}\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // * excessively deep type instantiation\n // if (isTamaguiElement(Component)) {\n // const props = Component.props\n // // @ts-ignore\n // Component = Component.type\n // options = options ? { ...props, ...options } : props\n // }\n\n const staticConfigProps = (() => {\n const parentStaticConfig =\n 'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null\n\n if (process.env.NODE_ENV === 'development') {\n if (parentStaticConfig?.isHOC) {\n // eslint-disable-next-line no-console\n console.warn(\n `Warning: Parent component is a functional component, not a Tamagui styled() component. Extending with styled() will break and lead to incorrect styles.`\n )\n }\n }\n\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n let isReactNativeWeb = parentStaticConfig?.isReactNativeWeb || RNComponents.has(Component)\n // this can happen due to smart-ness in fake-react-native, rough heuristic here to ensure we match (could be better..)\n if (!('staticConfig' in Component) && !isReactNativeWeb) {\n if (RNComponents.has(Component['displayName'])) {\n RNComponents.add(Component)\n isReactNativeWeb = true\n } else {\n // assuming some sort of non-tamagui non-rn view, will always use style={}\n }\n }\n const reactNativeWebComponent = isReactNativeWeb\n ? parentStaticConfig?.reactNativeWebComponent || Component\n : null\n const isTamagui = !isReactNativeWeb && !!parentStaticConfig\n const Comp = reactNativeWebComponent || (Component as any)\n const isImage = Boolean(\n staticExtractionOptions?.isImage || parentStaticConfig?.isImage || Comp === Image\n )\n const isInput = Boolean(\n staticExtractionOptions?.isInput || parentStaticConfig?.isInput || Comp === TextInput\n )\n const isText = Boolean(\n isInput || staticExtractionOptions?.isText || parentStaticConfig?.isText || Comp === Text\n )\n\n const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNativeWeb)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isTamagui && {\n Component: Comp,\n }),\n isTamagui,\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name,\n isReactNativeWeb,\n // for nesting multiple levels of rnw styled() need keep use the OG component\n reactNativeWebComponent,\n isInput,\n isText,\n isImage,\n acceptsClassName,\n }\n\n // TODO compiler doesn't have logic to include children, de-opt (see EnsureFlexed for test usage)\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n return {}\n })()\n\n const component = createComponent(staticConfigProps, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<any, infer Val>\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n return component as TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n}\n\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {}\n// }\n// },\n// disabled: {\n// true: {\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
5
+ "mappings": "AAAA,SAAS,OAAO,MAAM,iBAAiB;AAEvC,SAAS,uBAAuB;AAEhC,SAAS,oBAAoB;AAmCtB,SAAS,OAId,WAEA,SAOA,yBACA;AASA,QAAM,qBAAqB,MAAM;AAC/B,UAAM,qBACJ,kBAAkB,YAAa,UAAU,eAAgC;AAE3E,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UAAI,yDAAoB,OAAO;AAE7B,gBAAQ;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,SAAS;AACX,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,WACf;AAAA,MACL,IAAI;AACJ,UAAI,iBAAiB;AACnB,eAAO,OAAO,cAAc,eAAe;AAAA,MAC7C;AACA,UAAI,oBAAmB,yDAAoB,qBAAoB,aAAa,IAAI,SAAS;AAEzF,UAAI,EAAE,kBAAkB,cAAc,CAAC,kBAAkB;AACvD,YAAI,aAAa,IAAI,UAAU,cAAc,GAAG;AAC9C,uBAAa,IAAI,SAAS;AAC1B,6BAAmB;AAAA,QACrB,OAAO;AAAA,QAEP;AAAA,MACF;AACA,YAAM,0BAA0B,oBAC5B,yDAAoB,4BAA2B,YAC/C;AACJ,YAAM,YAAY,CAAC,oBAAoB,CAAC,CAAC;AACzC,YAAM,OAAO,2BAA4B;AACzC,YAAM,UAAU;AAAA,SACd,mEAAyB,aAAW,yDAAoB,YAAW,SAAS;AAAA,MAC9E;AACA,YAAM,UAAU;AAAA,SACd,mEAAyB,aAAW,yDAAoB,YAAW,SAAS;AAAA,MAC9E;AACA,YAAM,SAAS;AAAA,QACb,YAAW,mEAAyB,YAAU,yDAAoB,WAAU,SAAS;AAAA,MACvF;AAEA,YAAM,mBAAmB,yBAAyB,aAAa;AAE/D,YAAM,OAA8B;AAAA,QAClC,GAAG;AAAA,QACH,GAAI,CAAC,aAAa;AAAA,UAChB,WAAW;AAAA,QACb;AAAA,QACA;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe;AAAA,QACf;AAAA,QAEA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAIA,UAAI,aAAa,YAAY,CAAC,kBAAkB;AAC9C,aAAK,eAAe;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AACA,WAAO,CAAC;AAAA,EACV,GAAG;AAEH,QAAM,YAAY,gBAAgB,mBAAmB,SAAS;AA2B9D,SAAO;AAMT;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AAG7B,SAAS,YAAY,EAAE,MAAM,MAAM,GAAyC;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;AAAA,UACN;AAAA,YACE;AAAA,YACA,OAAO,KAAK;AAAA,UACd;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import { addTheme } from './addTheme'\nimport { activeThemeManagers } from './hooks/useTheme'\nimport { ThemeDefinition } from './types'\n\nexport function updateTheme({ name, theme }: { name: string; theme: ThemeDefinition }) {\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,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AAG7B,SAAS,YAAY,EAAE,MAAM,MAAM,GAA6C;AACrF,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;AAAA,UACN;AAAA,YACE;AAAA,YACA,OAAO,KAAK;AAAA,UACd;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import { isClient, isRSC, isSSR } from "../constants/platform";
3
+ import { isClient, isRSC, isServer } from "../constants/platform";
4
4
  import { ButtonInsideButtonContext } from "../contexts/ButtonInsideButtonContext";
5
5
  import { TextAncestorProvider } from "../contexts/TextAncestorContext";
6
6
  import { useMediaQueryListeners } from "../hooks/useMedia";
@@ -18,8 +18,8 @@ function TamaguiProvider({
18
18
  children
19
19
  });
20
20
  }
21
- if (!isSSR) {
22
- useMediaQueryListeners();
21
+ if (!isServer) {
22
+ useMediaQueryListeners(config);
23
23
  }
24
24
  if (isClient) {
25
25
  React.useLayoutEffect(() => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/TamaguiProvider.tsx"],
4
- "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport * as React from 'react'\n\nimport { isClient, isRSC, isSSR } from '../constants/platform'\nimport { ButtonInsideButtonContext } from '../contexts/ButtonInsideButtonContext'\nimport { TextAncestorProvider } from '../contexts/TextAncestorContext'\nimport { useMediaQueryListeners } from '../hooks/useMedia'\nimport type { TamaguiProviderProps } from '../types'\nimport { ThemeProvider } from './ThemeProvider'\n\nexport function TamaguiProvider({\n children,\n disableInjectCSS,\n config,\n ...themePropsProvider\n}: TamaguiProviderProps) {\n if (isRSC) {\n return (\n <span style={{ display: 'contents' }} className={`t_${config.defaultTheme || 'light'}`}>\n {children}\n </span>\n )\n }\n\n if (!isSSR) {\n useMediaQueryListeners()\n }\n\n if (isClient) {\n // inject CSS if asked to (not SSR compliant)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useLayoutEffect(() => {\n if (disableInjectCSS) return\n const style = document.createElement('style')\n style.appendChild(document.createTextNode(config.getCSS()))\n document.head.appendChild(style)\n return () => {\n document.head.removeChild(style)\n }\n }, [config, disableInjectCSS])\n }\n\n return (\n <ButtonInsideButtonContext.Provider value={false}>\n <TextAncestorProvider>\n <ThemeProvider\n defaultTheme={config.defaultTheme || 'light'}\n themeClassNameOnRoot={config.themeClassNameOnRoot}\n disableRootThemeClass={config.disableRootThemeClass}\n {...themePropsProvider}\n >\n {children}\n </ThemeProvider>\n </TextAncestorProvider>\n </ButtonInsideButtonContext.Provider>\n )\n}\n"],
5
- "mappings": "AAkBM;AAjBN,YAAY,WAAW;AAEvB,SAAS,UAAU,OAAO,aAAa;AACvC,SAAS,iCAAiC;AAC1C,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AAEvC,SAAS,qBAAqB;AAEvB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,KACG;AACL,GAAyB;AACvB,MAAI,OAAO;AACT,WACE,oBAAC;AAAA,MAAK,OAAO,EAAE,SAAS,WAAW;AAAA,MAAG,WAAW,KAAK,OAAO,gBAAgB;AAAA,MAC1E;AAAA,KACH;AAAA,EAEJ;AAEA,MAAI,CAAC,OAAO;AACV,2BAAuB;AAAA,EACzB;AAEA,MAAI,UAAU;AAGZ,UAAM,gBAAgB,MAAM;AAC1B,UAAI;AAAkB;AACtB,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,YAAY,SAAS,eAAe,OAAO,OAAO,CAAC,CAAC;AAC1D,eAAS,KAAK,YAAY,KAAK;AAC/B,aAAO,MAAM;AACX,iBAAS,KAAK,YAAY,KAAK;AAAA,MACjC;AAAA,IACF,GAAG,CAAC,QAAQ,gBAAgB,CAAC;AAAA,EAC/B;AAEA,SACE,oBAAC,0BAA0B,UAA1B;AAAA,IAAmC,OAAO;AAAA,IACzC,8BAAC;AAAA,MACC,8BAAC;AAAA,QACC,cAAc,OAAO,gBAAgB;AAAA,QACrC,sBAAsB,OAAO;AAAA,QAC7B,uBAAuB,OAAO;AAAA,QAC7B,GAAG;AAAA,QAEH;AAAA,OACH;AAAA,KACF;AAAA,GACF;AAEJ;",
4
+ "sourcesContent": ["import * as React from 'react'\n\nimport { isClient, isRSC, isServer } from '../constants/platform'\nimport { ButtonInsideButtonContext } from '../contexts/ButtonInsideButtonContext'\nimport { TextAncestorProvider } from '../contexts/TextAncestorContext'\nimport { useMediaQueryListeners } from '../hooks/useMedia'\nimport type { TamaguiProviderProps } from '../types'\nimport { ThemeProvider } from './ThemeProvider'\n\nexport function TamaguiProvider({\n children,\n disableInjectCSS,\n config,\n ...themePropsProvider\n}: TamaguiProviderProps) {\n if (isRSC) {\n return (\n <span style={{ display: 'contents' }} className={`t_${config.defaultTheme || 'light'}`}>\n {children}\n </span>\n )\n }\n\n if (!isServer) {\n useMediaQueryListeners(config)\n }\n\n if (isClient) {\n // inject CSS if asked to (not SSR compliant)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useLayoutEffect(() => {\n if (disableInjectCSS) return\n const style = document.createElement('style')\n style.appendChild(document.createTextNode(config.getCSS()))\n document.head.appendChild(style)\n return () => {\n document.head.removeChild(style)\n }\n }, [config, disableInjectCSS])\n }\n\n return (\n <ButtonInsideButtonContext.Provider value={false}>\n <TextAncestorProvider>\n <ThemeProvider\n defaultTheme={config.defaultTheme || 'light'}\n themeClassNameOnRoot={config.themeClassNameOnRoot}\n disableRootThemeClass={config.disableRootThemeClass}\n {...themePropsProvider}\n >\n {children}\n </ThemeProvider>\n </TextAncestorProvider>\n </ButtonInsideButtonContext.Provider>\n )\n}\n"],
5
+ "mappings": "AAiBM;AAjBN,YAAY,WAAW;AAEvB,SAAS,UAAU,OAAO,gBAAgB;AAC1C,SAAS,iCAAiC;AAC1C,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AAEvC,SAAS,qBAAqB;AAEvB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,KACG;AACL,GAAyB;AACvB,MAAI,OAAO;AACT,WACE,oBAAC;AAAA,MAAK,OAAO,EAAE,SAAS,WAAW;AAAA,MAAG,WAAW,KAAK,OAAO,gBAAgB;AAAA,MAC1E;AAAA,KACH;AAAA,EAEJ;AAEA,MAAI,CAAC,UAAU;AACb,2BAAuB,MAAM;AAAA,EAC/B;AAEA,MAAI,UAAU;AAGZ,UAAM,gBAAgB,MAAM;AAC1B,UAAI;AAAkB;AACtB,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,YAAY,SAAS,eAAe,OAAO,OAAO,CAAC,CAAC;AAC1D,eAAS,KAAK,YAAY,KAAK;AAC/B,aAAO,MAAM;AACX,iBAAS,KAAK,YAAY,KAAK;AAAA,MACjC;AAAA,IACF,GAAG,CAAC,QAAQ,gBAAgB,CAAC;AAAA,EAC/B;AAEA,SACE,oBAAC,0BAA0B,UAA1B;AAAA,IAAmC,OAAO;AAAA,IACzC,8BAAC;AAAA,MACC,8BAAC;AAAA,QACC,cAAc,OAAO,gBAAgB;AAAA,QACrC,sBAAsB,OAAO;AAAA,QAC7B,uBAAuB,OAAO;AAAA,QAC7B,GAAG;AAAA,QAEH;AAAA,OACH;AAAA,KACF;AAAA,GACF;AAEJ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.1-beta.167",
3
+ "version": "1.0.1-beta.169",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -28,14 +28,14 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@expo/match-media": "^0.3.0",
31
- "@tamagui/compose-refs": "^1.0.1-beta.167",
32
- "@tamagui/helpers": "^1.0.1-beta.167",
33
- "@tamagui/normalize-css-color-lite": "^1.0.1-beta.167",
34
- "@tamagui/rnw": "^1.0.1-beta.167",
35
- "@tamagui/rnw-lite": "^1.0.1-beta.167",
36
- "@tamagui/use-debounce": "^1.0.1-beta.167",
37
- "@tamagui/use-event": "^1.0.1-beta.167",
38
- "@tamagui/use-force-update": "^1.0.1-beta.167",
31
+ "@tamagui/compose-refs": "^1.0.1-beta.169",
32
+ "@tamagui/helpers": "^1.0.1-beta.169",
33
+ "@tamagui/normalize-css-color-lite": "^1.0.1-beta.169",
34
+ "@tamagui/rnw": "^1.0.1-beta.169",
35
+ "@tamagui/rnw-lite": "^1.0.1-beta.169",
36
+ "@tamagui/use-debounce": "^1.0.1-beta.169",
37
+ "@tamagui/use-event": "^1.0.1-beta.169",
38
+ "@tamagui/use-force-update": "^1.0.1-beta.169",
39
39
  "expo-screen-orientation": "^4.3.0",
40
40
  "hyphenate-style-name": "^1.0.4"
41
41
  },
@@ -44,7 +44,7 @@
44
44
  "react-dom": "*"
45
45
  },
46
46
  "devDependencies": {
47
- "@tamagui/build": "^1.0.1-beta.167",
47
+ "@tamagui/build": "^1.0.1-beta.169",
48
48
  "@types/react": "^18.0.15",
49
49
  "csstype": "^3.0.10",
50
50
  "esbuild": "^0.15.6",
package/src/addTheme.ts CHANGED
@@ -2,7 +2,7 @@ import { getConfig, updateConfig } from './config'
2
2
  import { isWeb } from './constants/platform'
3
3
  import { getThemeCSSRules } from './helpers/getThemeCSSRules'
4
4
  import { ensureThemeVariable, proxyThemeToParents } from './helpers/themes'
5
- import { ThemeObject } from './types'
5
+ import { ThemeDefinition, ThemeParsed } from './types'
6
6
 
7
7
  export function addTheme({
8
8
  name: themeName,
@@ -11,7 +11,7 @@ export function addTheme({
11
11
  update,
12
12
  }: {
13
13
  name: string
14
- theme: ThemeObject
14
+ theme: ThemeDefinition
15
15
  insertCSS?: boolean
16
16
  update?: boolean
17
17
  }) {
@@ -25,7 +25,7 @@ export function addTheme({
25
25
  }
26
26
  }
27
27
 
28
- const theme = { ...themeIn }
28
+ const theme = { ...themeIn } as ThemeParsed
29
29
  for (const key in theme) {
30
30
  ensureThemeVariable(theme, key)
31
31
  }
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ConfigListener, TamaguiInternalConfig } from './types'
1
+ import { ConfigListener, TamaguiInternalConfig, ThemeParsed } from './types'
2
2
 
3
3
  let conf: TamaguiInternalConfig | null
4
4
 
@@ -5,7 +5,7 @@ export const isAndroid = Platform?.OS === 'android'
5
5
  export const isIOS = Platform?.OS === 'ios'
6
6
  export const isWeb = false
7
7
  export const isWindowDefined = false
8
- export const isSSR = false
8
+ export const isServer = false
9
9
  export const isClient = false
10
10
  export const isRSC = false
11
11
  export const useIsomorphicLayoutEffect = useLayoutEffect
@@ -5,7 +5,7 @@ export const isAndroid = Platform?.OS === 'android'
5
5
  export const isIOS = Platform?.OS === 'ios'
6
6
  export const isWeb = process.env.TAMAGUI_TARGET === 'web'
7
7
  export const isWindowDefined = typeof window !== 'undefined'
8
- export const isSSR = isWeb && !isWindowDefined
8
+ export const isServer = isWeb && !isWindowDefined
9
9
  export const isClient = isWeb && isWindowDefined
10
10
 
11
11
  // may want to move to VITE_RSC_BUILD
@@ -19,7 +19,7 @@ export const isRSC = process.env.ENABLE_RSC
19
19
  : false
20
20
 
21
21
  const idFn = () => {}
22
- export const useIsomorphicLayoutEffect = isRSC ? idFn : isSSR ? useEffect : useLayoutEffect
22
+ export const useIsomorphicLayoutEffect = isRSC ? idFn : isServer ? useEffect : useLayoutEffect
23
23
  export const isChrome = typeof navigator !== 'undefined' && /Chrome/.test(navigator.userAgent || '')
24
24
  export const isWebTouchable = isClient && 'ontouchstart' in window
25
25
  export const isTouchable = !isWeb || isWebTouchable
@@ -21,6 +21,7 @@ import React, {
21
21
  useCallback,
22
22
  useContext,
23
23
  useEffect,
24
+ useLayoutEffect,
24
25
  } from 'react'
25
26
  import { Text, View, ViewStyle } from 'react-native'
26
27
 
@@ -42,7 +43,11 @@ import { getAllSelectors } from './helpers/insertStyleRule'
42
43
  import { mergeProps } from './helpers/mergeProps'
43
44
  import { proxyThemeVariables } from './helpers/proxyThemeVariables'
44
45
  import { useShallowSetState } from './helpers/useShallowSetState'
45
- import { addMediaQueryListener, mediaState, removeMediaQueryListener } from './hooks/useMedia'
46
+ import {
47
+ addMediaQueryListener,
48
+ getInitialMediaState,
49
+ removeMediaQueryListener,
50
+ } from './hooks/useMedia'
46
51
  import { usePressable } from './hooks/usePressable'
47
52
  import { useServerRef, useServerState } from './hooks/useServerHooks'
48
53
  import { getThemeManager, useTheme } from './hooks/useTheme'
@@ -67,16 +72,7 @@ import { wrapThemeManagerContext } from './views/Theme'
67
72
 
68
73
  React['keep']
69
74
 
70
- const defaultComponentState: TamaguiComponentState = Object.freeze({
71
- hover: false,
72
- press: false,
73
- pressIn: false,
74
- focus: false,
75
- // only used by enterStyle
76
- mounted: false,
77
- animation: null,
78
- })
79
-
75
+ let defaultComponentState: TamaguiComponentState | null = null
80
76
  export const mouseUps = new Set<Function>()
81
77
  if (typeof document !== 'undefined') {
82
78
  const cancelTouches = () => {
@@ -134,6 +130,7 @@ export function createComponent<
134
130
  }
135
131
 
136
132
  const debugProp = props['debug']
133
+
137
134
  const { Component, isText, isZStack } = staticConfig
138
135
  const componentName = props.componentName || staticConfig.componentName
139
136
  const componentClassName = props.asChild
@@ -146,10 +143,10 @@ export function createComponent<
146
143
  config = config || getConfig()
147
144
  const theme = useTheme(props.theme, componentName, props, forceUpdate)
148
145
 
149
- const states = useServerState<TamaguiComponentState>(defaultComponentState)
146
+ const states = useServerState<TamaguiComponentState>(defaultComponentState!)
150
147
  const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0]
151
148
 
152
- const shouldAvoidClasses = !!(props.animation && avoidClasses)
149
+ const shouldAvoidClasses = !!(props.animation && avoidClasses) || !staticConfig.acceptsClassName
153
150
  const shouldForcePseudo = !!propsIn.forceStyle
154
151
  const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)
155
152
  const splitStyleState =
@@ -198,6 +195,8 @@ export function createComponent<
198
195
  console.log('props', propsIn)
199
196
  // eslint-disable-next-line no-console
200
197
  console.log('splitStyles', splitStyles)
198
+ // eslint-disable-next-line no-console
199
+ console.log('className', Object.values(splitStyles.classNames))
201
200
  if (typeof window !== 'undefined') {
202
201
  // eslint-disable-next-line no-console
203
202
  console.log('ref', hostRef, '(click to view)')
@@ -215,14 +214,29 @@ export function createComponent<
215
214
 
216
215
  // media queries
217
216
  useIsomorphicLayoutEffect(() => {
218
- for (const key of mediaKeys) {
219
- addMediaQueryListener(key, forceUpdate)
217
+ if (!mediaKeys.length) {
218
+ return
220
219
  }
221
- return () => {
222
- for (const key of mediaKeys) {
223
- removeMediaQueryListener(key, forceUpdate)
224
- }
220
+ const disposers: any[] = []
221
+ for (const key of mediaKeys) {
222
+ disposers.push(
223
+ addMediaQueryListener(key, (next: boolean) => {
224
+ setState((prev) => {
225
+ if (prev.mediaState![key] !== next) {
226
+ return {
227
+ ...prev,
228
+ mediaState: {
229
+ ...prev.mediaState,
230
+ [key]: next,
231
+ },
232
+ }
233
+ }
234
+ return prev
235
+ })
236
+ })
237
+ )
225
238
  }
239
+ return () => {}
226
240
  }, [mediaKeys.join(',')])
227
241
 
228
242
  // animations
@@ -872,9 +886,9 @@ export function createComponent<
872
886
  let space = spaceProp
873
887
 
874
888
  // find space by media query
875
- if (mediaKeys.length) {
876
- for (const key in mediaState) {
877
- if (!mediaState[key]) continue
889
+ if (state.mediaState && mediaKeys.length) {
890
+ for (const key in state.mediaState) {
891
+ if (!state.mediaState[key]) continue
878
892
  if (props[key] && props[key].space !== undefined) {
879
893
  space = props[key].space
880
894
  }
@@ -1045,6 +1059,19 @@ export function createComponent<
1045
1059
  // Once configuration is run and all components are registered
1046
1060
  // get default props + className and analyze styles
1047
1061
  onConfiguredOnce((conf) => {
1062
+ if (!defaultComponentState) {
1063
+ defaultComponentState = Object.freeze({
1064
+ hover: false,
1065
+ press: false,
1066
+ pressIn: false,
1067
+ focus: false,
1068
+ // only used by enterStyle
1069
+ mounted: false,
1070
+ animation: null,
1071
+ mediaState: getInitialMediaState(),
1072
+ })
1073
+ }
1074
+
1048
1075
  // in static mode we just use these to lookup configuration
1049
1076
  // ... we likely want this? need to test
1050
1077
  if (process.env.IS_STATIC === 'is_static') return
@@ -1084,7 +1111,7 @@ export function createComponent<
1084
1111
  )
1085
1112
  }
1086
1113
 
1087
- const debug = true ? defaultPropsIn['debug'] : false
1114
+ const debug = defaultPropsIn['debug']
1088
1115
 
1089
1116
  if (process.env.NODE_ENV === 'development' && debug === 'break') {
1090
1117
  // eslint-disable-next-line no-debugger
@@ -1105,6 +1132,7 @@ export function createComponent<
1105
1132
  pressIn: false,
1106
1133
  focus: false,
1107
1134
  resolveVariablesAs: 'both',
1135
+ noClassNames: !staticConfig.acceptsClassName,
1108
1136
  keepVariantsAsProps: true,
1109
1137
  },
1110
1138
  undefined,
@@ -12,7 +12,7 @@ import { ensureThemeVariable, proxyThemeToParents } from './helpers/themes'
12
12
  import { configureMedia } from './hooks/useMedia'
13
13
  import { parseFont, registerFontVariables } from './insertFont'
14
14
  import { Tamagui } from './Tamagui'
15
- import { CreateTamaguiProps, InferTamaguiConfig, TamaguiInternalConfig, ThemeObject } from './types'
15
+ import { CreateTamaguiProps, InferTamaguiConfig, TamaguiInternalConfig, ThemeParsed } from './types'
16
16
 
17
17
  // config is re-run by the @tamagui/static, dont double validate
18
18
  const createdConfigs = new WeakMap<any, boolean>()
@@ -36,11 +36,6 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
36
36
  }
37
37
  }
38
38
 
39
- configureMedia({
40
- queries: configIn.media as any,
41
- defaultActive: configIn.mediaQueryDefaultActive,
42
- })
43
-
44
39
  const fontTokens = Object.fromEntries(
45
40
  Object.entries(configIn.fonts!).map(([k, v]) => {
46
41
  return [k, createVariables(v, 'f', true)]
@@ -107,16 +102,16 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
107
102
  // dedupe themes to avoid duplicate CSS generation
108
103
  type DedupedTheme = {
109
104
  names: string[]
110
- theme: ThemeObject
105
+ theme: ThemeParsed
111
106
  }
112
107
  const dedupedThemes: {
113
108
  [key: string]: DedupedTheme
114
109
  } = {}
115
- const existing = new WeakMap<ThemeObject, DedupedTheme>()
110
+ const existing = new WeakMap<ThemeParsed, DedupedTheme>()
116
111
 
117
112
  // first, de-dupe and parse them
118
113
  for (const themeName in themes) {
119
- const rawTheme = themes[themeName]
114
+ const rawTheme = themes[themeName] as ThemeParsed
120
115
 
121
116
  // if existing, avoid
122
117
  if (existing.has(rawTheme)) {
@@ -167,6 +162,7 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
167
162
  const css = cssRuleSets.join('\n')
168
163
 
169
164
  return {
165
+ // could improve types but we do ensureThemeVariable so its accurate
170
166
  themes,
171
167
  cssRuleSets,
172
168
  css,
@@ -193,7 +189,7 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
193
189
  inverseShorthands: shorthands
194
190
  ? Object.fromEntries(Object.entries(shorthands).map(([k, v]) => [v, k]))
195
191
  : {},
196
- themes: themeConfig.themes,
192
+ themes: themeConfig.themes as any,
197
193
  fontsParsed,
198
194
  themeConfig,
199
195
  tokensParsed,
@@ -201,6 +197,7 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
201
197
  getCSS,
202
198
  }
203
199
 
200
+ configureMedia(config)
204
201
  setConfig(config)
205
202
 
206
203
  if (configListeners.size) {
@@ -3,7 +3,7 @@ import { createContext } from 'react'
3
3
  import { getThemes } from '../config'
4
4
  import { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants'
5
5
  import { getThemeUnwrapped } from '../hooks/getThemeUnwrapped'
6
- import { ThemeObject, Themes } from '../types'
6
+ import { ThemeParsed, Themes } from '../types'
7
7
 
8
8
  type ThemeListener = (name: string | null, themeManager: ThemeManager) => void
9
9
 
@@ -29,7 +29,7 @@ export class ThemeManager {
29
29
  constructor(
30
30
  public name: string = '',
31
31
  public className: string = '',
32
- public theme: ThemeObject | null = null,
32
+ public theme: ThemeParsed | null = null,
33
33
  public parentManager: ThemeManager | null = null,
34
34
  public reset: boolean = false
35
35
  ) {
@@ -109,7 +109,7 @@ export class ThemeManager {
109
109
  debug?: any
110
110
  ): {
111
111
  name: string
112
- theme: ThemeObject | null
112
+ theme: ThemeParsed | null
113
113
  className: string | undefined
114
114
  } {
115
115
  const { themes = getThemes(), name, componentName } = props
@@ -117,7 +117,7 @@ export class ThemeManager {
117
117
  if (props.reset && name) {
118
118
  return {
119
119
  name: name,
120
- theme: themes[name],
120
+ theme: themes[name] as ThemeParsed,
121
121
  className: this.getClassName(name),
122
122
  }
123
123
  }