@tamagui/web 1.14.7 → 1.14.8

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 (108) hide show
  1. package/dist/cjs/helpers/ThemeManager.js +4 -1
  2. package/dist/cjs/helpers/ThemeManager.js.map +2 -2
  3. package/dist/cjs/hooks/useTheme.js +50 -24
  4. package/dist/cjs/hooks/useTheme.js.map +2 -2
  5. package/dist/cjs/views/ThemeDebug.js +57 -38
  6. package/dist/cjs/views/ThemeDebug.js.map +2 -2
  7. package/dist/esm/helpers/ThemeManager.js +4 -1
  8. package/dist/esm/helpers/ThemeManager.js.map +2 -2
  9. package/dist/esm/helpers/ThemeManager.mjs +4 -1
  10. package/dist/esm/helpers/ThemeManager.mjs.map +2 -2
  11. package/dist/esm/hooks/useTheme.js +50 -24
  12. package/dist/esm/hooks/useTheme.js.map +2 -2
  13. package/dist/esm/hooks/useTheme.mjs +50 -24
  14. package/dist/esm/hooks/useTheme.mjs.map +2 -2
  15. package/dist/esm/views/ThemeDebug.js +59 -40
  16. package/dist/esm/views/ThemeDebug.js.map +2 -2
  17. package/dist/esm/views/ThemeDebug.mjs +59 -40
  18. package/dist/esm/views/ThemeDebug.mjs.map +2 -2
  19. package/package.json +9 -9
  20. package/src/helpers/ThemeManager.tsx +5 -1
  21. package/src/hooks/useTheme.tsx +54 -26
  22. package/src/views/ThemeDebug.tsx +55 -34
  23. package/types/Tamagui.d.ts.map +1 -0
  24. package/types/addTheme.d.ts.map +1 -0
  25. package/types/config.d.ts.map +1 -0
  26. package/types/constants/constants.d.ts.map +1 -0
  27. package/types/constants/isDevTools.d.ts.map +1 -0
  28. package/types/contexts/AnimationDriverContext.d.ts.map +1 -0
  29. package/types/contexts/ButtonNestingContext.d.ts.map +1 -0
  30. package/types/contexts/FontLanguageContext.d.ts.map +1 -0
  31. package/types/contexts/TextAncestorContext.d.ts.map +1 -0
  32. package/types/createComponent.d.ts.map +1 -0
  33. package/types/createFont.d.ts.map +1 -0
  34. package/types/createShorthands.d.ts.map +1 -0
  35. package/types/createTamagui.d.ts.map +1 -0
  36. package/types/createTheme.d.ts.map +1 -0
  37. package/types/createTokens.d.ts.map +1 -0
  38. package/types/createVariable.d.ts.map +1 -0
  39. package/types/createVariables.d.ts.map +1 -0
  40. package/types/helpers/ThemeManager.d.ts.map +1 -0
  41. package/types/helpers/ThemeManagerContext.d.ts.map +1 -0
  42. package/types/helpers/createMediaStyle.d.ts.map +1 -0
  43. package/types/helpers/createPropMapper.d.ts.map +1 -0
  44. package/types/helpers/createProxy.d.ts.map +1 -0
  45. package/types/helpers/defaultOffset.d.ts.map +1 -0
  46. package/types/helpers/expandStyle.d.ts.map +1 -0
  47. package/types/helpers/expandStyles.d.ts.map +1 -0
  48. package/types/helpers/extendStaticConfig.d.ts.map +1 -0
  49. package/types/helpers/getAnimationDriver.d.ts.map +1 -0
  50. package/types/helpers/getExpandedShorthands.d.ts.map +1 -0
  51. package/types/helpers/getFontLanguage.d.ts.map +1 -0
  52. package/types/helpers/getSplitStyles.d.ts.map +1 -0
  53. package/types/helpers/getStylesAtomic.d.ts.map +1 -0
  54. package/types/helpers/getStylesAtomic.native.d.ts.map +1 -0
  55. package/types/helpers/getThemeCSSRules.d.ts.map +1 -0
  56. package/types/helpers/getThemeCSSRules.native.d.ts.map +1 -0
  57. package/types/helpers/getVariantExtras.d.ts.map +1 -0
  58. package/types/helpers/insertStyleRule.d.ts.map +1 -0
  59. package/types/helpers/isObj.d.ts.map +1 -0
  60. package/types/helpers/isTamaguiComponent.d.ts.map +1 -0
  61. package/types/helpers/isTamaguiElement.d.ts.map +1 -0
  62. package/types/helpers/matchMedia.d.ts.map +1 -0
  63. package/types/helpers/matchMedia.native.d.ts.map +1 -0
  64. package/types/helpers/mergeProps.d.ts.map +1 -0
  65. package/types/helpers/normalizeColor.d.ts.map +1 -0
  66. package/types/helpers/normalizeShadow.d.ts.map +1 -0
  67. package/types/helpers/normalizeShadow.native.d.ts.map +1 -0
  68. package/types/helpers/normalizeStylePropKeys.d.ts.map +1 -0
  69. package/types/helpers/normalizeStylePropKeys.native.d.ts.map +1 -0
  70. package/types/helpers/normalizeValueWithProperty.d.ts.map +1 -0
  71. package/types/helpers/proxyThemeVariables.d.ts.map +1 -0
  72. package/types/helpers/pseudoDescriptors.d.ts.map +1 -0
  73. package/types/helpers/registerCSSVariable.d.ts.map +1 -0
  74. package/types/helpers/themeable.d.ts.map +1 -0
  75. package/types/helpers/themes.d.ts.map +1 -0
  76. package/types/helpers/timer.d.ts.map +1 -0
  77. package/types/helpers/useShallowSetState.d.ts.map +1 -0
  78. package/types/helpers/warnOnce.d.ts.map +1 -0
  79. package/types/helpers/withStaticProperties.d.ts.map +1 -0
  80. package/types/hooks/getThemeUnwrapped.d.ts.map +1 -0
  81. package/types/hooks/useAnimationDriver.d.ts.map +1 -0
  82. package/types/hooks/useId.d.ts.map +1 -0
  83. package/types/hooks/useIsTouchDevice.d.ts.map +1 -0
  84. package/types/hooks/useMedia.d.ts.map +1 -0
  85. package/types/hooks/useSafeRef.d.ts.map +1 -0
  86. package/types/hooks/useServerHooks.d.ts.map +1 -0
  87. package/types/hooks/useStyle.d.ts.map +1 -0
  88. package/types/hooks/useTheme.d.ts.map +1 -0
  89. package/types/hooks/useThemeName.d.ts.map +1 -0
  90. package/types/index.d.ts.map +1 -0
  91. package/types/inject-styles.d.ts.map +1 -0
  92. package/types/insertFont.d.ts.map +1 -0
  93. package/types/setupHooks.d.ts.map +1 -0
  94. package/types/setupReactNative.d.ts.map +1 -0
  95. package/types/styled.d.ts.map +1 -0
  96. package/types/types.d.ts.map +1 -0
  97. package/types/updateTheme.d.ts.map +1 -0
  98. package/types/views/AnimationDriverProvider.d.ts.map +1 -0
  99. package/types/views/FontLanguage.d.ts.map +1 -0
  100. package/types/views/FontLanguage.native.d.ts.map +1 -0
  101. package/types/views/FontLanguage.types.d.ts.map +1 -0
  102. package/types/views/Slot.d.ts.map +1 -0
  103. package/types/views/Stack.d.ts.map +1 -0
  104. package/types/views/TamaguiProvider.d.ts.map +1 -0
  105. package/types/views/Text.d.ts.map +1 -0
  106. package/types/views/Theme.d.ts.map +1 -0
  107. package/types/views/ThemeDebug.d.ts.map +1 -0
  108. package/types/views/ThemeProvider.d.ts.map +1 -0
