@tamagui/core 1.0.1-beta.166 → 1.0.1-beta.168

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 (103) 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 +4 -2
  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/createVariable.js +9 -0
  12. package/dist/cjs/createVariable.js.map +2 -2
  13. package/dist/cjs/helpers/ThemeManager.js.map +1 -1
  14. package/dist/cjs/helpers/getSplitStyles.js +16 -9
  15. package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
  16. package/dist/cjs/helpers/getThemeCSSRules.js.map +1 -1
  17. package/dist/cjs/helpers/isTamaguiElement.js.map +2 -2
  18. package/dist/cjs/hooks/useIsSSR.js +8 -4
  19. package/dist/cjs/hooks/useIsSSR.js.map +2 -2
  20. package/dist/cjs/hooks/useIsTouchDevice.js +1 -1
  21. package/dist/cjs/hooks/useIsTouchDevice.js.map +2 -2
  22. package/dist/cjs/hooks/useMedia.js +48 -29
  23. package/dist/cjs/hooks/useMedia.js.map +2 -2
  24. package/dist/cjs/hooks/useTheme.js +1 -1
  25. package/dist/cjs/hooks/useTheme.js.map +2 -2
  26. package/dist/cjs/styled.js +11 -8
  27. package/dist/cjs/styled.js.map +2 -2
  28. package/dist/cjs/types.js.map +1 -1
  29. package/dist/cjs/updateTheme.js.map +2 -2
  30. package/dist/cjs/views/TamaguiProvider.js +2 -2
  31. package/dist/cjs/views/TamaguiProvider.js.map +2 -2
  32. package/dist/esm/addTheme.js.map +1 -1
  33. package/dist/esm/config.js.map +1 -1
  34. package/dist/esm/constants/platform.js +3 -3
  35. package/dist/esm/constants/platform.js.map +2 -2
  36. package/dist/esm/constants/platform.native.js +2 -2
  37. package/dist/esm/constants/platform.native.js.map +2 -2
  38. package/dist/esm/createComponent.js +4 -2
  39. package/dist/esm/createComponent.js.map +2 -2
  40. package/dist/esm/createTamagui.js +1 -4
  41. package/dist/esm/createTamagui.js.map +2 -2
  42. package/dist/esm/createVariable.js +8 -0
  43. package/dist/esm/createVariable.js.map +2 -2
  44. package/dist/esm/helpers/ThemeManager.js.map +1 -1
  45. package/dist/esm/helpers/getSplitStyles.js +16 -9
  46. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  47. package/dist/esm/helpers/getThemeCSSRules.js.map +1 -1
  48. package/dist/esm/helpers/isTamaguiElement.js.map +2 -2
  49. package/dist/esm/hooks/useIsSSR.js +9 -5
  50. package/dist/esm/hooks/useIsSSR.js.map +2 -2
  51. package/dist/esm/hooks/useIsTouchDevice.js +2 -2
  52. package/dist/esm/hooks/useIsTouchDevice.js.map +2 -2
  53. package/dist/esm/hooks/useMedia.js +49 -30
  54. package/dist/esm/hooks/useMedia.js.map +2 -2
  55. package/dist/esm/hooks/useTheme.js +2 -2
  56. package/dist/esm/hooks/useTheme.js.map +2 -2
  57. package/dist/esm/styled.js +11 -8
  58. package/dist/esm/styled.js.map +2 -2
  59. package/dist/esm/updateTheme.js.map +2 -2
  60. package/dist/esm/views/TamaguiProvider.js +3 -3
  61. package/dist/esm/views/TamaguiProvider.js.map +2 -2
  62. package/package.json +10 -10
  63. package/src/addTheme.ts +3 -3
  64. package/src/config.ts +1 -1
  65. package/src/constants/platform.native.ts +1 -1
  66. package/src/constants/platform.ts +2 -2
  67. package/src/createComponent.tsx +10 -2
  68. package/src/createTamagui.ts +7 -10
  69. package/src/createVariable.ts +8 -1
  70. package/src/helpers/ThemeManager.tsx +4 -4
  71. package/src/helpers/getSplitStyles.tsx +25 -12
  72. package/src/helpers/getThemeCSSRules.ts +2 -2
  73. package/src/helpers/isTamaguiElement.tsx +3 -5
  74. package/src/hooks/useIsSSR.tsx +10 -5
  75. package/src/hooks/useIsTouchDevice.tsx +2 -2
  76. package/src/hooks/useMedia.tsx +65 -36
  77. package/src/hooks/useTheme.tsx +6 -6
  78. package/src/styled.tsx +40 -12
  79. package/src/types.tsx +45 -12
  80. package/src/updateTheme.ts +2 -2
  81. package/src/views/TamaguiProvider.tsx +3 -4
  82. package/types/addTheme.d.ts +2 -2
  83. package/types/config.d.ts +18 -2
  84. package/types/constants/platform.d.ts +1 -1
  85. package/types/constants/platform.native.d.ts +1 -1
  86. package/types/createVariable.d.ts +5 -0
  87. package/types/helpers/ThemeManager.d.ts +5 -5
  88. package/types/helpers/calc.d.ts +5 -0
  89. package/types/helpers/expandStyle.d.ts +4 -0
  90. package/types/helpers/expandStyles.d.ts +7 -0
  91. package/types/helpers/getSplitStyles.d.ts +3 -3
  92. package/types/helpers/getStylesAtomic.d.ts +4 -0
  93. package/types/helpers/getThemeCSSRules.d.ts +2 -2
  94. package/types/helpers/isTamaguiElement.d.ts +4 -6
  95. package/types/helpers/mergeProps.d.ts +13 -0
  96. package/types/helpers/normalizeValueWithProperty.d.ts +4 -0
  97. package/types/hooks/useIsSSR.d.ts +3 -1
  98. package/types/hooks/useMedia.d.ts +3 -3
  99. package/types/hooks/useTheme.d.ts +4 -4
  100. package/types/insertFont.d.ts +3 -0
  101. package/types/styled.d.ts +5 -1
  102. package/types/types.d.ts +112 -12
  103. 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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Content": ["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\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,iCAAiC;AAC3D,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,WACA,eACA,OACA,gBACgB;AAEhB,MAAI,OAAO;AACT,UAAM,SAAS,UAAU;AAEzB,WAAO,gBAAgB,OAAO,OAAO,OAAO,eAAe,OAAO,YAAY;AAAA,EAChF;AAEA,QAAM,QAAQ,aAAa;AAC3B,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,UAAU,IAAI;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,QAAQ;AAAA,EAChB;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,SAAI,+BAAO,WAAU,WAAW;AAE9B,cAAQ,eAAe,2BAAoB,IAAI;AAC/C,YAAM,OAAO,EAAE,WAAW,eAAe,MAAM,WAAW,GAAI,cAAc,EAAE,MAAM,EAAG;AACvF,iBAAW,OAAO,MAAM;AAEtB,gBAAQ,IAAI,MAAM,KAAK,KAAK,IAAI;AAAA,MAClC;AAEA,cAAQ,SAAS;AAAA,IACnB;AAAA,EACF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,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 { 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\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 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 type ParentPropsBase = ParentComponent extends TamaguiComponent<any, any, infer P>\n ? P\n : GetProps<ParentComponent>\n type ParentVariants = ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}\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;AAChC,SAAS,oBAAoB;AAqBtB,SAAS,OAId,WAEA,SAMA,yBACA;AACA,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;AA4B9D,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.166",
