@tamagui/web 1.14.7 → 1.14.9
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.
- package/dist/cjs/helpers/ThemeManager.js +4 -1
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +38 -16
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/views/ThemeDebug.js +57 -38
- package/dist/cjs/views/ThemeDebug.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +4 -1
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.mjs +4 -1
- package/dist/esm/helpers/ThemeManager.mjs.map +2 -2
- package/dist/esm/hooks/useTheme.js +38 -16
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/hooks/useTheme.mjs +38 -16
- package/dist/esm/hooks/useTheme.mjs.map +2 -2
- package/dist/esm/views/ThemeDebug.js +59 -40
- package/dist/esm/views/ThemeDebug.js.map +2 -2
- package/dist/esm/views/ThemeDebug.mjs +59 -40
- package/dist/esm/views/ThemeDebug.mjs.map +2 -2
- package/package.json +9 -9
- package/src/helpers/ThemeManager.tsx +5 -1
- package/src/hooks/useTheme.tsx +43 -18
- package/src/views/ThemeDebug.tsx +55 -34
- package/types/Tamagui.d.ts.map +1 -0
- package/types/addTheme.d.ts.map +1 -0
- package/types/config.d.ts.map +1 -0
- package/types/constants/constants.d.ts.map +1 -0
- package/types/constants/isDevTools.d.ts.map +1 -0
- package/types/contexts/AnimationDriverContext.d.ts.map +1 -0
- package/types/contexts/ButtonNestingContext.d.ts.map +1 -0
- package/types/contexts/FontLanguageContext.d.ts.map +1 -0
- package/types/contexts/TextAncestorContext.d.ts.map +1 -0
- package/types/createComponent.d.ts.map +1 -0
- package/types/createFont.d.ts.map +1 -0
- package/types/createShorthands.d.ts.map +1 -0
- package/types/createTamagui.d.ts.map +1 -0
- package/types/createTheme.d.ts.map +1 -0
- package/types/createTokens.d.ts.map +1 -0
- package/types/createVariable.d.ts.map +1 -0
- package/types/createVariables.d.ts.map +1 -0
- package/types/helpers/ThemeManager.d.ts.map +1 -0
- package/types/helpers/ThemeManagerContext.d.ts.map +1 -0
- package/types/helpers/createMediaStyle.d.ts.map +1 -0
- package/types/helpers/createPropMapper.d.ts.map +1 -0
- package/types/helpers/createProxy.d.ts.map +1 -0
- package/types/helpers/defaultOffset.d.ts.map +1 -0
- package/types/helpers/expandStyle.d.ts.map +1 -0
- package/types/helpers/expandStyles.d.ts.map +1 -0
- package/types/helpers/extendStaticConfig.d.ts.map +1 -0
- package/types/helpers/getAnimationDriver.d.ts.map +1 -0
- package/types/helpers/getExpandedShorthands.d.ts.map +1 -0
- package/types/helpers/getFontLanguage.d.ts.map +1 -0
- package/types/helpers/getSplitStyles.d.ts.map +1 -0
- package/types/helpers/getStylesAtomic.d.ts.map +1 -0
- package/types/helpers/getStylesAtomic.native.d.ts.map +1 -0
- package/types/helpers/getThemeCSSRules.d.ts.map +1 -0
- package/types/helpers/getThemeCSSRules.native.d.ts.map +1 -0
- package/types/helpers/getVariantExtras.d.ts.map +1 -0
- package/types/helpers/insertStyleRule.d.ts.map +1 -0
- package/types/helpers/isObj.d.ts.map +1 -0
- package/types/helpers/isTamaguiComponent.d.ts.map +1 -0
- package/types/helpers/isTamaguiElement.d.ts.map +1 -0
- package/types/helpers/matchMedia.d.ts.map +1 -0
- package/types/helpers/matchMedia.native.d.ts.map +1 -0
- package/types/helpers/mergeProps.d.ts.map +1 -0
- package/types/helpers/normalizeColor.d.ts.map +1 -0
- package/types/helpers/normalizeShadow.d.ts.map +1 -0
- package/types/helpers/normalizeShadow.native.d.ts.map +1 -0
- package/types/helpers/normalizeStylePropKeys.d.ts.map +1 -0
- package/types/helpers/normalizeStylePropKeys.native.d.ts.map +1 -0
- package/types/helpers/normalizeValueWithProperty.d.ts.map +1 -0
- package/types/helpers/proxyThemeVariables.d.ts.map +1 -0
- package/types/helpers/pseudoDescriptors.d.ts.map +1 -0
- package/types/helpers/registerCSSVariable.d.ts.map +1 -0
- package/types/helpers/themeable.d.ts.map +1 -0
- package/types/helpers/themes.d.ts.map +1 -0
- package/types/helpers/timer.d.ts.map +1 -0
- package/types/helpers/useShallowSetState.d.ts.map +1 -0
- package/types/helpers/warnOnce.d.ts.map +1 -0
- package/types/helpers/withStaticProperties.d.ts.map +1 -0
- package/types/hooks/getThemeUnwrapped.d.ts.map +1 -0
- package/types/hooks/useAnimationDriver.d.ts.map +1 -0
- package/types/hooks/useId.d.ts.map +1 -0
- package/types/hooks/useIsTouchDevice.d.ts.map +1 -0
- package/types/hooks/useMedia.d.ts.map +1 -0
- package/types/hooks/useSafeRef.d.ts.map +1 -0
- package/types/hooks/useServerHooks.d.ts.map +1 -0
- package/types/hooks/useStyle.d.ts.map +1 -0
- package/types/hooks/useTheme.d.ts.map +1 -0
- package/types/hooks/useThemeName.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -0
- package/types/inject-styles.d.ts.map +1 -0
- package/types/insertFont.d.ts.map +1 -0
- package/types/setupHooks.d.ts.map +1 -0
- package/types/setupReactNative.d.ts.map +1 -0
- package/types/styled.d.ts.map +1 -0
- package/types/types.d.ts.map +1 -0
- package/types/updateTheme.d.ts.map +1 -0
- package/types/views/AnimationDriverProvider.d.ts.map +1 -0
- package/types/views/FontLanguage.d.ts.map +1 -0
- package/types/views/FontLanguage.native.d.ts.map +1 -0
- package/types/views/FontLanguage.types.d.ts.map +1 -0
- package/types/views/Slot.d.ts.map +1 -0
- package/types/views/Stack.d.ts.map +1 -0
- package/types/views/TamaguiProvider.d.ts.map +1 -0
- package/types/views/Text.d.ts.map +1 -0
- package/types/views/Theme.d.ts.map +1 -0
- package/types/views/ThemeDebug.d.ts.map +1 -0
- 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,YACE,QAAmD,KAAK,SAAS,CAAC,GAClE,eAAe,MACf;AACA,UAAM,cAAc,MAAM;AACxB,UAAI,MAAM,YAAY;AACpB,aAAK,MAA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AAK,MAAM;AAAA,IACxB;AACA,QAAI,UAAU;AACZ,iBAAW,QAAQ,SAAS,GAAG,UAAU,aAAa,QAAQ;AAAA,IAChE;AACA,QAAI,MAAM,GAAG;AACX,YAAMA,eAAc,WAAW,UAAU,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,CAAC;AAChE,UAAIA,eAAc,GAAG;AACnB,mBAAW,OAAOA,cAAa,GAAG,QAAQ;AAAA,MAC5C;AAAA,IACF;AACA,QAAI,eAAe;AAEjB,UAAI,UAAU;AACZ,cAAM,kBAAkB,OAAO,MAAM,GAAG,OAAO,QAAQ,qCAAoB,CAAC;AAC5E,mBAAW,KAAK,GAAG,mBAAmB,YAAY,eAAe;AAAA,MACnE;AACA,iBAAW,KAAK,GAAG,UAAU,eAAe;AAC5C,UAAI,UAAU;AACZ,mBAAW,QAAQ,GAAG,UAAU,YAAY,eAAe;AAAA,MAC7D;AAAA,IACF;AAEA,UAAM,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,MAAM;AAEhD,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,MAAM,UAAU,UAAU;AAC7E,cAAQ,IAAI,OAAO,EAAE,OAAO,
|
|
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": ";;;;;;;;;;;;;;;;;;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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F;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
|
}
|
|
@@ -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
|
|
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,12 +173,16 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
180
173
|
};
|
|
181
174
|
}, [isNewTheme, themeManager, state, debug]);
|
|
182
175
|
(0, import_react.useLayoutEffect)(() => {
|
|
183
|
-
const nextState =
|
|
176
|
+
const nextState = getShouldUpdateTheme(themeManager);
|
|
184
177
|
if (nextState) {
|
|
185
178
|
if (isNewTheme) {
|
|
186
179
|
themeManager.updateState(nextState, true);
|
|
187
180
|
}
|
|
188
181
|
setThemeState(createState);
|
|
182
|
+
} else {
|
|
183
|
+
if (isNewTheme) {
|
|
184
|
+
setThemeState(createState);
|
|
185
|
+
}
|
|
189
186
|
}
|
|
190
187
|
const disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme((name, manager) => {
|
|
191
188
|
const shouldUpdate = Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
|
|
@@ -207,6 +204,15 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
207
204
|
props.name,
|
|
208
205
|
props.reset
|
|
209
206
|
]);
|
|
207
|
+
if (process.env.NODE_ENV === "development") {
|
|
208
|
+
(0, import_react.useEffect)(() => {
|
|
209
|
+
globalThis["TamaguiThemeManagers"] ?? (globalThis["TamaguiThemeManagers"] = /* @__PURE__ */ new Set());
|
|
210
|
+
globalThis["TamaguiThemeManagers"].add(themeManager);
|
|
211
|
+
return () => {
|
|
212
|
+
globalThis["TamaguiThemeManagers"].delete(themeManager);
|
|
213
|
+
};
|
|
214
|
+
}, [themeManager]);
|
|
215
|
+
}
|
|
210
216
|
}
|
|
211
217
|
if (shouldReturnParentState) {
|
|
212
218
|
if (!parentManager)
|
|
@@ -235,7 +241,8 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
235
241
|
if (prev == null ? void 0 : prev.themeManager) {
|
|
236
242
|
themeManager2 = prev.themeManager;
|
|
237
243
|
const forceChange = Boolean(keys == null ? void 0 : keys.length);
|
|
238
|
-
const
|
|
244
|
+
const next = themeManager2.getState(props, parentManager);
|
|
245
|
+
const nextState = getShouldUpdateTheme(themeManager2, next, forceChange);
|
|
239
246
|
if (nextState) {
|
|
240
247
|
state2 = nextState;
|
|
241
248
|
if (!prev.isNewTheme || !import_constants.isWeb) {
|
|
@@ -243,13 +250,17 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
243
250
|
} else {
|
|
244
251
|
themeManager2.updateState(nextState, true);
|
|
245
252
|
}
|
|
253
|
+
} else {
|
|
254
|
+
if (prev.isNewTheme) {
|
|
255
|
+
if (parentManager && !next) {
|
|
256
|
+
themeManager2 = parentManager;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
246
259
|
}
|
|
247
260
|
} else {
|
|
248
261
|
themeManager2 = getNewThemeManager();
|
|
249
262
|
}
|
|
250
|
-
const isNewTheme2 = Boolean(
|
|
251
|
-
themeManager2 !== parentManager || prev && themeManager2.state.name !== prev.state.name
|
|
252
|
-
);
|
|
263
|
+
const isNewTheme2 = Boolean(themeManager2 !== parentManager);
|
|
253
264
|
const mounted2 = !props.inverse ? true : root || (prev == null ? void 0 : prev.mounted);
|
|
254
265
|
if (!state2) {
|
|
255
266
|
state2 = isNewTheme2 ? { ...themeManager2.state } : { ...parentManager.state };
|
|
@@ -261,8 +272,19 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
261
272
|
mounted: mounted2
|
|
262
273
|
};
|
|
263
274
|
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
264
|
-
console.groupCollapsed(` \u{1F537} useChangeThemeEffect createState`);
|
|
265
|
-
|
|
275
|
+
console.groupCollapsed(` \u{1F537} ${themeManager2.id} useChangeThemeEffect createState`);
|
|
276
|
+
const parentState = { ...parentManager == null ? void 0 : parentManager.state };
|
|
277
|
+
const parentId = parentManager == null ? void 0 : parentManager.id;
|
|
278
|
+
const themeManagerState = { ...themeManager2.state };
|
|
279
|
+
console.log({
|
|
280
|
+
props,
|
|
281
|
+
parentState,
|
|
282
|
+
parentId,
|
|
283
|
+
themeManager: themeManager2,
|
|
284
|
+
prev,
|
|
285
|
+
response,
|
|
286
|
+
themeManagerState
|
|
287
|
+
});
|
|
266
288
|
console.groupEnd();
|
|
267
289
|
}
|
|
268
290
|
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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A,MACjB,cAAc;AAAA,IAChB;AAAA,EACF;AAEA,QAAM,oBAAgB,sDAA6B,yBAAW,8CAAmB,CAAC;AAElF,QAAM;AAAA,IACJ;AAAA;AAAA,IAEA;AAAA,EACF,IAAI;AAEJ,MAAI,SAAS;AACX,QAAI,CAAC;AAAe,YAAM;AAC1B,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,GAAG,cAAc;AAAA,MACjB,cAAc;AAAA,IAChB;AAAA,EACF;AAEA,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAgB,WAAW;AAC/D,QAAM,EAAE,OAAO,cAAc,SAAS,WAAW,IAAI;AACrD,QAAM,qBAAqB,QAAQ,CAAC,WAAW,WAAW,MAAM,OAAO;AACvE,QAAM,0BAA0B;AAEhC,WAAS,
|
|
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 = 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 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,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QC,cAAa,EAAE,GAAGF,cAAa,MAAM,IAAI,EAAE,GAAG,cAAe,MAAM;AAAA,IAC7E;AAEA,UAAM,WAAW;AAAA,MACf,OAAAC;AAAA,MACA,cAAAD;AAAA,MACA,YAAAE;AAAA,MACA,SAAAC;AAAA,IACF;AAEA,QAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,OAAO,GAAG;AAC5D,cAAQ,eAAe,cAAOH,cAAa,qCAAqC;AAChF,YAAM,cAAc,EAAE,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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 <
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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 <Theme {id} /> \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,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,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,YACE,QAAmD,KAAK,SAAS,CAAC,GAClE,eAAe,MACf;AACA,UAAM,cAAc,MAAM;AACxB,UAAI,MAAM,YAAY;AACpB,aAAK,MAAM,QAAQ,MAAM;AACzB,aAAK,MAAM,OAAO,MAAM,QAAQ;AAChC,eAAO;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Aa,QAAQ;AAAA,IAChE;AACA,QAAI,MAAM,GAAG;AACX,YAAMA,eAAc,WAAW,UAAU,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,CAAC;AAChE,UAAIA,eAAc,GAAG;AACnB,mBAAW,OAAOA,cAAa,GAAG,QAAQ;AAAA,MAC5C;AAAA,IACF;AACA,QAAI,eAAe;AAEjB,UAAI,UAAU;AACZ,cAAM,kBAAkB,OAAO,MAAM,GAAG,OAAO,QAAQ,oBAAoB,CAAC;AAC5E,mBAAW,KAAK,GAAG,mBAAmB,YAAY,eAAe;AAAA,MACnE;AACA,iBAAW,KAAK,GAAG,UAAU,eAAe;AAC5C,UAAI,UAAU;AACZ,mBAAW,QAAQ,GAAG,UAAU,YAAY,eAAe;AAAA,MAC7D;AAAA,IACF;AAEA,UAAM,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,MAAM;AAEhD,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,MAAM,UAAU,UAAU;AAC7E,cAAQ,IAAI,OAAO,EAAE,OAAO,
|
|
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": "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,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,YACE,QAAmD,KAAK,SAAS,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,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 = {
|