@@ -166,6 +166,9 @@ function getState(props, parentManager) {
166
166
  if (props.name && props.reset) {
167
167
  throw new Error("Cannot reset + set new name");
168
168
  }
169
+ if (!props.name && !props.inverse && !props.reset && !props.componentName) {
170
+ return null;
171
+ }
169
172
  if (props.reset && !(parentManager == null ? void 0 : parentManager.parentManager)) {
170
173
  if (process.env.NODE_ENV === "development") {
171
174
  console.warn("Cannot reset no grandparent exists");
@@ -227,7 +230,7 @@ function getState(props, parentManager) {
227
230
  }
228
231
  const found = potentials.find((t) => t in themes);
229
232
  if (process.env.NODE_ENV === "development" && typeof props.debug === "string") {
230
- console.log(" - ", { found, potentials });
233
+ console.log(" - ", { found, potentials, parentManager });
231
234
  }
232
235
  if (found) {
233
236
  result = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/ThemeManager.tsx"],
4
- "sourcesContent": ["import { getThemes, getTokens } from '../config.js'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants.js'\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { ThemeParsed, ThemeProps } from '../types.js'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n reset?: boolean\n}\n\nexport type ThemeManagerState = {\n name: string\n theme?: ThemeParsed | null\n className?: string\n parentName?: string\n}\n\nconst emptyState: ThemeManagerState = { name: '' }\n\nexport function hasNoThemeUpdatingProps(props: ThemeProps) {\n return !(props.name || props.componentName || props.inverse || props.reset)\n}\n\nlet uid = 0\n\nexport class ThemeManager {\n id = uid++\n isComponent = false\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManagerIn?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManagerIn === 'root') {\n this.updateState(props, false)\n return\n }\n\n const parentManager = getNonComponentParentManager(parentManagerIn)\n\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `No parent manager given, this is likely due to duplicated Tamagui dependencies. Check your lockfile for mis-matched versions.`\n )\n }\n throw `\u274C`\n }\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n\n if (parentManager) {\n this.parentManager = parentManager\n }\n\n if (this.updateState(props, false)) {\n return\n }\n\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n shouldNotify = true\n ) {\n const isChanging = (() => {\n if (props.forceTheme) {\n this.state.theme = props.forceTheme\n this.state.name = props.name || ''\n return true\n }\n const nextState = this.getStateIfChanged(props)\n if (nextState) {\n this.props = props\n this.state = nextState\n return true\n }\n })()\n\n if (isChanging) {\n const names = this.state.name.split('_')\n const lastName = names[names.length - 1][0]\n this.isComponent = lastName[0] === lastName[0].toUpperCase()\n this._allKeys = null\n\n if (process.env.NODE_ENV === 'development') {\n this['_numChangeEventsSent'] ??= 0\n this['_numChangeEventsSent']++\n }\n\n if (shouldNotify) {\n this.notify()\n }\n\n return this.state\n }\n }\n\n getStateIfChanged(\n props = this.props,\n state: ThemeManagerState | null = this.state,\n parentManager = this.parentManager\n ) {\n const _ = this.getState(props, parentManager)\n // is removing\n if (state && state !== emptyState && !_) {\n return parentManager?.state\n }\n if (this.getStateShouldChange(_, state)) {\n return _\n }\n }\n\n getStateShouldChange(\n nextState: ThemeManagerState | null,\n state: ThemeManagerState | null = this.state\n ) {\n if (!nextState?.theme || nextState.theme === state?.theme) {\n return false\n }\n return true\n }\n\n getState(props = this.props, parentManager = this.parentManager) {\n return (\n getState(props, parentManager) ||\n (process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)\n )\n }\n\n _allKeys: Set<string> | null = null\n get allKeys() {\n this._allKeys ||= new Set([\n ...(this.parentManager?.allKeys || []),\n ...Object.keys(this.state.theme || {}),\n ])\n return this._allKeys\n }\n\n // gets value going up to parents\n getValue(key: string, state?: ThemeManagerState) {\n if (!key) return\n let theme = (state || this.state).theme\n let manager = this as ThemeManager | null\n while (theme && manager) {\n if (key in theme) {\n return theme[key]\n }\n manager = manager.parentManager\n theme = manager?.state.theme\n }\n const tokens = getTokens()\n if (key in tokens.color) {\n return tokens.color[key]\n }\n }\n\n notify() {\n this.themeListeners.forEach((cb) => cb(this.state.name, this))\n }\n\n onChangeTheme(cb: ThemeListener, debugId?: number) {\n if (process.env.NODE_ENV === 'development' && debugId) {\n // @ts-ignore\n this._listeningIds ??= new Set()\n // @ts-ignore\n this._listeningIds.add(debugId)\n }\n\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, props: ThemeProps) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (props.inverse || props.forceClassName) {\n return (\n next +\n // ensure you invert to base dark as well as specific dark\n // ... logic should likely be elsewhere\n (next.includes('dark_') ? ` t_dark` : next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n\n if (props.reset && !parentManager?.parentManager) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('Cannot reset no grandparent exists')\n }\n return null\n }\n\n let result: ThemeManagerState | null = null\n\n const nextName = props.reset\n ? parentManager?.parentManager?.state?.name || ''\n : props.name || ''\n const { componentName } = props\n const parentName = parentManager?.state?.name || ''\n\n // components look for most specific, fallback upwards\n const base = parentName.split(THEME_NAME_SEPARATOR)\n const lastSegment = base[base.length - 1]\n const isParentComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentComponentTheme\n ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)\n : parentName\n const max = base.length\n const min =\n componentName && !nextName\n ? max // component name only don't search upwards\n : 0\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.groupCollapsed('ThemeManager.getState()')\n console.log({\n props,\n parentName,\n parentBaseTheme,\n base,\n min,\n max,\n isParentComponentTheme,\n })\n }\n\n for (let i = max; i >= min; i--) {\n let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)\n if (props.inverse) {\n prefix = inverseThemeName(prefix)\n }\n const potentials: string[] = []\n if (prefix && prefix !== parentBaseTheme) {\n potentials.push(prefix)\n }\n if (nextName) {\n potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)\n }\n if (i === 1) {\n const lastSegment = potentials.findIndex((x) => !x.includes('_'))\n if (lastSegment > 0) {\n potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent\n }\n }\n if (componentName) {\n // components only look for component themes\n if (nextName) {\n const beforeSeparator = prefix.slice(0, prefix.indexOf(THEME_NAME_SEPARATOR))\n potentials.push(`${beforeSeparator}_${nextName}_${componentName}`)\n }\n potentials.push(`${prefix}_${componentName}`)\n if (nextName) {\n potentials.unshift(`${prefix}_${nextName}_${componentName}`)\n }\n }\n\n const found = potentials.find((t) => t in themes)\n\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.log(' - ', { found, potentials })\n }\n\n if (found) {\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props),\n parentName,\n }\n break\n }\n }\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.warn('ThemeManager.getState():', {\n result,\n })\n console.trace()\n console.groupEnd()\n }\n\n return result\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\n ? themeName.replace(/^light/, 'dark')\n : themeName.replace(/^dark/, 'light')\n}\n\nexport function getNonComponentParentManager(themeManager?: ThemeManager | null) {\n // components never inherit from components\n // example <Switch><Switch.Thumb /></Switch>\n // the Switch theme shouldn't be considered parent of Thumb\n let res = themeManager\n while (res) {\n if (res?.isComponent) {\n res = res.parentManager\n } else {\n break\n }\n }\n return res\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAqC;AACrC,uBAA6D;AAC7D,+BAAkC;AAoBlC,MAAM,aAAgC,EAAE,MAAM,GAAG;AAE1C,SAAS,wBAAwB,OAAmB;AACzD,SAAO,EAAE,MAAM,QAAQ,MAAM,iBAAiB,MAAM,WAAW,MAAM;AACvE;AAEA,IAAI,MAAM;AAEH,MAAM,aAAa;AAAA,EAOxB,YACS,QAAoB,CAAC,GAC5B,iBACA;AAFO;AAPT,cAAK;AACL,uBAAc;AACd,0BAAiB,oBAAI,IAAmB;AACxC,yBAAqC;AACrC,iBAA2B;AA2G3B,oBAA+B;AArG7B,QAAI,oBAAoB,QAAQ;AAC9B,WAAK,YAAY,OAAO,KAAK;AAC7B;AAAA,IACF;AAEA,UAAM,gBAAgB,6BAA6B,eAAe;AAElE,QAAI,CAAC,eAAe;AAClB,UAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAGA,QAAI,wBAAwB,KAAK,GAAG;AAClC,aAAO;AAAA,IACT;AAEA,QAAI,eAAe;AACjB,WAAK,gBAAgB;AAAA,IACvB;AAEA,QAAI,KAAK,YAAY,OAAO,KAAK,GAAG;AAClC;AAAA,IACF;AAEA,WAAO,iBAAiB;AAAA,EAC1B;AAAA,EAEA,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AEA,MAAM,mBAAmB,CAAC,cAAsB;AAC9C,SAAO,UAAU,WAAW,OAAO,IAC/B,UAAU,QAAQ,UAAU,MAAM,IAClC,UAAU,QAAQ,SAAS,OAAO;AACxC;AAEO,SAAS,6BAA6B,cAAoC;AAI/E,MAAI,MAAM;AACV,SAAO,KAAK;AACV,QAAI,2BAAK,aAAa;AACpB,YAAM,IAAI;AAAA,IACZ,OAAO;AACL;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import { getThemes, getTokens } from '../config.js'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants.js'\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { ThemeParsed, ThemeProps } from '../types.js'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n reset?: boolean\n}\n\nexport type ThemeManagerState = {\n name: string\n theme?: ThemeParsed | null\n className?: string\n parentName?: string\n}\n\nconst emptyState: ThemeManagerState = { name: '' }\n\nexport function hasNoThemeUpdatingProps(props: ThemeProps) {\n return !(props.name || props.componentName || props.inverse || props.reset)\n}\n\nlet uid = 0\n\nexport class ThemeManager {\n id = uid++\n isComponent = false\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManagerIn?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManagerIn === 'root') {\n this.updateState(props, false)\n return\n }\n\n const parentManager = getNonComponentParentManager(parentManagerIn)\n\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `No parent manager given, this is likely due to duplicated Tamagui dependencies. Check your lockfile for mis-matched versions.`\n )\n }\n throw `\u274C`\n }\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n\n if (parentManager) {\n this.parentManager = parentManager\n }\n\n if (this.updateState(props, false)) {\n return\n }\n\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n shouldNotify = true\n ) {\n const isChanging = (() => {\n if (props.forceTheme) {\n this.state.theme = props.forceTheme\n this.state.name = props.name || ''\n return true\n }\n const nextState = this.getStateIfChanged(props)\n if (nextState) {\n this.props = props\n this.state = nextState\n return true\n }\n })()\n\n if (isChanging) {\n const names = this.state.name.split('_')\n const lastName = names[names.length - 1][0]\n this.isComponent = lastName[0] === lastName[0].toUpperCase()\n this._allKeys = null\n\n if (process.env.NODE_ENV === 'development') {\n this['_numChangeEventsSent'] ??= 0\n this['_numChangeEventsSent']++\n }\n\n if (shouldNotify) {\n this.notify()\n }\n\n return this.state\n }\n }\n\n getStateIfChanged(\n props = this.props,\n state: ThemeManagerState | null = this.state,\n parentManager = this.parentManager\n ) {\n const _ = this.getState(props, parentManager)\n // is removing\n if (state && state !== emptyState && !_) {\n return parentManager?.state\n }\n if (this.getStateShouldChange(_, state)) {\n return _\n }\n }\n\n getStateShouldChange(\n nextState: ThemeManagerState | null,\n state: ThemeManagerState | null = this.state\n ) {\n if (!nextState?.theme || nextState.theme === state?.theme) {\n return false\n }\n return true\n }\n\n getState(props = this.props, parentManager = this.parentManager) {\n return (\n getState(props, parentManager) ||\n (process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)\n )\n }\n\n _allKeys: Set<string> | null = null\n get allKeys() {\n this._allKeys ||= new Set([\n ...(this.parentManager?.allKeys || []),\n ...Object.keys(this.state.theme || {}),\n ])\n return this._allKeys\n }\n\n // gets value going up to parents\n getValue(key: string, state?: ThemeManagerState) {\n if (!key) return\n let theme = (state || this.state).theme\n let manager = this as ThemeManager | null\n while (theme && manager) {\n if (key in theme) {\n return theme[key]\n }\n manager = manager.parentManager\n theme = manager?.state.theme\n }\n const tokens = getTokens()\n if (key in tokens.color) {\n return tokens.color[key]\n }\n }\n\n notify() {\n this.themeListeners.forEach((cb) => cb(this.state.name, this))\n }\n\n onChangeTheme(cb: ThemeListener, debugId?: number) {\n if (process.env.NODE_ENV === 'development' && debugId) {\n // @ts-ignore\n this._listeningIds ??= new Set()\n // @ts-ignore\n this._listeningIds.add(debugId)\n }\n\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, props: ThemeProps) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (props.inverse || props.forceClassName) {\n return (\n next +\n // ensure you invert to base dark as well as specific dark\n // ... logic should likely be elsewhere\n (next.includes('dark_') ? ` t_dark` : next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n\n if (!props.name && !props.inverse && !props.reset && !props.componentName) {\n return null\n }\n\n if (props.reset && !parentManager?.parentManager) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('Cannot reset no grandparent exists')\n }\n return null\n }\n\n let result: ThemeManagerState | null = null\n\n const nextName = props.reset\n ? parentManager?.parentManager?.state?.name || ''\n : props.name || ''\n const { componentName } = props\n const parentName = parentManager?.state?.name || ''\n\n // components look for most specific, fallback upwards\n const base = parentName.split(THEME_NAME_SEPARATOR)\n const lastSegment = base[base.length - 1]\n const isParentComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentComponentTheme\n ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)\n : parentName\n const max = base.length\n const min =\n componentName && !nextName\n ? max // component name only don't search upwards\n : 0\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.groupCollapsed('ThemeManager.getState()')\n console.log({\n props,\n parentName,\n parentBaseTheme,\n base,\n min,\n max,\n isParentComponentTheme,\n })\n }\n\n for (let i = max; i >= min; i--) {\n let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)\n if (props.inverse) {\n prefix = inverseThemeName(prefix)\n }\n const potentials: string[] = []\n if (prefix && prefix !== parentBaseTheme) {\n potentials.push(prefix)\n }\n if (nextName) {\n potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)\n }\n if (i === 1) {\n const lastSegment = potentials.findIndex((x) => !x.includes('_'))\n if (lastSegment > 0) {\n potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent\n }\n }\n if (componentName) {\n // components only look for component themes\n if (nextName) {\n const beforeSeparator = prefix.slice(0, prefix.indexOf(THEME_NAME_SEPARATOR))\n potentials.push(`${beforeSeparator}_${nextName}_${componentName}`)\n }\n potentials.push(`${prefix}_${componentName}`)\n if (nextName) {\n potentials.unshift(`${prefix}_${nextName}_${componentName}`)\n }\n }\n\n const found = potentials.find((t) => t in themes)\n\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.log(' - ', { found, potentials, parentManager })\n }\n\n if (found) {\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props),\n parentName,\n }\n break\n }\n }\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.warn('ThemeManager.getState():', {\n result,\n })\n console.trace()\n console.groupEnd()\n }\n\n return result\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\n ? themeName.replace(/^light/, 'dark')\n : themeName.replace(/^dark/, 'light')\n}\n\nexport function getNonComponentParentManager(themeManager?: ThemeManager | null) {\n // components never inherit from components\n // example <Switch><Switch.Thumb /></Switch>\n // the Switch theme shouldn't be considered parent of Thumb\n let res = themeManager\n while (res) {\n if (res?.isComponent) {\n res = res.parentManager\n } else {\n break\n }\n }\n return res\n}\n"],
5
+ "mappings": ";;;;;;;;;;;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,IACZ,OAAO;AACL;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
6
6
  "names": ["lastSegment"]
7
7
  }
@@ -147,15 +147,8 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
147
147
  const { state, themeManager, mounted, isNewTheme } = themeState;
148
148
  const isInversingOnMount = Boolean(!themeState.mounted && props.inverse);
149
149
  const shouldReturnParentState = isInversingOnMount;
150
- function getNextThemeManagerState(manager = themeManager) {
151
- const next = manager.getState(
152
- props,
153
- parentManager === themeManager ? parentManager.parentManager : parentManager
154
- );
155
- return next;
156
- }
157
- function getThemeManagerNextStateIfChanged(manager = themeManager, forceShouldChange = false) {
158
- const next = getNextThemeManagerState(manager);
150
+ function getShouldUpdateTheme(manager = themeManager, nextState, forceShouldChange = false) {
151
+ const next = nextState || manager.getState(props, parentManager);
159
152
  if (!next)
160
153
  return;
161
154
  if ((disableUpdate == null ? void 0 : disableUpdate()) === true)
@@ -180,22 +173,30 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
180
173
  };
181
174
  }, [isNewTheme, themeManager, state, debug]);
182
175
  (0, import_react.useLayoutEffect)(() => {
183
- const nextState = getThemeManagerNextStateIfChanged(themeManager);
176
+ var _a;
177
+ const nextState = getShouldUpdateTheme(themeManager);
184
178
  if (nextState) {
185
179
  if (isNewTheme) {
186
180
  themeManager.updateState(nextState, true);
187
181
  }
188
182
  setThemeState(createState);
189
- }
190
- const disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme((name, manager) => {
191
- const shouldUpdate = Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
192
- if (shouldUpdate) {
193
- if (process.env.NODE_ENV === "development" && props["debug"]) {
194
- console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys });
195
- }
183
+ } else {
184
+ if (isNewTheme) {
196
185
  setThemeState(createState);
197
186
  }
198
- }, themeManager.id);
187
+ }
188
+ const disposeChangeListener = (_a = themeManager.parentManager) == null ? void 0 : _a.onChangeTheme(
189
+ (name, manager) => {
190
+ const shouldUpdate = Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
191
+ if (shouldUpdate) {
192
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
193
+ console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys });
194
+ }
195
+ setThemeState(createState);
196
+ }
197
+ },
198
+ themeManager.id
199
+ );
199
200
  return () => {
200
201
  disposeChangeListener == null ? void 0 : disposeChangeListener();
201
202
  };