3
+ "version": "1.0.1-beta.168",
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.166",
32
- "@tamagui/helpers": "^1.0.1-beta.166",
33
- "@tamagui/normalize-css-color-lite": "^1.0.1-beta.166",
34
- "@tamagui/rnw": "^1.0.1-beta.166",
35
- "@tamagui/rnw-lite": "^1.0.1-beta.166",
36
- "@tamagui/use-debounce": "^1.0.1-beta.166",
37
- "@tamagui/use-event": "^1.0.1-beta.166",
38
- "@tamagui/use-force-update": "^1.0.1-beta.166",
31
+ "@tamagui/compose-refs": "^1.0.1-beta.168",
32
+ "@tamagui/helpers": "^1.0.1-beta.168",
33
+ "@tamagui/normalize-css-color-lite": "^1.0.1-beta.168",
34
+ "@tamagui/rnw": "^1.0.1-beta.168",
35
+ "@tamagui/rnw-lite": "^1.0.1-beta.168",
36
+ "@tamagui/use-debounce": "^1.0.1-beta.168",
37
+ "@tamagui/use-event": "^1.0.1-beta.168",
38
+ "@tamagui/use-force-update": "^1.0.1-beta.168",
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.166",
47
+ "@tamagui/build": "^1.0.1-beta.168",
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
 
@@ -134,6 +135,7 @@ export function createComponent<
134
135
  }
135
136
 
136
137
  const debugProp = props['debug']
138
+
137
139
  const { Component, isText, isZStack } = staticConfig
138
140
  const componentName = props.componentName || staticConfig.componentName
139
141
  const componentClassName = props.asChild
@@ -149,7 +151,7 @@ export function createComponent<
149
151
  const states = useServerState<TamaguiComponentState>(defaultComponentState)
150
152
  const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0]
151
153
 