@@ -207,6 +208,15 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
207
208
  props.name,
208
209
  props.reset
209
210
  ]);
211
+ if (process.env.NODE_ENV === "development") {
212
+ (0, import_react.useEffect)(() => {
213
+ globalThis["TamaguiThemeManagers"] ?? (globalThis["TamaguiThemeManagers"] = /* @__PURE__ */ new Set());
214
+ globalThis["TamaguiThemeManagers"].add(themeManager);
215
+ return () => {
216
+ globalThis["TamaguiThemeManagers"].delete(themeManager);
217
+ };
218
+ }, [themeManager]);
219
+ }
210
220
  }
211
221
  if (shouldReturnParentState) {
212
222
  if (!parentManager)
@@ -235,7 +245,8 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
235
245
  if (prev == null ? void 0 : prev.themeManager) {
236
246
  themeManager2 = prev.themeManager;
237
247
  const forceChange = Boolean(keys == null ? void 0 : keys.length);
238
- const nextState = getThemeManagerNextStateIfChanged(themeManager2, forceChange);
248
+ const next = themeManager2.getState(props, parentManager);
249
+ const nextState = getShouldUpdateTheme(themeManager2, next, forceChange);
239
250
  if (nextState) {
240
251
  state2 = nextState;
241
252
  if (!prev.isNewTheme || !import_constants.isWeb) {
@@ -243,13 +254,17 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
243
254
  } else {
244
255
  themeManager2.updateState(nextState, true);
245
256
  }
257
+ } else {
258
+ if (prev.isNewTheme) {
259
+ if (parentManager && !next) {
260
+ themeManager2 = parentManager;
261
+ }
262
+ }
246
263
  }
247
264
  } else {
248
265
  themeManager2 = getNewThemeManager();
249
266
  }
250
- const isNewTheme2 = Boolean(
251
- themeManager2 !== parentManager || prev && themeManager2.state.name !== prev.state.name
252
- );
267
+ const isNewTheme2 = Boolean(themeManager2 !== parentManager);
253
268
  const mounted2 = !props.inverse ? true : root || (prev == null ? void 0 : prev.mounted);
254
269
  if (!state2) {
255
270
  state2 = isNewTheme2 ? { ...themeManager2.state } : { ...parentManager.state };
@@ -261,8 +276,19 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
261
276
  mounted: mounted2
262
277
  };
263
278
  if (process.env.NODE_ENV === "development" && props["debug"]) {
264
- console.groupCollapsed(` \u{1F537} useChangeThemeEffect createState`);
265
- console.log({ props, parentManager, themeManager: themeManager2, prev, response });
279
+ console.groupCollapsed(` \u{1F537} ${themeManager2.id} useChangeThemeEffect createState`);
280
+ const parentState = { ...parentManager == null ? void 0 : parentManager.state };
281
+ const parentId = parentManager == null ? void 0 : parentManager.id;
282
+ const themeManagerState = { ...themeManager2.state };
283
+ console.log({
284
+ props,
285
+ parentState,
286
+ parentId,
287
+ themeManager: themeManager2,
288
+ prev,
289
+ response,
290
+ themeManagerState
291
+ });
266
292
  console.groupEnd();
267
293
  }
268
294
  return response;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useTheme.tsx"],
4
- "sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config.js'\nimport { isDevTools } from '../constants/isDevTools.js'\nimport { isVariable } from '../createVariable.js'\nimport { createProxy } from '../helpers/createProxy.js'\nimport {\n ThemeManager,\n ThemeManagerState,\n getNonComponentParentManager,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager.js'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext.js'\nimport type { ThemeParsed, ThemeProps } from '../types.js'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped.js'\nimport { useServerRef } from './useServerHooks.js'\n\nexport type ChangedThemeResponse = {\n isNewTheme: boolean\n themeManager: ThemeManager | null\n name: string\n theme?: ThemeParsed | null\n className?: string\n}\n\ntype State = {\n state: ThemeManagerState\n themeManager: ThemeManager\n isNewTheme: boolean\n mounted?: boolean\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const keys = useServerRef<string[]>([])\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n keys.current,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? keys.current.length === 0\n }\n : undefined\n )\n\n const { themeManager, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any, keys.current)\n }, [theme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied(\n {\n theme,\n themeManager,\n }: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n },\n keys?: string[]\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n\n // auto convert variables to plain\n const keyString = key[0] === '$' ? key.slice(1) : key\n const val = themeManager.getValue(keyString)\n\n if (val && keys) {\n return new Proxy(val as any, {\n // when they touch the actual value we only track it\n // if its a variable (web), its ignored!\n get(_, subkey) {\n if (subkey === 'val' && !keys.includes(keyString)) {\n keys.push(keyString)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n keys?: string[],\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n isNewTheme: false,\n ...createState().state,\n themeManager: null,\n }\n }\n\n const parentManager = getNonComponentParentManager(useContext(ThemeManagerContext))\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n isNewTheme: false,\n ...parentManager.state,\n themeManager: parentManager,\n }\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { state, themeManager, mounted, isNewTheme } = themeState\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = isInversingOnMount\n\n function getNextThemeManagerState(manager = themeManager) {\n const next = manager.getState(\n props,\n parentManager === themeManager ? parentManager.parentManager : parentManager\n )\n return next\n }\n\n function getThemeManagerNextStateIfChanged(\n manager = themeManager,\n forceShouldChange = false\n ) {\n const next = getNextThemeManagerState(manager)\n if (!next) return\n if (disableUpdate?.() === true) return\n if (!forceShouldChange && !manager.getStateShouldChange(next, state)) return\n return next\n }\n\n if (!isServer) {\n useEffect(() => {\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n\n if (!isNewTheme) return\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n return () => {\n activeThemeManagers.delete(themeManager)\n }\n }, [isNewTheme, themeManager, state, debug])\n\n // listen for parent change + notify children change\n useLayoutEffect(() => {\n const nextState = getThemeManagerNextStateIfChanged(themeManager)\n\n if (nextState) {\n if (isNewTheme) {\n // if it's a new theme we can just update + publish to children\n themeManager.updateState(nextState, true)\n }\n // if not we will be creating a whole new themeManager\n setThemeState(createState)\n }\n\n const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {\n const shouldUpdate = Boolean(keys?.length || isNewTheme)\n if (shouldUpdate) {\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys })\n }\n setThemeState(createState)\n }\n }, themeManager.id)\n\n return () => {\n disposeChangeListener?.()\n }\n }, [\n parentManager,\n isNewTheme,\n props.componentName,\n props.inverse,\n props.name,\n props.reset,\n ])\n }\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n return {\n isNewTheme: false,\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n }\n }\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State): State {\n if (prev && disableUpdate?.()) {\n return prev\n }\n\n // returns previous theme manager if no change\n let themeManager: ThemeManager\n let state: ThemeManagerState | undefined\n\n const getNewThemeManager = () => {\n return new ThemeManager(props, root ? 'root' : parentManager)\n }\n\n if (prev?.themeManager) {\n themeManager = prev.themeManager\n\n // this could be a bit better, problem is on toggling light/dark the state is actually\n // showing light even when the last was dark. but technically allso onChangeTheme should\n // basically always call on a change, so i'm wondering if we even need the shouldUpdate\n // at all anymore. this forces updates onChangeTheme for all dynamic style accessed components\n // which is correct, potentially in the future we can avoid forceChange and just know to\n // update if keys.length is set + onChangeTheme called\n const forceChange = Boolean(keys?.length)\n\n const nextState = getThemeManagerNextStateIfChanged(themeManager, forceChange)\n\n if (nextState) {\n state = nextState\n\n if (!prev.isNewTheme || !isWeb) {\n themeManager = getNewThemeManager()\n } else {\n themeManager.updateState(nextState, true)\n }\n }\n } else {\n themeManager = getNewThemeManager()\n }\n\n const isNewTheme = Boolean(\n themeManager !== parentManager ||\n (prev && themeManager.state.name !== prev.state.name)\n )\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n\n if (!state) {\n state = isNewTheme ? { ...themeManager.state } : { ...parentManager!.state }\n }\n\n const response = {\n state,\n themeManager,\n isNewTheme,\n mounted,\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.groupCollapsed(` \uD83D\uDD37 useChangeThemeEffect createState`)\n console.log({ props, parentManager, themeManager, prev, response })\n console.groupEnd()\n }\n\n return response\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiD;AACjD,mBAA0E;AAE1E,oBAA0B;AAC1B,wBAA2B;AAE3B,yBAA4B;AAC5B,0BAKO;AACP,iCAAoC;AAEpC,+BAAkC;AAClC,4BAA6B;AAiB7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,aAAS,yBAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE,CAAC;AACzC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO,IAAI;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AAEO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AA7CzE;AA8CE,UAAQ,yBAAQ,QAAO,uBAAkB,KAAK,MAAvB,mBAA0B,UAAU,uBAAuB;AACpF;AAEO,MAAM,oBAAoB,CAAC,UAAsB;AACtD,QAAM,WAAO,oCAAuB,CAAC,CAAC;AAEtC,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,4BACI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,6CAAsC;AAC7D,cAAQ,IAAI,EAAE,OAAO,eAAe,cAAAH,eAAc,MAAM,SAAS,CAAC;AAClE,cAAQ,SAAS;AAAA,IACnB;AAEA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config.js'\nimport { isDevTools } from '../constants/isDevTools.js'\nimport { isVariable } from '../createVariable.js'\nimport { createProxy } from '../helpers/createProxy.js'\nimport {\n ThemeManager,\n ThemeManagerState,\n getNonComponentParentManager,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager.js'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext.js'\nimport type { ThemeParsed, ThemeProps } from '../types.js'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped.js'\nimport { useServerRef } from './useServerHooks.js'\n\nexport type ChangedThemeResponse = {\n isNewTheme: boolean\n themeManager: ThemeManager | null\n name: string\n theme?: ThemeParsed | null\n className?: string\n}\n\ntype State = {\n state: ThemeManagerState\n themeManager: ThemeManager\n isNewTheme: boolean\n mounted?: boolean\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const keys = useServerRef<string[]>([])\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n keys.current,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? keys.current.length === 0\n }\n : undefined\n )\n\n const { themeManager, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any, keys.current)\n }, [theme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied(\n {\n theme,\n themeManager,\n }: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n },\n keys?: string[]\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n\n // auto convert variables to plain\n const keyString = key[0] === '$' ? key.slice(1) : key\n const val = themeManager.getValue(keyString)\n\n if (val && keys) {\n return new Proxy(val as any, {\n // when they touch the actual value we only track it\n // if its a variable (web), its ignored!\n get(_, subkey) {\n if (subkey === 'val' && !keys.includes(keyString)) {\n keys.push(keyString)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n keys?: string[],\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n isNewTheme: false,\n ...createState().state,\n themeManager: null,\n }\n }\n\n const parentManager = getNonComponentParentManager(useContext(ThemeManagerContext))\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n isNewTheme: false,\n ...parentManager.state,\n themeManager: parentManager,\n }\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { state, themeManager, mounted, isNewTheme } = themeState\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = isInversingOnMount\n\n function getShouldUpdateTheme(\n manager = themeManager,\n nextState?: ThemeManagerState | null,\n forceShouldChange = false\n ) {\n const next = nextState || manager.getState(props, parentManager)\n if (!next) return\n if (disableUpdate?.() === true) return\n if (!forceShouldChange && !manager.getStateShouldChange(next, state)) return\n return next\n }\n\n if (!isServer) {\n useEffect(() => {\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n\n if (!isNewTheme) return\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n return () => {\n activeThemeManagers.delete(themeManager)\n }\n }, [isNewTheme, themeManager, state, debug])\n\n // listen for parent change + notify children change\n useLayoutEffect(() => {\n const nextState = getShouldUpdateTheme(themeManager)\n\n if (nextState) {\n if (isNewTheme) {\n // if it's a new theme we can just update + publish to children\n themeManager.updateState(nextState, true)\n }\n\n // if not we will be creating a whole new themeManager\n setThemeState(createState)\n } else {\n if (isNewTheme) {\n // need to revert to parent\n setThemeState(createState)\n }\n }\n\n const disposeChangeListener = themeManager.parentManager?.onChangeTheme(\n (name, manager) => {\n const shouldUpdate = Boolean(keys?.length || isNewTheme)\n if (shouldUpdate) {\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys })\n }\n setThemeState(createState)\n }\n },\n themeManager.id\n )\n\n return () => {\n disposeChangeListener?.()\n }\n }, [\n parentManager,\n isNewTheme,\n props.componentName,\n props.inverse,\n props.name,\n props.reset,\n ])\n\n if (process.env.NODE_ENV === 'development') {\n useEffect(() => {\n globalThis['TamaguiThemeManagers'] ??= new Set()\n globalThis['TamaguiThemeManagers'].add(themeManager)\n return () => {\n globalThis['TamaguiThemeManagers'].delete(themeManager)\n }\n }, [themeManager])\n }\n }\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n return {\n isNewTheme: false,\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n }\n }\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State): State {\n if (prev && disableUpdate?.()) {\n return prev\n }\n\n // returns previous theme manager if no change\n let themeManager: ThemeManager\n let state: ThemeManagerState | undefined\n\n const getNewThemeManager = () => {\n return new ThemeManager(props, root ? 'root' : parentManager)\n }\n\n if (prev?.themeManager) {\n themeManager = prev.themeManager\n\n // this could be a bit better, problem is on toggling light/dark the state is actually\n // showing light even when the last was dark. but technically allso onChangeTheme should\n // basically always call on a change, so i'm wondering if we even need the shouldUpdate\n // at all anymore. this forces updates onChangeTheme for all dynamic style accessed components\n // which is correct, potentially in the future we can avoid forceChange and just know to\n // update if keys.length is set + onChangeTheme called\n const forceChange = Boolean(keys?.length)\n\n const next = themeManager.getState(props, parentManager)\n const nextState = getShouldUpdateTheme(themeManager, next, forceChange)\n\n if (nextState) {\n state = nextState\n\n if (!prev.isNewTheme || !isWeb) {\n themeManager = getNewThemeManager()\n } else {\n themeManager.updateState(nextState, true)\n }\n } else {\n if (prev.isNewTheme) {\n // reset to parent\n if (parentManager && !next) {\n themeManager = parentManager\n }\n }\n }\n } else {\n themeManager = getNewThemeManager()\n }\n\n const isNewTheme = Boolean(themeManager !== parentManager)\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n\n if (!state) {\n state = isNewTheme ? { ...themeManager.state } : { ...parentManager!.state }\n }\n\n const response = {\n state,\n themeManager,\n isNewTheme,\n mounted,\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.groupCollapsed(` \uD83D\uDD37 ${themeManager.id} useChangeThemeEffect createState`)\n const parentState = { ...parentManager?.state }\n const parentId = parentManager?.id\n const themeManagerState = { ...themeManager.state }\n console.log({\n props,\n parentState,\n parentId,\n themeManager,\n prev,\n response,\n themeManagerState,\n })\n console.groupEnd()\n }\n\n return response\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAiD;AACjD,mBAA0E;AAE1E,oBAA0B;AAC1B,wBAA2B;AAE3B,yBAA4B;AAC5B,0BAKO;AACP,iCAAoC;AAEpC,+BAAkC;AAClC,4BAA6B;AAiB7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,aAAS,yBAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE,CAAC;AACzC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO,IAAI;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AAEO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AA7CzE;AA8CE,UAAQ,yBAAQ,QAAO,uBAAkB,KAAK,MAAvB,mBAA0B,UAAU,uBAAuB;AACpF;AAEO,MAAM,oBAAoB,CAAC,UAAsB;AACtD,QAAM,WAAO,oCAAuB,CAAC,CAAC;AAEtC,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,4BACI,MAAM;AAzDd;AA0DU,eAAO,WAAM,iBAAN,mCAA0B,KAAK,QAAQ,WAAW;AAAA,IAC3D,IACA;AAAA,EACN;AAEA,QAAM,EAAE,cAAc,OAAO,MAAM,UAAU,IAAI;AAEjD,MAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU,WAAW;AACvE,YAAQ,eAAe,2BAAoB,IAAI;AAC/C,UAAM,OAAO,EAAE,GAAG,OAAO,MAAM,WAAW,GAAI,gCAAc,EAAE,MAAM,EAAG;AACvE,eAAW,OAAO,MAAM;AACtB,cAAQ,IAAI,MAAM,KAAK,KAAK,GAA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E,GAAG,+CAAe,MAAM;AAC9C,YAAM,WAAW,+CAAe;AAChC,YAAM,oBAAoB,EAAE,GAAGA,cAAa,MAAM;AAClD,cAAQ,IAAI;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,cAAQ,SAAS;AAAA,IACnB;AAEA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["_", "themeManager", "state", "isNewTheme", "mounted"]
7
7
  }
@@ -24,6 +24,8 @@ module.exports = __toCommonJS(ThemeDebug_exports);
24
24
  var import_jsx_runtime = require("react/jsx-runtime");
25
25
  var import_use_force_update = require("@tamagui/use-force-update");
26
26
  var import_react = require("react");
27
+ var import_react_dom = require("react-dom");
28
+ let node;
27
29
  function ThemeDebug({
28
30
  themeState,
29
31
  themeProps,
@@ -33,6 +35,22 @@ function ThemeDebug({
33
35
  if (process.env.NODE_ENV === "development") {
34
36
  const [onChangeCount, setOnChangeCount] = (0, import_react.useState)(0);
35
37
  const rerender = (0, import_use_force_update.useForceUpdate)();
38
+ const id = (0, import_react.useId)();
39
+ if (process.env.NODE_ENV === "development" && typeof document !== "undefined") {
40
+ if (!node) {
41
+ node = document.createElement("div");
42
+ node.style.width = "100%";
43
+ node.style.height = "200px";
44
+ node.style.overflowY = "scroll";
45
+ node.style.position = "fixed";
46
+ node.style.top = "0px";
47
+ node.style.left = "0px";
48
+ node.style.display = "flex";
49
+ node.style.flexDirection = "row";
50
+ node.style.background = "var(--background)";
51
+ document.body.appendChild(node);
52
+ }
53
+ }
36
54
  (0, import_react.useEffect)(() => {
37
55
  var _a2, _b2;
38
56
  (_b2 = (_a2 = themeState.themeManager) == null ? void 0 : _a2.parentManager) == null ? void 0 : _b2.onChangeTheme((name, manager) => {
@@ -44,44 +62,45 @@ function ThemeDebug({
44
62
  const tm = setInterval(rerender, 100);
45
63
  return () => clearTimeout(tm);
46
64
  }, []);
47
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
48
- "div",
49
- {
50
- style: {
51
- whiteSpace: "pre",
52
- background: "var(--background)",
53
- display: "inline-block",
54
- border: "1px solid #ccc",
55
- margin: 20,
56
- color: "red"
57
- },
58
- children: [
59
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("code", { children: [
60
- "<Theme />\xA0",
61
- JSON.stringify(
62
- {
63
- name: themeState.name,
64
- className: themeState.className,
65
- inverse: themeProps.inverse,
66
- forceClassName: themeProps.forceClassName,
67
- parent: (_a = themeState.themeManager) == null ? void 0 : _a.state.parentName,
68
- id: (_b = themeState.themeManager) == null ? void 0 : _b.id,
69
- parentId: (_d = (_c = themeState.themeManager) == null ? void 0 : _c.parentManager) == null ? void 0 : _d.id,
70
- isNew: themeState.isNewTheme,
71
- onChangeCount,
72
- listening: [...((_e = themeState.themeManager) == null ? void 0 : _e["_listeningIds"]) || []].join(
73
- ","
74
- ),
75
- _numChangeEventsSent: (_f = themeState.themeManager) == null ? void 0 : _f["_numChangeEventsSent"]
76
- },
77
- null,
78
- 2
79
- )
80
- ] }),
81
- children
82
- ]
83
- }
84
- );
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
66
+ (0, import_react_dom.createPortal)(
67
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
68
+ "code",
69
+ {
70
+ style: {
71
+ whiteSpace: "pre"
72
+ },
73
+ children: [
74
+ "<Theme ",
75
+ id,
76
+ " />\xA0",
77
+ JSON.stringify(
78
+ {
79
+ name: themeState.name,
80
+ className: themeState.className,
81
+ inverse: themeProps.inverse,
82
+ forceClassName: themeProps.forceClassName,
83
+ parent: (_a = themeState.themeManager) == null ? void 0 : _a.state.parentName,
84
+ id: (_b = themeState.themeManager) == null ? void 0 : _b.id,
85
+ parentId: (_d = (_c = themeState.themeManager) == null ? void 0 : _c.parentManager) == null ? void 0 : _d.id,
86
+ isNew: themeState.isNewTheme,
87
+ onChangeCount,
88
+ listening: [...((_e = themeState.themeManager) == null ? void 0 : _e["_listeningIds"]) || []].join(
89
+ ","
90
+ ),
91
+ _numChangeEventsSent: (_f = themeState.themeManager) == null ? void 0 : _f["_numChangeEventsSent"]
92
+ },
93
+ null,
94
+ 2
95
+ )
96
+ ]
97
+ }
98
+ ),
99
+ node
100
+ ),
101
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: id }),
102
+ children
103
+ ] });
85
104
  }
86
105
  return children;
87
106
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeDebug.tsx"],
4
- "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useEffect, useState } from 'react'\n\nimport { ChangedThemeResponse } from '../hooks/useTheme.js'\nimport { ThemeProps } from '../types.js'\n\nexport function ThemeDebug({\n themeState,\n themeProps,\n children,\n}: {\n themeState: ChangedThemeResponse\n themeProps: ThemeProps\n children: any\n}) {\n if (process.env.NODE_ENV === 'development') {\n const [onChangeCount, setOnChangeCount] = useState(0)\n const rerender = useForceUpdate()\n\n useEffect(() => {\n themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {\n setOnChangeCount((p) => ++p)\n console.warn(`theme changed`, name)\n })\n }, [themeState.themeManager])\n\n useEffect(() => {\n // to refresh _listeningIds every so often\n const tm = setInterval(rerender, 100)\n return () => clearTimeout(tm)\n }, [])\n\n return (\n <div\n style={{\n whiteSpace: 'pre',\n background: 'var(--background)',\n display: 'inline-block',\n border: '1px solid #ccc',\n margin: 20,\n color: 'red',\n }}\n >\n <code>\n &lt;Theme /&gt;&nbsp;\n {JSON.stringify(\n {\n name: themeState.name,\n className: themeState.className,\n inverse: themeProps.inverse,\n forceClassName: themeProps.forceClassName,\n parent: themeState.themeManager?.state.parentName,\n id: themeState.themeManager?.id,\n parentId: themeState.themeManager?.parentManager?.id,\n isNew: themeState.isNewTheme,\n onChangeCount,\n listening: [...(themeState.themeManager?.['_listeningIds'] || [])].join(\n ','\n ),\n _numChangeEventsSent: themeState.themeManager?.['_numChangeEventsSent'],\n },\n null,\n 2\n )}\n </code>\n {children}\n </div>\n )\n }\n return children\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CQ;AA3CR,8BAA+B;AAC/B,mBAAoC;AAK7B,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAdH;AAeE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UAAM,CAAC,eAAe,gBAAgB,QAAI,uBAAS,CAAC;AACpD,UAAM,eAAW,wCAAe;AAEhC,gCAAU,MAAM;AAnBpB,UAAAA,KAAAC;AAoBM,OAAAA,OAAAD,MAAA,WAAW,iBAAX,gBAAAA,IAAyB,kBAAzB,gBAAAC,IAAwC,cAAc,CAAC,MAAM,YAAY;AACvE,yBAAiB,CAAC,MAAM,EAAE,CAAC;AAC3B,gBAAQ,KAAK,iBAAiB,IAAI;AAAA,MACpC;AAAA,IACF,GAAG,CAAC,WAAW,YAAY,CAAC;AAE5B,gCAAU,MAAM;AAEd,YAAM,KAAK,YAAY,UAAU,GAAG;AACpC,aAAO,MAAM,aAAa,EAAE;AAAA,IAC9B,GAAG,CAAC,CAAC;AAEL,WACE;AAAA,MAAC;AAAA;AAAA,QACC,OAAO;AAAA,UACL,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ,SAAS;AAAA,UACT,QAAQ;AAAA,UACR,QAAQ;AAAA,UACR,OAAO;AAAA,QACT;AAAA,QAEA;AAAA,uDAAC,UAAK;AAAA;AAAA,YAEH,KAAK;AAAA,cACJ;AAAA,gBACE,MAAM,WAAW;AAAA,gBACjB,WAAW,WAAW;AAAA,gBACtB,SAAS,WAAW;AAAA,gBACpB,gBAAgB,WAAW;AAAA,gBAC3B,SAAQ,gBAAW,iBAAX,mBAAyB,MAAM;AAAA,gBACvC,KAAI,gBAAW,iBAAX,mBAAyB;AAAA,gBAC7B,WAAU,sBAAW,iBAAX,mBAAyB,kBAAzB,mBAAwC;AAAA,gBAClD,OAAO,WAAW;AAAA,gBAClB;AAAA,gBACA,WAAW,CAAC,KAAI,gBAAW,iBAAX,mBAA0B,qBAAoB,CAAC,CAAE,EAAE;AAAA,kBACjE;AAAA,gBACF;AAAA,gBACA,uBAAsB,gBAAW,iBAAX,mBAA0B;AAAA,cAClD;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,aACF;AAAA,UACC;AAAA;AAAA;AAAA,IACH;AAAA,EAEJ;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useEffect, useId, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { ChangedThemeResponse } from '../hooks/useTheme.js'\nimport { ThemeProps } from '../types.js'\n\nlet node\n\nexport function ThemeDebug({\n themeState,\n themeProps,\n children,\n}: {\n themeState: ChangedThemeResponse\n themeProps: ThemeProps\n children: any\n}) {\n if (process.env.NODE_ENV === 'development') {\n const [onChangeCount, setOnChangeCount] = useState(0)\n const rerender = useForceUpdate()\n const id = useId()\n\n if (process.env.NODE_ENV === 'development' && typeof document !== 'undefined') {\n if (!node) {\n node = document.createElement('div')\n node.style.width = '100%'\n node.style.height = '200px'\n node.style.overflowY = 'scroll'\n node.style.position = 'fixed'\n node.style.top = '0px'\n node.style.left = '0px'\n node.style.display = 'flex'\n node.style.flexDirection = 'row'\n node.style.background = 'var(--background)'\n document.body.appendChild(node)\n }\n }\n\n useEffect(() => {\n themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {\n setOnChangeCount((p) => ++p)\n console.warn(`theme changed`, name)\n })\n }, [themeState.themeManager])\n\n useEffect(() => {\n // to refresh _listeningIds every so often\n const tm = setInterval(rerender, 100)\n return () => clearTimeout(tm)\n }, [])\n\n return (\n <>\n {createPortal(\n <code\n style={{\n whiteSpace: 'pre',\n }}\n >\n &lt;Theme {id} /&gt;&nbsp;\n {JSON.stringify(\n {\n name: themeState.name,\n className: themeState.className,\n inverse: themeProps.inverse,\n forceClassName: themeProps.forceClassName,\n parent: themeState.themeManager?.state.parentName,\n id: themeState.themeManager?.id,\n parentId: themeState.themeManager?.parentManager?.id,\n isNew: themeState.isNewTheme,\n onChangeCount,\n listening: [...(themeState.themeManager?.['_listeningIds'] || [])].join(\n ','\n ),\n _numChangeEventsSent: themeState.themeManager?.['_numChangeEventsSent'],\n },\n null,\n 2\n )}\n </code>,\n node\n )}\n\n <div>{id}</div>\n\n {children}\n </>\n )\n }\n return children\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqDM;AArDN,8BAA+B;AAC/B,mBAAmD;AACnD,uBAA6B;AAK7B,IAAI;AAEG,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAjBH;AAkBE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UAAM,CAAC,eAAe,gBAAgB,QAAI,uBAAS,CAAC;AACpD,UAAM,eAAW,wCAAe;AAChC,UAAM,SAAK,oBAAM;AAEjB,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,aAAa,aAAa;AAC7E,UAAI,CAAC,MAAM;AACT,eAAO,SAAS,cAAc,KAAK;AACnC,aAAK,MAAM,QAAQ;AACnB,aAAK,MAAM,SAAS;AACpB,aAAK,MAAM,YAAY;AACvB,aAAK,MAAM,WAAW;AACtB,aAAK,MAAM,MAAM;AACjB,aAAK,MAAM,OAAO;AAClB,aAAK,MAAM,UAAU;AACrB,aAAK,MAAM,gBAAgB;AAC3B,aAAK,MAAM,aAAa;AACxB,iBAAS,KAAK,YAAY,IAAI;AAAA,MAChC;AAAA,IACF;AAEA,gCAAU,MAAM;AAvCpB,UAAAA,KAAAC;AAwCM,OAAAA,OAAAD,MAAA,WAAW,iBAAX,gBAAAA,IAAyB,kBAAzB,gBAAAC,IAAwC,cAAc,CAAC,MAAM,YAAY;AACvE,yBAAiB,CAAC,MAAM,EAAE,CAAC;AAC3B,gBAAQ,KAAK,iBAAiB,IAAI;AAAA,MACpC;AAAA,IACF,GAAG,CAAC,WAAW,YAAY,CAAC;AAE5B,gCAAU,MAAM;AAEd,YAAM,KAAK,YAAY,UAAU,GAAG;AACpC,aAAO,MAAM,aAAa,EAAE;AAAA,IAC9B,GAAG,CAAC,CAAC;AAEL,WACE,4EACG;AAAA;AAAA,QACC;AAAA,UAAC;AAAA;AAAA,YACC,OAAO;AAAA,cACL,YAAY;AAAA,YACd;AAAA,YACD;AAAA;AAAA,cACY;AAAA,cAAG;AAAA,cACb,KAAK;AAAA,gBACJ;AAAA,kBACE,MAAM,WAAW;AAAA,kBACjB,WAAW,WAAW;AAAA,kBACtB,SAAS,WAAW;AAAA,kBACpB,gBAAgB,WAAW;AAAA,kBAC3B,SAAQ,gBAAW,iBAAX,mBAAyB,MAAM;AAAA,kBACvC,KAAI,gBAAW,iBAAX,mBAAyB;AAAA,kBAC7B,WAAU,sBAAW,iBAAX,mBAAyB,kBAAzB,mBAAwC;AAAA,kBAClD,OAAO,WAAW;AAAA,kBAClB;AAAA,kBACA,WAAW,CAAC,KAAI,gBAAW,iBAAX,mBAA0B,qBAAoB,CAAC,CAAE,EAAE;AAAA,oBACjE;AAAA,kBACF;AAAA,kBACA,uBAAsB,gBAAW,iBAAX,mBAA0B;AAAA,gBAClD;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA;AAAA;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,MAEA,4CAAC,SAAK,cAAG;AAAA,MAER;AAAA,OACH;AAAA,EAEJ;AACA,SAAO;AACT;",
6
6
  "names": ["_a", "_b"]
7
7
  }