152
- const shouldAvoidClasses = !!(props.animation && avoidClasses)
154
+ const shouldAvoidClasses = !!(props.animation && avoidClasses) || !staticConfig.acceptsClassName
153
155
  const shouldForcePseudo = !!propsIn.forceStyle
154
156
  const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)
155
157
  const splitStyleState =
@@ -198,6 +200,8 @@ export function createComponent<
198
200
  console.log('props', propsIn)
199
201
  // eslint-disable-next-line no-console
200
202
  console.log('splitStyles', splitStyles)
203
+ // eslint-disable-next-line no-console
204
+ console.log('className', Object.values(splitStyles.classNames))
201
205
  if (typeof window !== 'undefined') {
202
206
  // eslint-disable-next-line no-console
203
207
  console.log('ref', hostRef, '(click to view)')
@@ -215,6 +219,9 @@ export function createComponent<
215
219
 
216
220
  // media queries
217
221
  useIsomorphicLayoutEffect(() => {
222
+ // if (!mediaKeys.length) {
223
+ // return
224
+ // }
218
225
  for (const key of mediaKeys) {
219
226
  addMediaQueryListener(key, forceUpdate)
220
227
  }
@@ -1084,7 +1091,7 @@ export function createComponent<
1084
1091
  )
1085
1092
  }
1086
1093
 
1087
- const debug = true ? defaultPropsIn['debug'] : false
1094
+ const debug = defaultPropsIn['debug']
1088
1095
 
1089
1096
  if (process.env.NODE_ENV === 'development' && debug === 'break') {
1090
1097
  // eslint-disable-next-line no-debugger
@@ -1105,6 +1112,7 @@ export function createComponent<
1105
1112
  pressIn: false,
1106
1113
  focus: false,
1107
1114
  resolveVariablesAs: 'both',
1115
+ noClassNames: !staticConfig.acceptsClassName,
1108
1116
  keepVariantsAsProps: true,
1109
1117
  },
1110
1118
  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) {
@@ -1,5 +1,6 @@
1
- import { isValidCSSCharCode, simpleHash } from '@tamagui/helpers'
1
+ import { simpleHash } from '@tamagui/helpers'
2
2
 
3
+ import { getConfig } from './config'
3
4
  import { isWeb } from './constants/platform'
4
5
 
5
6
  /**
@@ -49,6 +50,12 @@ export function isVariable(v: Variable | any): v is Variable {
49
50
  return !!(v && v[IS_VAR])
50
51
  }
51
52
 
53
+ export function getVariable(nameOrVariable: Variable | string) {
54
+ if (isVariable(nameOrVariable)) return variableToString(nameOrVariable)
55
+ const tokens = getConfig().tokensParsed
56
+ return variableToString(tokens[nameOrVariable] ?? nameOrVariable)
57
+ }
58
+
52
59
  export function getVariableValue(v: Variable | any) {
53
60
  if (isVariable(v)) return v.val
54
61
  return v
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  import { stylePropsText, stylePropsTransform, validPseudoKeys, validStyles } from '@tamagui/helpers'
2
- import { useInsertionEffect, useMemo } from 'react'
2
+ import { useInsertionEffect } from 'react'
3
3
  import type { ViewStyle } from 'react-native'
4
4
 
5
5
  import { getConfig } from '../config'
@@ -15,7 +15,7 @@ import type {
15
15
  StackProps,
16
16
  StaticConfigParsed,
17
17
  TamaguiInternalConfig,
18
- ThemeObject,
18
+ ThemeParsed,
19
19
  } from '../types'
20
20
  import { FontLanguageProps, LanguageContextType } from '../views/FontLanguage.types'
21
21
  import { createMediaStyle } from './createMediaStyle'
@@ -30,6 +30,7 @@ import {
30
30
  updateInserted,
31
31
  updateRules,
32
32
  } from './insertStyleRule'
33
+ import { mergeProps } from './mergeProps'
33
34
  import { mergeTransform } from './mergeTransform'
34
35
  import { normalizeValueWithProperty } from './normalizeValueWithProperty.js'
35
36
  import { pseudoDescriptors } from './pseudoDescriptors'
@@ -66,7 +67,7 @@ let conf: TamaguiInternalConfig
66
67
  type StyleSplitter = (
67
68
  props: { [key: string]: any },
68
69
  staticConfig: StaticConfigParsed,
69
- theme: ThemeObject,
70
+ theme: ThemeParsed,
70
71
  state: SplitStyleState,
71
72
  defaultClassNames?: any,
72
73
  languageContext?: LanguageContextType,
@@ -117,7 +118,10 @@ export const getSplitStyles: StyleSplitter = (
117
118
  const usedKeys = new Set<string>()
118
119
  const propKeys = Object.keys(props)
119
120
  const shouldDoClasses =
120
- (isWeb || process.env.IS_STATIC === 'is_static') && !state.noClassNames && !props.animation
121
+ staticConfig.acceptsClassName &&
122
+ (isWeb || process.env.IS_STATIC === 'is_static') &&
123
+ !state.noClassNames &&
124
+ !props.animation
121
125
  const len = propKeys.length
122
126
  const rulesToInsert: RulesToInsert = []
123
127
  const style: ViewStyle = {}
@@ -126,7 +130,7 @@ export const getSplitStyles: StyleSplitter = (
126
130
  // parity with react-native-web
127
131
  style.display = 'inline-flex' as any
128
132
  }
129
- let classNames: ClassNamesObject = {}
133
+ const classNames: ClassNamesObject = {}
130
134
  // we need to gather these specific to each media query / pseudo
131
135
  // value is [hash, val], so ["-jnjad-asdnjk", "scaleX(1) rotate(10deg)"]
132
136
  const transforms: Record<TransformNamespaceKey, [string, string]> = {}
@@ -346,10 +350,18 @@ export const getSplitStyles: StyleSplitter = (
346
350
  // media
347
351
  if (isMedia) {
348
352
  const mediaKey = key
349
- mediaKeys.push(key)
350
353
  const mediaKeyShort = mediaKey.slice(1)
351
354
 
355
+ mediaKeys.push(mediaKeyShort)
356
+
352
357
  if (!mediaQueryConfig[mediaKeyShort]) {
358
+ if (process.env.NODE_ENV === 'development' && debug) {
359
+ // eslint-disable-next-line no-console
360
+ console.warn(
361
+ `Warning: using a $ prefixed prop that doesn't match to a media query, may be an error`,
362
+ key
363
+ )
364
+ }
353
365
  if (!usedKeys.has(key)) {
354
366
  // this isn't a media key, pass through
355
367
  viewProps[key] = val
@@ -376,7 +388,7 @@ export const getSplitStyles: StyleSplitter = (
376
388
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
377
389
  // prettier-ignore
378
390
  // eslint-disable-next-line no-console
379
- console.log(' 🔹 mediaStyle', { mediaKey, mediaStyle, props, shouldDoClasses })
391
+ console.log(` 📺 ${mediaKey}`, mediaState[mediaKeyShort], { mediaKey, mediaStyle, props, shouldDoClasses, mediaState: { ...mediaState } })
380
392
  }
381
393
 
382
394
  if (shouldDoClasses) {
@@ -391,7 +403,7 @@ export const getSplitStyles: StyleSplitter = (
391
403
  }
392
404
  }
393
405
  } else {
394
- if (mediaState[mediaKey]) {
406
+ if (mediaState[mediaKeyShort]) {
395
407
  if (process.env.NODE_ENV === 'development' && debug) {
396
408
  // eslint-disable-next-line no-console
397
409
  console.log('apply media style', mediaKey, mediaState)
@@ -447,9 +459,10 @@ export const getSplitStyles: StyleSplitter = (
447
459
 
448
460
  // add in defaults if not set:
449
461
  if (defaultClassNames) {
450
- classNames = {
451
- ...defaultClassNames,
452
- ...classNames,
462
+ for (const key in defaultClassNames) {
463
+ if (!(key in classNames)) {
464
+ classNames[key] = defaultClassNames[key]
465
+ }
453
466
  }
454
467
  }
455
468
 
@@ -646,7 +659,7 @@ export const getSubStyle = (
646
659
  subKey: string,
647
660
  styleIn: Object,
648
661
  staticConfig: StaticConfigParsed,
649
- theme: ThemeObject,
662
+ theme: ThemeParsed,
650
663
  props: any,
651
664
  state: SplitStyleState,
652
665
  conf: TamaguiInternalConfig,
@@ -1,6 +1,6 @@
1
1
  import { THEME_CLASSNAME_PREFIX } from '../constants/constants'
2
2
  import { Variable, variableToString } from '../createVariable'
3
- import { CreateTamaguiProps, ThemeObject } from '../types'
3
+ import { CreateTamaguiProps, ThemeParsed } from '../types'
4
4
  import { tokensValueToVariable } from './registerCSSVariable'
5
5
 
6
6
  export function getThemeCSSRules({
@@ -11,7 +11,7 @@ export function getThemeCSSRules({
11
11
  }: {
12
12
  config: CreateTamaguiProps
13
13
  themeName: string
14
- theme: ThemeObject
14
+ theme: ThemeParsed
15
15
  names: string[]
16
16
  }) {
17
17
  const cssRuleSets: string[] = []