@@ -141,6 +141,9 @@ function getState(props, parentManager) {
141
141
  if (props.name && props.reset) {
142
142
  throw new Error("Cannot reset + set new name");
143
143
  }
144
+ if (!props.name && !props.inverse && !props.reset && !props.componentName) {
145
+ return null;
146
+ }
144
147
  if (props.reset && !(parentManager == null ? void 0 : parentManager.parentManager)) {
145
148
  if (process.env.NODE_ENV === "development") {
146
149
  console.warn("Cannot reset no grandparent exists");
@@ -202,7 +205,7 @@ function getState(props, parentManager) {
202
205
  }
203
206
  const found = potentials.find((t) => t in themes);
204
207
  if (process.env.NODE_ENV === "development" && typeof props.debug === "string") {
205
- console.log(" - ", { found, potentials });
208
+ console.log(" - ", { found, potentials, parentManager });
206
209
  }
207
210
  if (found) {
208
211
  result = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/ThemeManager.tsx"],
4
- "sourcesContent": ["import { getThemes, getTokens } from '../config.js'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants.js'\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { ThemeParsed, ThemeProps } from '../types.js'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n reset?: boolean\n}\n\nexport type ThemeManagerState = {\n name: string\n theme?: ThemeParsed | null\n className?: string\n parentName?: string\n}\n\nconst emptyState: ThemeManagerState = { name: '' }\n\nexport function hasNoThemeUpdatingProps(props: ThemeProps) {\n return !(props.name || props.componentName || props.inverse || props.reset)\n}\n\nlet uid = 0\n\nexport class ThemeManager {\n id = uid++\n isComponent = false\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManagerIn?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManagerIn === 'root') {\n this.updateState(props, false)\n return\n }\n\n const parentManager = getNonComponentParentManager(parentManagerIn)\n\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `No parent manager given, this is likely due to duplicated Tamagui dependencies. Check your lockfile for mis-matched versions.`\n )\n }\n throw `\u274C`\n }\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n\n if (parentManager) {\n this.parentManager = parentManager\n }\n\n if (this.updateState(props, false)) {\n return\n }\n\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n shouldNotify = true\n ) {\n const isChanging = (() => {\n if (props.forceTheme) {\n this.state.theme = props.forceTheme\n this.state.name = props.name || ''\n return true\n }\n const nextState = this.getStateIfChanged(props)\n if (nextState) {\n this.props = props\n this.state = nextState\n return true\n }\n })()\n\n if (isChanging) {\n const names = this.state.name.split('_')\n const lastName = names[names.length - 1][0]\n this.isComponent = lastName[0] === lastName[0].toUpperCase()\n this._allKeys = null\n\n if (process.env.NODE_ENV === 'development') {\n this['_numChangeEventsSent'] ??= 0\n this['_numChangeEventsSent']++\n }\n\n if (shouldNotify) {\n this.notify()\n }\n\n return this.state\n }\n }\n\n getStateIfChanged(\n props = this.props,\n state: ThemeManagerState | null = this.state,\n parentManager = this.parentManager\n ) {\n const _ = this.getState(props, parentManager)\n // is removing\n if (state && state !== emptyState && !_) {\n return parentManager?.state\n }\n if (this.getStateShouldChange(_, state)) {\n return _\n }\n }\n\n getStateShouldChange(\n nextState: ThemeManagerState | null,\n state: ThemeManagerState | null = this.state\n ) {\n if (!nextState?.theme || nextState.theme === state?.theme) {\n return false\n }\n return true\n }\n\n getState(props = this.props, parentManager = this.parentManager) {\n return (\n getState(props, parentManager) ||\n (process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)\n )\n }\n\n _allKeys: Set<string> | null = null\n get allKeys() {\n this._allKeys ||= new Set([\n ...(this.parentManager?.allKeys || []),\n ...Object.keys(this.state.theme || {}),\n ])\n return this._allKeys\n }\n\n // gets value going up to parents\n getValue(key: string, state?: ThemeManagerState) {\n if (!key) return\n let theme = (state || this.state).theme\n let manager = this as ThemeManager | null\n while (theme && manager) {\n if (key in theme) {\n return theme[key]\n }\n manager = manager.parentManager\n theme = manager?.state.theme\n }\n const tokens = getTokens()\n if (key in tokens.color) {\n return tokens.color[key]\n }\n }\n\n notify() {\n this.themeListeners.forEach((cb) => cb(this.state.name, this))\n }\n\n onChangeTheme(cb: ThemeListener, debugId?: number) {\n if (process.env.NODE_ENV === 'development' && debugId) {\n // @ts-ignore\n this._listeningIds ??= new Set()\n // @ts-ignore\n this._listeningIds.add(debugId)\n }\n\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, props: ThemeProps) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (props.inverse || props.forceClassName) {\n return (\n next +\n // ensure you invert to base dark as well as specific dark\n // ... logic should likely be elsewhere\n (next.includes('dark_') ? ` t_dark` : next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n\n if (props.reset && !parentManager?.parentManager) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('Cannot reset no grandparent exists')\n }\n return null\n }\n\n let result: ThemeManagerState | null = null\n\n const nextName = props.reset\n ? parentManager?.parentManager?.state?.name || ''\n : props.name || ''\n const { componentName } = props\n const parentName = parentManager?.state?.name || ''\n\n // components look for most specific, fallback upwards\n const base = parentName.split(THEME_NAME_SEPARATOR)\n const lastSegment = base[base.length - 1]\n const isParentComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentComponentTheme\n ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)\n : parentName\n const max = base.length\n const min =\n componentName && !nextName\n ? max // component name only don't search upwards\n : 0\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.groupCollapsed('ThemeManager.getState()')\n console.log({\n props,\n parentName,\n parentBaseTheme,\n base,\n min,\n max,\n isParentComponentTheme,\n })\n }\n\n for (let i = max; i >= min; i--) {\n let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)\n if (props.inverse) {\n prefix = inverseThemeName(prefix)\n }\n const potentials: string[] = []\n if (prefix && prefix !== parentBaseTheme) {\n potentials.push(prefix)\n }\n if (nextName) {\n potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)\n }\n if (i === 1) {\n const lastSegment = potentials.findIndex((x) => !x.includes('_'))\n if (lastSegment > 0) {\n potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent\n }\n }\n if (componentName) {\n // components only look for component themes\n if (nextName) {\n const beforeSeparator = prefix.slice(0, prefix.indexOf(THEME_NAME_SEPARATOR))\n potentials.push(`${beforeSeparator}_${nextName}_${componentName}`)\n }\n potentials.push(`${prefix}_${componentName}`)\n if (nextName) {\n potentials.unshift(`${prefix}_${nextName}_${componentName}`)\n }\n }\n\n const found = potentials.find((t) => t in themes)\n\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.log(' - ', { found, potentials })\n }\n\n if (found) {\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props),\n parentName,\n }\n break\n }\n }\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.warn('ThemeManager.getState():', {\n result,\n })\n console.trace()\n console.groupEnd()\n }\n\n return result\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\n ? themeName.replace(/^light/, 'dark')\n : themeName.replace(/^dark/, 'light')\n}\n\nexport function getNonComponentParentManager(themeManager?: ThemeManager | null) {\n // components never inherit from components\n // example <Switch><Switch.Thumb /></Switch>\n // the Switch theme shouldn't be considered parent of Thumb\n let res = themeManager\n while (res) {\n if (res?.isComponent) {\n res = res.parentManager\n } else {\n break\n }\n }\n return res\n}\n"],
5
- "mappings": "AAAA,SAAS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\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { ThemeParsed, ThemeProps } from '../types.js'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n reset?: boolean\n}\n\nexport type ThemeManagerState = {\n name: string\n theme?: ThemeParsed | null\n className?: string\n parentName?: string\n}\n\nconst emptyState: ThemeManagerState = { name: '' }\n\nexport function hasNoThemeUpdatingProps(props: ThemeProps) {\n return !(props.name || props.componentName || props.inverse || props.reset)\n}\n\nlet uid = 0\n\nexport class ThemeManager {\n id = uid++\n isComponent = false\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManagerIn?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManagerIn === 'root') {\n this.updateState(props, false)\n return\n }\n\n const parentManager = getNonComponentParentManager(parentManagerIn)\n\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `No parent manager given, this is likely due to duplicated Tamagui dependencies. Check your lockfile for mis-matched versions.`\n )\n }\n throw `\u274C`\n }\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n\n if (parentManager) {\n this.parentManager = parentManager\n }\n\n if (this.updateState(props, false)) {\n return\n }\n\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n shouldNotify = true\n ) {\n const isChanging = (() => {\n if (props.forceTheme) {\n this.state.theme = props.forceTheme\n this.state.name = props.name || ''\n return true\n }\n const nextState = this.getStateIfChanged(props)\n if (nextState) {\n this.props = props\n this.state = nextState\n return true\n }\n })()\n\n if (isChanging) {\n const names = this.state.name.split('_')\n const lastName = names[names.length - 1][0]\n this.isComponent = lastName[0] === lastName[0].toUpperCase()\n this._allKeys = null\n\n if (process.env.NODE_ENV === 'development') {\n this['_numChangeEventsSent'] ??= 0\n this['_numChangeEventsSent']++\n }\n\n if (shouldNotify) {\n this.notify()\n }\n\n return this.state\n }\n }\n\n getStateIfChanged(\n props = this.props,\n state: ThemeManagerState | null = this.state,\n parentManager = this.parentManager\n ) {\n const _ = this.getState(props, parentManager)\n // is removing\n if (state && state !== emptyState && !_) {\n return parentManager?.state\n }\n if (this.getStateShouldChange(_, state)) {\n return _\n }\n }\n\n getStateShouldChange(\n nextState: ThemeManagerState | null,\n state: ThemeManagerState | null = this.state\n ) {\n if (!nextState?.theme || nextState.theme === state?.theme) {\n return false\n }\n return true\n }\n\n getState(props = this.props, parentManager = this.parentManager) {\n return (\n getState(props, parentManager) ||\n (process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)\n )\n }\n\n _allKeys: Set<string> | null = null\n get allKeys() {\n this._allKeys ||= new Set([\n ...(this.parentManager?.allKeys || []),\n ...Object.keys(this.state.theme || {}),\n ])\n return this._allKeys\n }\n\n // gets value going up to parents\n getValue(key: string, state?: ThemeManagerState) {\n if (!key) return\n let theme = (state || this.state).theme\n let manager = this as ThemeManager | null\n while (theme && manager) {\n if (key in theme) {\n return theme[key]\n }\n manager = manager.parentManager\n theme = manager?.state.theme\n }\n const tokens = getTokens()\n if (key in tokens.color) {\n return tokens.color[key]\n }\n }\n\n notify() {\n this.themeListeners.forEach((cb) => cb(this.state.name, this))\n }\n\n onChangeTheme(cb: ThemeListener, debugId?: number) {\n if (process.env.NODE_ENV === 'development' && debugId) {\n // @ts-ignore\n this._listeningIds ??= new Set()\n // @ts-ignore\n this._listeningIds.add(debugId)\n }\n\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, props: ThemeProps) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (props.inverse || props.forceClassName) {\n return (\n next +\n // ensure you invert to base dark as well as specific dark\n // ... logic should likely be elsewhere\n (next.includes('dark_') ? ` t_dark` : next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n\n if (!props.name && !props.inverse && !props.reset && !props.componentName) {\n return null\n }\n\n if (props.reset && !parentManager?.parentManager) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('Cannot reset no grandparent exists')\n }\n return null\n }\n\n let result: ThemeManagerState | null = null\n\n const nextName = props.reset\n ? parentManager?.parentManager?.state?.name || ''\n : props.name || ''\n const { componentName } = props\n const parentName = parentManager?.state?.name || ''\n\n // components look for most specific, fallback upwards\n const base = parentName.split(THEME_NAME_SEPARATOR)\n const lastSegment = base[base.length - 1]\n const isParentComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentComponentTheme\n ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)\n : parentName\n const max = base.length\n const min =\n componentName && !nextName\n ? max // component name only don't search upwards\n : 0\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.groupCollapsed('ThemeManager.getState()')\n console.log({\n props,\n parentName,\n parentBaseTheme,\n base,\n min,\n max,\n isParentComponentTheme,\n })\n }\n\n for (let i = max; i >= min; i--) {\n let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)\n if (props.inverse) {\n prefix = inverseThemeName(prefix)\n }\n const potentials: string[] = []\n if (prefix && prefix !== parentBaseTheme) {\n potentials.push(prefix)\n }\n if (nextName) {\n potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)\n }\n if (i === 1) {\n const lastSegment = potentials.findIndex((x) => !x.includes('_'))\n if (lastSegment > 0) {\n potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent\n }\n }\n if (componentName) {\n // components only look for component themes\n if (nextName) {\n const beforeSeparator = prefix.slice(0, prefix.indexOf(THEME_NAME_SEPARATOR))\n potentials.push(`${beforeSeparator}_${nextName}_${componentName}`)\n }\n potentials.push(`${prefix}_${componentName}`)\n if (nextName) {\n potentials.unshift(`${prefix}_${nextName}_${componentName}`)\n }\n }\n\n const found = potentials.find((t) => t in themes)\n\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.log(' - ', { found, potentials, parentManager })\n }\n\n if (found) {\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props),\n parentName,\n }\n break\n }\n }\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.warn('ThemeManager.getState():', {\n result,\n })\n console.trace()\n console.groupEnd()\n }\n\n return result\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\n ? themeName.replace(/^light/, 'dark')\n : themeName.replace(/^dark/, 'light')\n}\n\nexport function getNonComponentParentManager(themeManager?: ThemeManager | null) {\n // components never inherit from components\n // example <Switch><Switch.Thumb /></Switch>\n // the Switch theme shouldn't be considered parent of Thumb\n let res = themeManager\n while (res) {\n if (res?.isComponent) {\n res = res.parentManager\n } else {\n break\n }\n }\n return res\n}\n"],
5
+ "mappings": "AAAA,SAAS,WAAW,iBAAiB;AACrC,SAAS,wBAAwB,4BAA4B;AAC7D,SAAS,yBAAyB;AAoBlC,MAAM,aAAgC,EAAE,MAAM,GAAG;AAE1C,SAAS,wBAAwB,OAAmB;AACzD,SAAO,EAAE,MAAM,QAAQ,MAAM,iBAAiB,MAAM,WAAW,MAAM;AACvE;AAEA,IAAI,MAAM;AAEH,MAAM,aAAa;AAAA,EAOxB,YACS,QAAoB,CAAC,GAC5B,iBACA;AAFO;AAPT,cAAK;AACL,uBAAc;AACd,0BAAiB,oBAAI,IAAmB;AACxC,yBAAqC;AACrC,iBAA2B;AA2G3B,oBAA+B;AArG7B,QAAI,oB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Q,WAAW,KAAK,CAAC,MAAM,KAAK,MAAM;AAEhD,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,MAAM,UAAU,UAAU;AAC7E,cAAQ,IAAI,OAAO,EAAE,OAAO,YAAY,cAAc,CAAC;AAAA,IACzD;AAEA,QAAI,OAAO;AACT,eAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO,kBAAkB,OAAO,KAAK,CAAC;AAAA,QACtC,WAAW,sBAAsB,OAAO,KAAK;AAAA,QAC7C;AAAA,MACF;AACA;AAAA,IACF;AAAA,EACF;AAGA,MAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,MAAM,UAAU,UAAU;AAC7E,YAAQ,KAAK,4BAA4B;AAAA,MACvC;AAAA,IACF,CAAC;AACD,YAAQ,MAAM;AACd,YAAQ,SAAS;AAAA,EACnB;AAEA,SAAO;AACT;AAEA,MAAM,mBAAmB,CAAC,cAAsB;AAC9C,SAAO,UAAU,WAAW,OAAO,IAC/B,UAAU,QAAQ,UAAU,MAAM,IAClC,UAAU,QAAQ,SAAS,OAAO;AACxC;AAEO,SAAS,6BAA6B,cAAoC;AAI/E,MAAI,MAAM;AACV,SAAO,KAAK;AACV,QAAI,2BAAK,aAAa;AACpB,YAAM,IAAI;AAAA,IACZ,OAAO;AACL;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
6
6
  "names": ["lastSegment"]
7
7
  }
@@ -141,6 +141,9 @@ function getState(props, parentManager) {
141
141
  if (props.name && props.reset) {
142
142
  throw new Error("Cannot reset + set new name");
143
143
  }
144
+ if (!props.name && !props.inverse && !props.reset && !props.componentName) {
145
+ return null;
146
+ }
144
147
  if (props.reset && !(parentManager == null ? void 0 : parentManager.parentManager)) {
145
148
  if (process.env.NODE_ENV === "development") {
146
149
  console.warn("Cannot reset no grandparent exists");
@@ -202,7 +205,7 @@ function getState(props, parentManager) {
202
205
  }
203
206
  const found = potentials.find((t) => t in themes);
204
207
  if (process.env.NODE_ENV === "development" && typeof props.debug === "string") {
205
- console.log(" - ", { found, potentials });
208
+ console.log(" - ", { found, potentials, parentManager });
206
209
  }
207
210
  if (found) {
208
211
  result = {