@tamagui/web 1.5.8 → 1.5.10

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.
@@ -135,11 +135,11 @@ class ThemeManager {
135
135
  }
136
136
  }
137
137
  function getNextThemeClassName(name, isInverting = false) {
138
- const next = `${import_constants.THEME_CLASSNAME_PREFIX}${name}`;
138
+ const next = `t_sub_theme ${import_constants.THEME_CLASSNAME_PREFIX}${name}`;
139
139
  if (isInverting) {
140
140
  return next + // ensure you invert to base dark as well as specific dark
141
141
  // ... logic should likely be elsewhere
142
- (next.includes("dark_") ? ` t_dark` : "") + (next.includes("light_") ? ` t_light` : "");
142
+ (next.includes("dark_") ? ` t_dark` : next.includes("light_") ? ` t_light` : "");
143
143
  }
144
144
  return next.replace("light_", "").replace("dark_", "");
145
145
  }
@@ -155,7 +155,8 @@ function getState(props, parentManager) {
155
155
  throw new Error("Cannot reset + set new name");
156
156
  }
157
157
  if (props.reset && !(parentManager == null ? void 0 : parentManager.parentManager)) {
158
- throw new Error("Cannot reset no grandparent exists");
158
+ console.warn("Cannot reset no grandparent exists");
159
+ return null;
159
160
  }
160
161
  let result = null;
161
162
  const nextName = props.reset ? ((_b = (_a = parentManager == null ? void 0 : parentManager.parentManager) == null ? void 0 : _a.state) == null ? void 0 : _b.name) || "" : props.name || "";
@@ -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\nexport class ThemeManager {\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManager?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManager === 'root') {\n this.updateState(props, false)\n return\n }\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n console.trace()\n throw new Error(`No parent manager given`)\n }\n throw `\u274C`\n }\n // copy over listeners\n this.themeListeners = parentManager.themeListeners\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n if (parentManager) {\n this.parentManager = parentManager\n }\n const updatedState = this.getStateIfChanged(props)\n if (updatedState) {\n this.state = updatedState\n return\n }\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n notify = true\n ) {\n const shouldFlush = (() => {\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.state = nextState\n return true\n }\n })()\n if (shouldFlush) {\n // reset any derived state\n this._allKeys = null\n notify && this.notify()\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) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, isInverting = false) {\n const next = `${THEME_CLASSNAME_PREFIX}${name}`\n if (isInverting) {\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` : '') +\n (next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nconst cache = new WeakMap<ThemeProps, [ThemeManager, ThemeManagerState | null]>()\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const cached = cache.get(props)\n if (cached && cached[0] === parentManager) {\n return cached[1]\n }\n\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n if (props.reset && !parentManager?.parentManager) {\n throw new Error('Cannot reset no grandparent exists')\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 isParentAComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentAComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentAComponentTheme\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 // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') [ console.groupCollapsed('ThemeManager.getState()', props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme }), console.trace(), console.groupEnd() ]\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 potentials.push(\n `${prefix.slice(\n 0,\n prefix.indexOf(THEME_NAME_SEPARATOR)\n )}_${nextName}_${componentName}`\n )\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 // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose')\n console.log('getState found', found, 'from', potentials, 'parentName', parentName)\n\n if (found) {\n // optimization return null if not changed\n if (found === parentName) {\n break\n }\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props.inverse),\n parentName,\n }\n break\n }\n }\n\n if (parentManager) {\n cache.set(props, [parentManager, result])\n }\n\n return result\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\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7D;AAAA,IACF;AAEA,UAAM,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,MAAM;AAGhD,QAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAC5D,cAAQ,IAAI,kBAAkB,OAAO,QAAQ,YAAY,cAAc,UAAU;AAEnF,QAAI,OAAO;AAET,UAAI,UAAU,YAAY;AACxB;AAAA,MACF;AACA,eAAS;AAAA,QACP,MAAM;AAAA,QACN,WAAO,4CAAkB,OAAO,KAAK,CAAC;AAAA,QACtC,WAAW,sBAAsB,OAAO,MAAM,OAAO;AAAA,QACrD;AAAA,MACF;AACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,IAAI,OAAO,CAAC,eAAe,MAAM,CAAC;AAAA,EAC1C;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;",
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\nexport class ThemeManager {\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManager?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManager === 'root') {\n this.updateState(props, false)\n return\n }\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n console.trace()\n throw new Error(`No parent manager given`)\n }\n throw `\u274C`\n }\n // copy over listeners\n this.themeListeners = parentManager.themeListeners\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n if (parentManager) {\n this.parentManager = parentManager\n }\n const updatedState = this.getStateIfChanged(props)\n if (updatedState) {\n this.state = updatedState\n return\n }\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n notify = true\n ) {\n const shouldFlush = (() => {\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.state = nextState\n return true\n }\n })()\n if (shouldFlush) {\n // reset any derived state\n this._allKeys = null\n notify && this.notify()\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) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, isInverting = false) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (isInverting) {\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\nconst cache = new WeakMap<ThemeProps, [ThemeManager, ThemeManagerState | null]>()\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const cached = cache.get(props)\n if (cached && cached[0] === parentManager) {\n return cached[1]\n }\n\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n if (props.reset && !parentManager?.parentManager) {\n console.warn('Cannot reset no grandparent exists')\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 isParentAComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentAComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentAComponentTheme\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 // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') [ console.groupCollapsed('ThemeManager.getState()', props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme }), console.trace(), console.groupEnd() ]\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 potentials.push(\n `${prefix.slice(\n 0,\n prefix.indexOf(THEME_NAME_SEPARATOR)\n )}_${nextName}_${componentName}`\n )\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 // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose')\n console.log('getState found', found, 'from', potentials, 'parentName', parentName)\n\n if (found) {\n // optimization return null if not changed\n if (found === parentName) {\n break\n }\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props.inverse),\n parentName,\n }\n break\n }\n }\n\n if (parentManager) {\n cache.set(props, [parentManager, result])\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;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,QA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AAM;AAAA,QACN,WAAO,4CAAkB,OAAO,KAAK,CAAC;AAAA,QACtC,WAAW,sBAAsB,OAAO,MAAM,OAAO;AAAA,QACrD;AAAA,MACF;AACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,IAAI,OAAO,CAAC,eAAe,MAAM,CAAC;AAAA,EAC1C;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;",
6
6
  "names": ["lastSegment"]
7
7
  }
@@ -46,63 +46,80 @@ function getThemeCSSRules({
46
46
  vars += `--${(0, import_helpers.simpleHash)(themeKey, 40)}:${value};`;
47
47
  }
48
48
  const isDarkOrLightBase = themeName === "dark" || themeName === "light";
49
- const selectors = names.map((name) => {
50
- return `${CNP}${name}`;
51
- });
49
+ const selectorsSet = new Set(
50
+ names.map((name) => {
51
+ return `${CNP}${name}`;
52
+ })
53
+ );
52
54
  if (hasDarkLight) {
53
55
  for (const subName of names) {
54
- const isDark = isDarkOrLightBase || subName.startsWith("dark_");
55
- const max = config.maxDarkLightNesting ?? 3;
56
+ const isDark = themeName === "dark" || subName.startsWith("dark_");
57
+ const maxDepth = config.maxDarkLightNesting ?? 3;
56
58
  if (!(isDark || subName.startsWith("light_"))) {
57
- selectors.push(`:root:root ${CNP}${subName}`);
59
+ selectorsSet.add(`:root:root ${CNP}${subName}`);
58
60
  continue;
59
61
  }
60
62
  const childSelector = `${CNP}${subName.replace(isDark ? "dark_" : "light_", "")}`;
61
- const order = isDark ? ["dark", "light"] : ["light", "dark"];
62
- if (isDarkOrLightBase) {
63
- order.reverse();
64
- }
65
- const [stronger, weaker] = order;
66
- const numSelectors = Math.round(max * 1.5);
67
- for (let pi = 0; pi < numSelectors; pi++) {
68
- const isOdd = pi % 2 === 1;
69
- if (isOdd && pi < 3)
70
- continue;
71
- const parents = new Array(pi + 1).fill(void 0).map((_, psi) => {
72
- return `${CNP}${psi % 2 === 0 ? stronger : weaker}`;
73
- });
74
- let parentSelectors = parents.length > 1 ? parents.slice(1) : parents;
75
- if (isOdd) {
76
- const [_first, second, ...rest] = parentSelectors;
77
- parentSelectors = [second, ...rest, second];
63
+ const [altLightDark, altSubTheme] = [
64
+ isDark ? ["dark", "light"] : ["light", "dark"],
65
+ isDark ? ["dark", "sub_theme"] : ["light", "sub_theme"]
66
+ ];
67
+ for (const order of [altLightDark, altSubTheme]) {
68
+ if (isDarkOrLightBase) {
69
+ order.reverse();
70
+ }
71
+ const [stronger, weaker] = order;
72
+ const numSelectors = Math.round(maxDepth * 1.5);
73
+ for (let depth = 0; depth < numSelectors; depth++) {
74
+ const isOdd = depth % 2 === 1;
75
+ if (isOdd && depth < 3) {
76
+ continue;
77
+ }
78
+ const parents = new Array(depth + 1).fill(0).map((_, psi) => {
79
+ return `${CNP}${psi % 2 === 0 ? stronger : weaker}`;
80
+ });
81
+ let parentSelectors = parents.length > 1 ? parents.slice(1) : parents;
82
+ if (isOdd) {
83
+ const [_first, second, ...rest] = parentSelectors;
84
+ parentSelectors = [second, ...rest, second];
85
+ }
86
+ const lastParentSelector = parentSelectors[parentSelectors.length - 1];
87
+ const nextChildSelector = childSelector === lastParentSelector ? "" : childSelector;
88
+ selectorsSet.add(`${parentSelectors.join(" ")} ${nextChildSelector}`.trim());
78
89
  }
79
- const lastParentSelector = parentSelectors[parentSelectors.length - 1];
80
- selectors.push(
81
- `${parentSelectors.join(" ")} ${childSelector === lastParentSelector ? "" : childSelector}`
82
- );
83
90
  }
84
91
  }
85
92
  }
93
+ const selectors = [...selectorsSet];
86
94
  const selectorsString = selectors.map((x) => {
87
- const isBaseTheme = x === ".t_dark" || x === ".t_light" || x.startsWith(".t_dark ") || x.startsWith(".t_light ");
88
- const rootSep = isBaseTheme && config.themeClassNameOnRoot ? "" : " ";
95
+ const rootSep = isBaseTheme(x) && config.themeClassNameOnRoot ? "" : " ";
89
96
  return `:root${rootSep}${x}`;
90
- });
91
- const css = `${selectorsString.join(", ")} {${vars}}`;
97
+ }).join(", ");
98
+ const css = `${selectorsString} {${vars}}`;
92
99
  cssRuleSets.push(css);
93
- if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {
100
+ if (config.shouldAddPrefersColorThemes) {
101
+ const bgString = (0, import_createVariable.variableToString)(theme.background);
102
+ const fgString = (0, import_createVariable.variableToString)(theme.color);
103
+ const bodyRules = `body{background:${bgString};color:${fgString};}`;
94
104
  const isDark = themeName.startsWith("dark");
95
- cssRuleSets.push(
96
- `@media(prefers-color-scheme: ${isDark ? "dark" : "light"}) {
97
- body { background:${(0, import_createVariable.variableToString)(theme.background)}; color: ${(0, import_createVariable.variableToString)(
98
- theme.color
99
- )} }
100
- :root {${vars} }
101
- }`
102
- );
105
+ const baseName = isDark ? "dark" : "light";
106
+ const lessSpecificSelectors = selectors.map((x) => {
107
+ if (x == darkSelector || x === lightSelector)
108
+ return `:root`;
109
+ return x.replace(/^\.t_(dark|light) /, "").trim();
110
+ }).filter(Boolean).join(", ");
111
+ const themeRules = `${lessSpecificSelectors} {${vars}}`;
112
+ const prefersMediaSelectors = `@media(prefers-color-scheme:${baseName}){
113
+ ${bodyRules}
114
+ ${themeRules}
115
+ }`;
116
+ cssRuleSets.push(prefersMediaSelectors);
103
117
  }
104
118
  return cssRuleSets;
105
119
  }
120
+ const darkSelector = ".t_dark";
121
+ const lightSelector = ".t_light";
122
+ const isBaseTheme = (x) => x === darkSelector || x === lightSelector || x.startsWith(".t_dark ") || x.startsWith(".t_light ");
106
123
  // Annotate the CommonJS export names for ESM import in node:
107
124
  0 && (module.exports = {
108
125
  getThemeCSSRules
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/getThemeCSSRules.ts"],
4
- "sourcesContent": ["import { simpleHash } from '@tamagui/helpers'\n\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants.js'\nimport { Variable, variableToString } from '../createVariable.js'\nimport type { CreateTamaguiProps, ThemeParsed } from '../types.js'\nimport { tokensValueToVariable } from './registerCSSVariable.js'\n\nexport function getThemeCSSRules({\n config,\n themeName,\n theme,\n names,\n}: {\n config: CreateTamaguiProps\n themeName: string\n theme: ThemeParsed\n names: string[]\n}) {\n const cssRuleSets: string[] = []\n\n // special case for SSR\n const hasDarkLight = 'light' in config.themes && 'dark' in config.themes\n const CNP = `.${THEME_CLASSNAME_PREFIX}`\n let vars = ''\n\n // themeToVariableToValueMap.set(theme, {})\n // const varToValMap = themeToVariableToValueMap.get(theme)\n for (const themeKey in theme) {\n const variable = theme[themeKey] as Variable\n let value: any = null\n // if (varToValMap) {\n // varToValMap[variable.variable] = variable.val\n // }\n if (!tokensValueToVariable.has(variable.val)) {\n value = variable.val\n } else {\n value = tokensValueToVariable.get(variable.val)!.variable\n }\n // Hash themeKey in case it has invalid chars too\n vars += `--${simpleHash(themeKey, 40)}:${value};`\n }\n\n const isDarkOrLightBase = themeName === 'dark' || themeName === 'light'\n const selectors = names.map((name) => {\n return `${CNP}${name}`\n })\n\n // since we dont specify dark/light in classnames we have to do an awkward specificity war\n // use config.maxDarkLightNesting to determine how deep you can nest until it breaks\n if (hasDarkLight) {\n for (const subName of names) {\n const isDark = isDarkOrLightBase || subName.startsWith('dark_')\n const max = config.maxDarkLightNesting ?? 3\n\n if (!(isDark || subName.startsWith('light_'))) {\n // neither light nor dark subtheme, just generate one selector with :root:root which\n // will override all :root light/dark selectors generated below\n selectors.push(`:root:root ${CNP}${subName}`)\n continue\n }\n\n const childSelector = `${CNP}${subName.replace(isDark ? 'dark_' : 'light_', '')}`\n const order = isDark ? ['dark', 'light'] : ['light', 'dark']\n if (isDarkOrLightBase) {\n order.reverse()\n }\n const [stronger, weaker] = order\n const numSelectors = Math.round(max * 1.5)\n\n for (let pi = 0; pi < numSelectors; pi++) {\n const isOdd = pi % 2 === 1\n if (isOdd && pi < 3) continue\n const parents = new Array(pi + 1).fill(undefined).map((_, psi) => {\n return `${CNP}${psi % 2 === 0 ? stronger : weaker}`\n })\n let parentSelectors = parents.length > 1 ? parents.slice(1) : parents\n if (isOdd) {\n const [_first, second, ...rest] = parentSelectors\n parentSelectors = [second, ...rest, second]\n }\n // avoid .t_light .t_light at the end (make sure child is unique from last parent)\n const lastParentSelector = parentSelectors[parentSelectors.length - 1]\n selectors.push(\n `${parentSelectors.join(' ')} ${\n childSelector === lastParentSelector ? '' : childSelector\n }`\n )\n }\n }\n }\n\n const selectorsString = selectors.map((x) => {\n // only do our :root attach if it's not light/dark - not support sub themes on root saves a lot of effort/size\n // this isBaseTheme logic could probably be done more efficiently above\n const isBaseTheme =\n x === '.t_dark' ||\n x === '.t_light' ||\n x.startsWith('.t_dark ') ||\n x.startsWith('.t_light ')\n const rootSep = isBaseTheme && config.themeClassNameOnRoot ? '' : ' '\n return `:root${rootSep}${x}`\n })\n const css = `${selectorsString.join(', ')} {${vars}}`\n cssRuleSets.push(css)\n\n if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {\n // add media prefers for dark/light base\n const isDark = themeName.startsWith('dark')\n cssRuleSets.push(\n `@media(prefers-color-scheme: ${isDark ? 'dark' : 'light'}) {\nbody { background:${variableToString(theme.background)}; color: ${variableToString(\n theme.color\n )} }\n:root {${vars} } \n}`\n )\n }\n\n return cssRuleSets\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAE3B,uBAAuC;AACvC,4BAA2C;AAE3C,iCAAsC;AAE/B,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,QAAM,cAAwB,CAAC;AAG/B,QAAM,eAAe,WAAW,OAAO,UAAU,UAAU,OAAO;AAClE,QAAM,MAAM,IAAI;AAChB,MAAI,OAAO;AAIX,aAAW,YAAY,OAAO;AAC5B,UAAM,WAAW,MAAM,QAAQ;AAC/B,QAAI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I;AAClC,4BAAkB,CAAC,QAAQ,GAAG,MAAM,MAAM;AAAA,QAC5C;AAEA,cAAM,qBAAqB,gBAAgB,gBAAgB,SAAS,CAAC;AACrE,kBAAU;AAAA,UACR,GAAG,gBAAgB,KAAK,GAAG,KACzB,kBAAkB,qBAAqB,KAAK;AAAA,QAEhD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,kBAAkB,UAAU,IAAI,CAAC,MAAM;AAG3C,UAAM,cACJ,MAAM,aACN,MAAM,cACN,EAAE,WAAW,UAAU,KACvB,EAAE,WAAW,WAAW;AAC1B,UAAM,UAAU,eAAe,OAAO,uBAAuB,KAAK;AAClE,WAAO,QAAQ,UAAU;AAAA,EAC3B,CAAC;AACD,QAAM,MAAM,GAAG,gBAAgB,KAAK,IAAI,MAAM;AAC9C,cAAY,KAAK,GAAG;AAEpB,MAAI,OAAO,+BAA+B,mBAAmB;AAE3D,UAAM,SAAS,UAAU,WAAW,MAAM;AAC1C,gBAAY;AAAA,MACV,gCAAgC,SAAS,SAAS;AAAA,wBACpC,wCAAiB,MAAM,UAAU,iBAAa;AAAA,QAC1D,MAAM;AAAA,MACR;AAAA,SACG;AAAA;AAAA,IAEL;AAAA,EACF;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import { simpleHash } from '@tamagui/helpers'\n\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants.js'\nimport { Variable, variableToString } from '../createVariable.js'\nimport type { CreateTamaguiProps, ThemeParsed } from '../types.js'\nimport { tokensValueToVariable } from './registerCSSVariable.js'\n\nexport function getThemeCSSRules({\n config,\n themeName,\n theme,\n names,\n}: {\n config: CreateTamaguiProps\n themeName: string\n theme: ThemeParsed\n names: string[]\n}) {\n const cssRuleSets: string[] = []\n\n // special case for SSR\n const hasDarkLight = 'light' in config.themes && 'dark' in config.themes\n const CNP = `.${THEME_CLASSNAME_PREFIX}`\n let vars = ''\n\n // themeToVariableToValueMap.set(theme, {})\n // const varToValMap = themeToVariableToValueMap.get(theme)\n for (const themeKey in theme) {\n const variable = theme[themeKey] as Variable\n let value: any = null\n // if (varToValMap) {\n // varToValMap[variable.variable] = variable.val\n // }\n if (!tokensValueToVariable.has(variable.val)) {\n value = variable.val\n } else {\n value = tokensValueToVariable.get(variable.val)!.variable\n }\n // Hash themeKey in case it has invalid chars too\n vars += `--${simpleHash(themeKey, 40)}:${value};`\n }\n\n const isDarkOrLightBase = themeName === 'dark' || themeName === 'light'\n const selectorsSet = new Set(\n names.map((name) => {\n return `${CNP}${name}`\n })\n )\n\n // since we dont specify dark/light in classnames we have to do an awkward specificity war\n // use config.maxDarkLightNesting to determine how deep you can nest until it breaks\n if (hasDarkLight) {\n for (const subName of names) {\n const isDark = themeName === 'dark' || subName.startsWith('dark_')\n const maxDepth = config.maxDarkLightNesting ?? 3\n\n if (!(isDark || subName.startsWith('light_'))) {\n // neither light nor dark subtheme, just generate one selector with :root:root which\n // will override all :root light/dark selectors generated below\n selectorsSet.add(`:root:root ${CNP}${subName}`)\n continue\n }\n\n const childSelector = `${CNP}${subName.replace(isDark ? 'dark_' : 'light_', '')}`\n\n const [altLightDark, altSubTheme] = [\n isDark ? ['dark', 'light'] : ['light', 'dark'],\n isDark ? ['dark', 'sub_theme'] : ['light', 'sub_theme'],\n ]\n\n for (const order of [altLightDark, altSubTheme]) {\n if (isDarkOrLightBase) {\n order.reverse()\n }\n const [stronger, weaker] = order\n const numSelectors = Math.round(maxDepth * 1.5)\n\n for (let depth = 0; depth < numSelectors; depth++) {\n const isOdd = depth % 2 === 1\n\n // wtf is this continue:\n if (isOdd && depth < 3) {\n continue\n }\n\n const parents = new Array(depth + 1).fill(0).map((_, psi) => {\n return `${CNP}${psi % 2 === 0 ? stronger : weaker}`\n })\n\n let parentSelectors = parents.length > 1 ? parents.slice(1) : parents\n\n if (isOdd) {\n const [_first, second, ...rest] = parentSelectors\n parentSelectors = [second, ...rest, second]\n }\n\n const lastParentSelector = parentSelectors[parentSelectors.length - 1]\n const nextChildSelector =\n childSelector === lastParentSelector ? '' : childSelector\n\n // for light/dark/light:\n selectorsSet.add(`${parentSelectors.join(' ')} ${nextChildSelector}`.trim())\n }\n }\n }\n }\n\n const selectors = [...selectorsSet]\n\n // only do our :root attach if it's not light/dark - not support sub themes on root saves a lot of effort/size\n // this isBaseTheme logic could probably be done more efficiently above\n const selectorsString = selectors\n .map((x) => {\n const rootSep = isBaseTheme(x) && config.themeClassNameOnRoot ? '' : ' '\n return `:root${rootSep}${x}`\n })\n .join(', ')\n\n const css = `${selectorsString} {${vars}}`\n cssRuleSets.push(css)\n\n if (config.shouldAddPrefersColorThemes) {\n const bgString = variableToString(theme.background)\n const fgString = variableToString(theme.color)\n const bodyRules = `body{background:${bgString};color:${fgString};}`\n const isDark = themeName.startsWith('dark')\n const baseName = isDark ? 'dark' : 'light'\n const lessSpecificSelectors = selectors\n .map((x) => {\n if (x == darkSelector || x === lightSelector) return `:root`\n return x.replace(/^\\.t_(dark|light) /, '').trim()\n })\n .filter(Boolean)\n .join(', ')\n const themeRules = `${lessSpecificSelectors} {${vars}}`\n const prefersMediaSelectors = `@media(prefers-color-scheme:${baseName}){\n ${bodyRules}\n ${themeRules}\n}`\n cssRuleSets.push(prefersMediaSelectors)\n }\n\n return cssRuleSets\n}\n\nconst darkSelector = '.t_dark'\nconst lightSelector = '.t_light'\nconst isBaseTheme = (x: string) =>\n x === darkSelector ||\n x === lightSelector ||\n x.startsWith('.t_dark ') ||\n x.startsWith('.t_light ')\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAE3B,uBAAuC;AACvC,4BAA2C;AAE3C,iCAAsC;AAE/B,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,QAAM,cAAwB,CAAC;AAG/B,QAAM,eAAe,WAAW,OAAO,UAAU,UAAU,OAAO;AAClE,QAAM,MAAM,IAAI;AAChB,MAAI,OAA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AG,0BAA0B;AAChD,UAAM,wBAAwB,+BAA+B;AAAA,IAC7D;AAAA,IACA;AAAA;AAEA,gBAAY,KAAK,qBAAqB;AAAA,EACxC;AAEA,SAAO;AACT;AAEA,MAAM,eAAe;AACrB,MAAM,gBAAgB;AACtB,MAAM,cAAc,CAAC,MACnB,MAAM,gBACN,MAAM,iBACN,EAAE,WAAW,UAAU,KACvB,EAAE,WAAW,WAAW;",
6
6
  "names": []
7
7
  }
@@ -49,21 +49,19 @@ function proxyThemeToParents(themeName, theme, themes) {
49
49
  cur.push(part);
50
50
  return cur.join("_");
51
51
  });
52
- const len = parents.length;
52
+ const numParents = parents.length;
53
53
  return new Proxy(theme, {
54
54
  get(target, key) {
55
- if (key === import_getThemeUnwrapped.GetThemeUnwrapped) {
55
+ if (key === import_getThemeUnwrapped.GetThemeUnwrapped)
56
56
  return theme;
57
- }
58
- if (!len || Reflect.has(target, key)) {
59
- return Reflect.get(target, key);
60
- }
61
- for (let i = len - 1; i >= 0; i--) {
62
- const parent = themes[parents[i]];
63
- if (!parent)
64
- continue;
65
- if (Reflect.has(parent, key)) {
66
- return Reflect.get(parent, key);
57
+ if (numParents && !Reflect.has(target, key)) {
58
+ for (let i = numParents - 1; i >= 0; i--) {
59
+ const parent = themes[parents[i]];
60
+ if (!parent)
61
+ continue;
62
+ if (Reflect.has(parent, key)) {
63
+ return Reflect.get(parent, key);
64
+ }
67
65
  }
68
66
  }
69
67
  return Reflect.get(target, key);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/themes.ts"],
4
- "sourcesContent": ["import { createVariable, isVariable } from '../createVariable.js'\nimport { GetThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { CreateTamaguiProps } from '../types.js'\n\n// mutates, freeze after\n// shared by createTamagui so extracted here\nexport function ensureThemeVariable(theme: any, key: string) {\n const val = theme[key]\n const themeKey = key\n if (!isVariable(val)) {\n theme[key] = createVariable({\n key: themeKey,\n name: themeKey,\n val,\n })\n } else {\n if (val.name !== themeKey) {\n // rename to theme name\n theme[key] = createVariable({\n key: val.name,\n name: themeKey,\n val: val.val,\n })\n }\n }\n}\n\nexport function proxyThemeToParents(\n themeName: string,\n theme: any,\n themes: CreateTamaguiProps['themes']\n) {\n // we could test if this is better as just a straight object spread or fancier proxy\n const cur: string[] = []\n // if theme is dark_blue_alt1_Button\n // this will be the parent names in order: ['dark', 'dark_blue', 'dark_blue_alt1\"]\n const parents = themeName\n .split('_')\n .slice(0, -1)\n .map((part) => {\n cur.push(part)\n return cur.join('_')\n })\n\n const len = parents.length\n\n // proxy fallback values to parent theme values\n return new Proxy(theme, {\n get(target, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (!len || Reflect.has(target, key)) {\n return Reflect.get(target, key)\n }\n // check parents\n for (let i = len - 1; i >= 0; i--) {\n const parent = themes[parents[i]]\n if (!parent) continue\n if (Reflect.has(parent, key)) {\n return Reflect.get(parent, key)\n }\n }\n return Reflect.get(target, key)\n },\n })\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA2C;AAC3C,+BAAkC;AAK3B,SAAS,oBAAoB,OAAY,KAAa;AAC3D,QAAM,MAAM,MAAM,GAAG;AACrB,QAAM,WAAW;AACjB,MAAI,KAAC,kCAAW,GAAG,GAAG;AACpB,UAAM,GAAG,QAAI,sCAAe;AAAA,MAC1B,KAAK;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,QAAI,IAAI,SAAS,UAAU;AAEzB,YAAM,GAAG,QAAI,sCAAe;AAAA,QAC1B,KAAK,IAAI;AAAA,QACT,MAAM;AAAA,QACN,KAAK,IAAI;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,oBACd,WACA,OACA,QACA;AAEA,QAAM,MAAgB,CAAC;AAGvB,QAAM,UAAU,UACb,MAAM,GAAG,EACT,MAAM,GAAG,EAAE,EACX,IAAI,CAAC,SAAS;AACb,QAAI,KAAK,IAAI;AACb,WAAO,IAAI,KAAK,GAAG;AAAA,EACrB,CAAC;AAEH,QAAM,MAAM,QAAQ;AAGpB,SAAO,IAAI,MAAM,OAAO;AAAA,IACtB,IAAI,QAAQ,KAAK;AACf,UAAI,QAAQ,4CAAmB;AAC7B,eAAO;AAAA,MACT;AACA,UAAI,CAAC,OAAO,QAAQ,IAAI,QAAQ,GAAG,GAAG;AACpC,eAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,MAChC;AAEA,eAAS,IAAI,MAAM,GAAG,KAAK,GAAG,KAAK;AACjC,cAAM,SAAS,OAAO,QAAQ,CAAC,CAAC;AAChC,YAAI,CAAC;AAAQ;AACb,YAAI,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAC5B,iBAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,QAChC;AAAA,MACF;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF,CAAC;AACH;",
4
+ "sourcesContent": ["import { createVariable, isVariable } from '../createVariable.js'\nimport { GetThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { CreateTamaguiProps } from '../types.js'\n\n// mutates, freeze after\n// shared by createTamagui so extracted here\nexport function ensureThemeVariable(theme: any, key: string) {\n const val = theme[key]\n const themeKey = key\n if (!isVariable(val)) {\n theme[key] = createVariable({\n key: themeKey,\n name: themeKey,\n val,\n })\n } else {\n if (val.name !== themeKey) {\n // rename to theme name\n theme[key] = createVariable({\n key: val.name,\n name: themeKey,\n val: val.val,\n })\n }\n }\n}\n\nexport function proxyThemeToParents(\n themeName: string,\n theme: any,\n themes: CreateTamaguiProps['themes']\n) {\n // we could test if this is better as just a straight object spread or fancier proxy\n const cur: string[] = []\n // if theme is dark_blue_alt1_Button\n // this will be the parent names in order: ['dark', 'dark_blue', 'dark_blue_alt1\"]\n const parents = themeName\n .split('_')\n .slice(0, -1)\n .map((part) => {\n cur.push(part)\n return cur.join('_')\n })\n\n const numParents = parents.length\n\n // proxy fallback values to parent theme values\n return new Proxy(theme, {\n get(target, key) {\n if (key === GetThemeUnwrapped) return theme\n if (numParents && !Reflect.has(target, key)) {\n // check parents\n for (let i = numParents - 1; i >= 0; i--) {\n const parent = themes[parents[i]]\n if (!parent) continue\n if (Reflect.has(parent, key)) {\n return Reflect.get(parent, key)\n }\n }\n }\n return Reflect.get(target, key)\n },\n })\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA2C;AAC3C,+BAAkC;AAK3B,SAAS,oBAAoB,OAAY,KAAa;AAC3D,QAAM,MAAM,MAAM,GAAG;AACrB,QAAM,WAAW;AACjB,MAAI,KAAC,kCAAW,GAAG,GAAG;AACpB,UAAM,GAAG,QAAI,sCAAe;AAAA,MAC1B,KAAK;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,QAAI,IAAI,SAAS,UAAU;AAEzB,YAAM,GAAG,QAAI,sCAAe;AAAA,QAC1B,KAAK,IAAI;AAAA,QACT,MAAM;AAAA,QACN,KAAK,IAAI;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,oBACd,WACA,OACA,QACA;AAEA,QAAM,MAAgB,CAAC;AAGvB,QAAM,UAAU,UACb,MAAM,GAAG,EACT,MAAM,GAAG,EAAE,EACX,IAAI,CAAC,SAAS;AACb,QAAI,KAAK,IAAI;AACb,WAAO,IAAI,KAAK,GAAG;AAAA,EACrB,CAAC;AAEH,QAAM,aAAa,QAAQ;AAG3B,SAAO,IAAI,MAAM,OAAO;AAAA,IACtB,IAAI,QAAQ,KAAK;AACf,UAAI,QAAQ;AAAmB,eAAO;AACtC,UAAI,cAAc,CAAC,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAE3C,iBAAS,IAAI,aAAa,GAAG,KAAK,GAAG,KAAK;AACxC,gBAAM,SAAS,OAAO,QAAQ,CAAC,CAAC;AAChC,cAAI,CAAC;AAAQ;AACb,cAAI,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAC5B,mBAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF,CAAC;AACH;",
6
6
  "names": []
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -64,6 +64,7 @@ __reExport(src_exports, require("./helpers/matchMedia.js"), module.exports);
64
64
  __reExport(src_exports, require("./helpers/proxyThemeVariables.js"), module.exports);
65
65
  __reExport(src_exports, require("./helpers/themeable.js"), module.exports);
66
66
  __reExport(src_exports, require("./helpers/withStaticProperties.js"), module.exports);
67
+ __reExport(src_exports, require("./helpers/normalizeColor.js"), module.exports);
67
68
  __reExport(src_exports, require("./contexts/ButtonNestingContext.js"), module.exports);
68
69
  __reExport(src_exports, require("./hooks/useId.js"), module.exports);
69
70
  __reExport(src_exports, require("./hooks/useIsTouchDevice.js"), module.exports);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './Tamagui.js'\nexport * from './createComponent.js'\nexport * from './createShorthands.js'\nexport * from './createTheme.js'\nexport * from './createTamagui.js'\nexport * from './createFont.js'\nexport * from './createTokens.js'\nexport * from './createVariable.js'\nexport * from './createVariables.js'\nexport * from './insertFont.js'\nexport * from './addTheme.js'\nexport * from './updateTheme.js'\nexport * from './styled.js'\nexport * from './types.js'\nexport * from './setupReactNative.js'\n\nexport { getConfig, getThemes, getTokens, onConfiguredOnce } from './config.js'\n\nexport * from './constants/constants.js'\n\nexport * from './helpers/useShallowSetState.js'\nexport * from './helpers/getVariantExtras.js'\nexport * from './helpers/getAnimationDriver.js'\nexport * from './helpers/getExpandedShorthands.js'\nexport * from './helpers/getSplitStyles.js'\nexport * from './helpers/getStylesAtomic.js'\nexport * from './helpers/pseudoDescriptors.js'\nexport * from './helpers/mergeProps.js'\nexport * from './helpers/expandStyles.js'\nexport * from './helpers/isTamaguiElement.js'\nexport * from './helpers/isTamaguiComponent.js'\nexport * from './helpers/matchMedia.js'\nexport * from './helpers/proxyThemeVariables.js'\nexport * from './helpers/themeable.js'\nexport * from './helpers/withStaticProperties.js'\n\nexport * from './contexts/ButtonNestingContext.js'\n\nexport * from './hooks/useId.js'\nexport * from './hooks/useIsTouchDevice.js'\n\nexport {\n configureMedia,\n getMedia,\n mediaState,\n useMedia,\n useMediaPropsActive,\n mediaObjectToString,\n mediaQueryConfig,\n} from './hooks/useMedia.js'\nexport * from './hooks/useTheme.js'\nexport * from './hooks/useThemeName.js'\nexport * from './hooks/useSafeRef.js'\nexport * from './hooks/useStyle.js'\n\nexport * from './views/Slot.js'\nexport * from './views/Stack.js'\nexport * from './views/Text.js'\nexport * from './contexts/TextAncestorContext.js'\nexport * from './views/Theme.js'\nexport * from './views/ThemeProvider.js'\nexport * from './views/FontLanguage.js'\nexport * from './views/TamaguiProvider.js'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-did-finish-ssr'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/compose-refs'\nexport * from '@tamagui/helpers'\nexport * from '@tamagui/constants'\n\nexport * from './setupHooks.js'\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,yBAAd;AACA,wBAAc,iCADd;AAEA,wBAAc,kCAFd;AAGA,wBAAc,6BAHd;AAIA,wBAAc,+BAJd;AAKA,wBAAc,4BALd;AAMA,wBAAc,8BANd;AAOA,wBAAc,gCAPd;AAQA,wBAAc,iCARd;AASA,wBAAc,4BATd;AAUA,wBAAc,0BAVd;AAWA,wBAAc,6BAXd;AAYA,wBAAc,wBAZd;AAaA,wBAAc,uBAbd;AAcA,wBAAc,kCAdd;AAgBA,oBAAkE;AAElE,wBAAc,qCAlBd;AAoBA,wBAAc,4CApBd;AAqBA,wBAAc,0CArBd;AAsBA,wBAAc,4CAtBd;AAuBA,wBAAc,+CAvBd;AAwBA,wBAAc,wCAxBd;AAyBA,wBAAc,yCAzBd;AA0BA,wBAAc,2CA1Bd;AA2BA,wBAAc,oCA3Bd;AA4BA,wBAAc,sCA5Bd;AA6BA,wBAAc,0CA7Bd;AA8BA,wBAAc,4CA9Bd;AA+BA,wBAAc,oCA/Bd;AAgCA,wBAAc,6CAhCd;AAiCA,wBAAc,mCAjCd;AAkCA,wBAAc,8CAlCd;AAoCA,wBAAc,+CApCd;AAsCA,wBAAc,6BAtCd;AAuCA,wBAAc,wCAvCd;AAyCA,sBAQO;AACP,wBAAc,gCAlDd;AAmDA,wBAAc,oCAnDd;AAoDA,wBAAc,kCApDd;AAqDA,wBAAc,gCArDd;AAuDA,wBAAc,4BAvDd;AAwDA,wBAAc,6BAxDd;AAyDA,wBAAc,4BAzDd;AA0DA,wBAAc,8CA1Dd;AA2DA,wBAAc,6BA3Dd;AA4DA,wBAAc,qCA5Dd;AA6DA,wBAAc,oCA7Dd;AA8DA,wBAAc,uCA9Dd;AAgEA,wBAAc,sCAhEd;AAiEA,wBAAc,wCAjEd;AAkEA,wBAAc,+BAlEd;AAmEA,wBAAc,kCAnEd;AAoEA,wBAAc,6BApEd;AAqEA,wBAAc,+BArEd;AAuEA,wBAAc,4BAvEd;",
4
+ "sourcesContent": ["export * from './Tamagui.js'\nexport * from './createComponent.js'\nexport * from './createShorthands.js'\nexport * from './createTheme.js'\nexport * from './createTamagui.js'\nexport * from './createFont.js'\nexport * from './createTokens.js'\nexport * from './createVariable.js'\nexport * from './createVariables.js'\nexport * from './insertFont.js'\nexport * from './addTheme.js'\nexport * from './updateTheme.js'\nexport * from './styled.js'\nexport * from './types.js'\nexport * from './setupReactNative.js'\n\nexport { getConfig, getThemes, getTokens, onConfiguredOnce } from './config.js'\n\nexport * from './constants/constants.js'\n\nexport * from './helpers/useShallowSetState.js'\nexport * from './helpers/getVariantExtras.js'\nexport * from './helpers/getAnimationDriver.js'\nexport * from './helpers/getExpandedShorthands.js'\nexport * from './helpers/getSplitStyles.js'\nexport * from './helpers/getStylesAtomic.js'\nexport * from './helpers/pseudoDescriptors.js'\nexport * from './helpers/mergeProps.js'\nexport * from './helpers/expandStyles.js'\nexport * from './helpers/isTamaguiElement.js'\nexport * from './helpers/isTamaguiComponent.js'\nexport * from './helpers/matchMedia.js'\nexport * from './helpers/proxyThemeVariables.js'\nexport * from './helpers/themeable.js'\nexport * from './helpers/withStaticProperties.js'\nexport * from './helpers/normalizeColor.js'\n\nexport * from './contexts/ButtonNestingContext.js'\n\nexport * from './hooks/useId.js'\nexport * from './hooks/useIsTouchDevice.js'\n\nexport {\n configureMedia,\n getMedia,\n mediaState,\n useMedia,\n useMediaPropsActive,\n mediaObjectToString,\n mediaQueryConfig,\n} from './hooks/useMedia.js'\nexport * from './hooks/useTheme.js'\nexport * from './hooks/useThemeName.js'\nexport * from './hooks/useSafeRef.js'\nexport * from './hooks/useStyle.js'\n\nexport * from './views/Slot.js'\nexport * from './views/Stack.js'\nexport * from './views/Text.js'\nexport * from './contexts/TextAncestorContext.js'\nexport * from './views/Theme.js'\nexport * from './views/ThemeProvider.js'\nexport * from './views/FontLanguage.js'\nexport * from './views/TamaguiProvider.js'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-did-finish-ssr'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/compose-refs'\nexport * from '@tamagui/helpers'\nexport * from '@tamagui/constants'\n\nexport * from './setupHooks.js'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,yBAAd;AACA,wBAAc,iCADd;AAEA,wBA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  }
112
112
  }
113
113
  function getNextThemeClassName(name, isInverting = false) {
114
- const next = `${THEME_CLASSNAME_PREFIX}${name}`;
114
+ const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`;
115
115
  if (isInverting) {
116
116
  return next + // ensure you invert to base dark as well as specific dark
117
117
  // ... logic should likely be elsewhere
118
- (next.includes("dark_") ? ` t_dark` : "") + (next.includes("light_") ? ` t_light` : "");
118
+ (next.includes("dark_") ? ` t_dark` : next.includes("light_") ? ` t_light` : "");
119
119
  }
120
120
  return next.replace("light_", "").replace("dark_", "");
121
121
  }
@@ -131,7 +131,8 @@ function getState(props, parentManager) {
131
131
  throw new Error("Cannot reset + set new name");
132
132
  }
133
133
  if (props.reset && !(parentManager == null ? void 0 : parentManager.parentManager)) {
134
- throw new Error("Cannot reset no grandparent exists");
134
+ console.warn("Cannot reset no grandparent exists");
135
+ return null;
135
136
  }
136
137
  let result = null;
137
138
  const nextName = props.reset ? ((_b = (_a = parentManager == null ? void 0 : parentManager.parentManager) == null ? void 0 : _a.state) == null ? void 0 : _b.name) || "" : props.name || "";
@@ -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\nexport class ThemeManager {\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManager?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManager === 'root') {\n this.updateState(props, false)\n return\n }\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n console.trace()\n throw new Error(`No parent manager given`)\n }\n throw `\u274C`\n }\n // copy over listeners\n this.themeListeners = parentManager.themeListeners\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n if (parentManager) {\n this.parentManager = parentManager\n }\n const updatedState = this.getStateIfChanged(props)\n if (updatedState) {\n this.state = updatedState\n return\n }\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n notify = true\n ) {\n const shouldFlush = (() => {\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.state = nextState\n return true\n }\n })()\n if (shouldFlush) {\n // reset any derived state\n this._allKeys = null\n notify && this.notify()\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) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, isInverting = false) {\n const next = `${THEME_CLASSNAME_PREFIX}${name}`\n if (isInverting) {\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` : '') +\n (next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nconst cache = new WeakMap<ThemeProps, [ThemeManager, ThemeManagerState | null]>()\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const cached = cache.get(props)\n if (cached && cached[0] === parentManager) {\n return cached[1]\n }\n\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n if (props.reset && !parentManager?.parentManager) {\n throw new Error('Cannot reset no grandparent exists')\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 isParentAComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentAComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentAComponentTheme\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 // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') [ console.groupCollapsed('ThemeManager.getState()', props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme }), console.trace(), console.groupEnd() ]\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 potentials.push(\n `${prefix.slice(\n 0,\n prefix.indexOf(THEME_NAME_SEPARATOR)\n )}_${nextName}_${componentName}`\n )\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 // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose')\n console.log('getState found', found, 'from', potentials, 'parentName', parentName)\n\n if (found) {\n // optimization return null if not changed\n if (found === parentName) {\n break\n }\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props.inverse),\n parentName,\n }\n break\n }\n }\n\n if (parentManager) {\n cache.set(props, [parentManager, result])\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"],
5
- "mappings": "AAAA,SAAS,WAAW,iBAAiB;AACrC,SAAS,wBAAwB,4BAA4B;AAC7D,SAAS,yBAAyB;AAoBlC,MA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OAAO;AAET,UAAI,UAAU,YAAY;AACxB;AAAA,MACF;AACA,eAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO,kBAAkB,OAAO,KAAK,CAAC;AAAA,QACtC,WAAW,sBAAsB,OAAO,MAAM,OAAO;AAAA,QACrD;AAAA,MACF;AACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,IAAI,OAAO,CAAC,eAAe,MAAM,CAAC;AAAA,EAC1C;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;",
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\nexport class ThemeManager {\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManager?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManager === 'root') {\n this.updateState(props, false)\n return\n }\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n console.trace()\n throw new Error(`No parent manager given`)\n }\n throw `\u274C`\n }\n // copy over listeners\n this.themeListeners = parentManager.themeListeners\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n if (parentManager) {\n this.parentManager = parentManager\n }\n const updatedState = this.getStateIfChanged(props)\n if (updatedState) {\n this.state = updatedState\n return\n }\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n notify = true\n ) {\n const shouldFlush = (() => {\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.state = nextState\n return true\n }\n })()\n if (shouldFlush) {\n // reset any derived state\n this._allKeys = null\n notify && this.notify()\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) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, isInverting = false) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (isInverting) {\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\nconst cache = new WeakMap<ThemeProps, [ThemeManager, ThemeManagerState | null]>()\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const cached = cache.get(props)\n if (cached && cached[0] === parentManager) {\n return cached[1]\n }\n\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n if (props.reset && !parentManager?.parentManager) {\n console.warn('Cannot reset no grandparent exists')\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 isParentAComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentAComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentAComponentTheme\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 // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') [ console.groupCollapsed('ThemeManager.getState()', props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme }), console.trace(), console.groupEnd() ]\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 potentials.push(\n `${prefix.slice(\n 0,\n prefix.indexOf(THEME_NAME_SEPARATOR)\n )}_${nextName}_${componentName}`\n )\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 // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose')\n console.log('getState found', found, 'from', potentials, 'parentName', parentName)\n\n if (found) {\n // optimization return null if not changed\n if (found === parentName) {\n break\n }\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props.inverse),\n parentName,\n }\n break\n }\n }\n\n if (parentManager) {\n cache.set(props, [parentManager, result])\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"],
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;AAEO,MAAM,aAAa;AAAA,EAKxB,YACS,QAAoB,CAAC,GAC5B,eACA;AAFO;AALT,0BAAiB,oBAAI,IAAmB;AACxC,yBAAqC;AACrC,iBAA2B;AA2F3B,oBAA+B;AArF7B,QAAI,kBAAkB,QAAQ;AAC5B,W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T;AAEA,MAAM,mBAAmB,CAAC,cAAsB;AAC9C,SAAO,UAAU,WAAW,OAAO,IAC/B,UAAU,QAAQ,UAAU,MAAM,IAClC,UAAU,QAAQ,SAAS,OAAO;AACxC;",
6
6
  "names": ["lastSegment"]
7
7
  }
@@ -111,11 +111,11 @@ class ThemeManager {
111
111
  }
112
112
  }
113
113
  function getNextThemeClassName(name, isInverting = false) {
114
- const next = `${THEME_CLASSNAME_PREFIX}${name}`;
114
+ const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`;
115
115
  if (isInverting) {
116
116
  return next + // ensure you invert to base dark as well as specific dark
117
117
  // ... logic should likely be elsewhere
118
- (next.includes("dark_") ? ` t_dark` : "") + (next.includes("light_") ? ` t_light` : "");
118
+ (next.includes("dark_") ? ` t_dark` : next.includes("light_") ? ` t_light` : "");
119
119
  }
120
120
  return next.replace("light_", "").replace("dark_", "");
121
121
  }
@@ -131,7 +131,8 @@ function getState(props, parentManager) {
131
131
  throw new Error("Cannot reset + set new name");
132
132
  }
133
133
  if (props.reset && !(parentManager == null ? void 0 : parentManager.parentManager)) {
134
- throw new Error("Cannot reset no grandparent exists");
134
+ console.warn("Cannot reset no grandparent exists");
135
+ return null;
135
136
  }
136
137
  let result = null;
137
138
  const nextName = props.reset ? ((_b = (_a = parentManager == null ? void 0 : parentManager.parentManager) == null ? void 0 : _a.state) == null ? void 0 : _b.name) || "" : props.name || "";
@@ -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\nexport class ThemeManager {\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManager?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManager === 'root') {\n this.updateState(props, false)\n return\n }\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n console.trace()\n throw new Error(`No parent manager given`)\n }\n throw `\u274C`\n }\n // copy over listeners\n this.themeListeners = parentManager.themeListeners\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n if (parentManager) {\n this.parentManager = parentManager\n }\n const updatedState = this.getStateIfChanged(props)\n if (updatedState) {\n this.state = updatedState\n return\n }\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n notify = true\n ) {\n const shouldFlush = (() => {\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.state = nextState\n return true\n }\n })()\n if (shouldFlush) {\n // reset any derived state\n this._allKeys = null\n notify && this.notify()\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) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, isInverting = false) {\n const next = `${THEME_CLASSNAME_PREFIX}${name}`\n if (isInverting) {\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` : '') +\n (next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nconst cache = new WeakMap<ThemeProps, [ThemeManager, ThemeManagerState | null]>()\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const cached = cache.get(props)\n if (cached && cached[0] === parentManager) {\n return cached[1]\n }\n\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n if (props.reset && !parentManager?.parentManager) {\n throw new Error('Cannot reset no grandparent exists')\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 isParentAComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentAComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentAComponentTheme\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 // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') [ console.groupCollapsed('ThemeManager.getState()', props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme }), console.trace(), console.groupEnd() ]\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 potentials.push(\n `${prefix.slice(\n 0,\n prefix.indexOf(THEME_NAME_SEPARATOR)\n )}_${nextName}_${componentName}`\n )\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 // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose')\n console.log('getState found', found, 'from', potentials, 'parentName', parentName)\n\n if (found) {\n // optimization return null if not changed\n if (found === parentName) {\n break\n }\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props.inverse),\n parentName,\n }\n break\n }\n }\n\n if (parentManager) {\n cache.set(props, [parentManager, result])\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"],
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;AAEO,MAAM,aAAa;AAAA,EAKxB,YACS,QAAoB,CAAC,GAC5B,eACA;AAFO;AALT,0BAAiB,oBAAI,IAAmB;AACxC,yBAAqC;AACrC,iBAA2B;AA2F3B,oBAA+B;AArF7B,QAAI,kBAAkB,QAAQ;AAC5B,WAAK,YAAY,OAAO,KAAK;AAC7B;AAAA,IACF;AACA,QAAI,CAAC,eAAe;AAClB,UAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,gBAAQ,MAAM;AACd,cAAM,IAAI,MAAM,yBAAyB;AAAA,MAC3C;AACA,YAAM;AAAA,IACR;AAEA,SAAK,iBAAiB,cAAc;AAGpC,QAAI,wBAAwB,KAAK,GAAG;AAClC,aAAO;AAAA,IACT;AACA,QAAI,eAAe;AACjB,WAAK,gBAAgB;AAAA,IACvB;AACA,UAAM,eAAe,KAAK,kBAAkB,KAAK;AACjD,QAAI,cAAc;AAChB,WAAK,QAAQ;AACb;AAAA,IACF;AACA,WAAO,iBAAiB;AAAA,EAC1B;AAAA,EAEA,YACE,QAAmD,KAAK,SAAS,CAAC,GAClE,SAAS,MACT;AACA,UAAM,eAAe,MAAM;AACzB,UAAI,MAAM,YAAY;AACpB,aAAK,MAAM,QAAQ,MAAM;AACzB,aAAK,MAAM,OAAO,MAAM,QAAQ;AAChC,eAAO;AAAA,MACT;AACA,YAAM,YAAY,KAAK,kBAAkB,KAAK;AAC9C,UAAI,WAAW;AACb,aAAK,QAAQ;AACb,eA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AAA,MAC7D;AAAA,IACF;AAEA,UAAM,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,MAAM;AAGhD,QAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAC5D,cAAQ,IAAI,kBAAkB,OAAO,QAAQ,YAAY,cAAc,UAAU;AAEnF,QAAI,OAAO;AAET,UAAI,UAAU,YAAY;AACxB;AAAA,MACF;AACA,eAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO,kBAAkB,OAAO,KAAK,CAAC;AAAA,QACtC,WAAW,sBAAsB,OAAO,MAAM,OAAO;AAAA,QACrD;AAAA,MACF;AACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,eAAe;AACjB,UAAM,IAAI,OAAO,CAAC,eAAe,MAAM,CAAC;AAAA,EAC1C;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;",
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\nexport class ThemeManager {\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManager?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManager === 'root') {\n this.updateState(props, false)\n return\n }\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n console.trace()\n throw new Error(`No parent manager given`)\n }\n throw `\u274C`\n }\n // copy over listeners\n this.themeListeners = parentManager.themeListeners\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n if (parentManager) {\n this.parentManager = parentManager\n }\n const updatedState = this.getStateIfChanged(props)\n if (updatedState) {\n this.state = updatedState\n return\n }\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n notify = true\n ) {\n const shouldFlush = (() => {\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.state = nextState\n return true\n }\n })()\n if (shouldFlush) {\n // reset any derived state\n this._allKeys = null\n notify && this.notify()\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) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, isInverting = false) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (isInverting) {\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\nconst cache = new WeakMap<ThemeProps, [ThemeManager, ThemeManagerState | null]>()\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const cached = cache.get(props)\n if (cached && cached[0] === parentManager) {\n return cached[1]\n }\n\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n if (props.reset && !parentManager?.parentManager) {\n console.warn('Cannot reset no grandparent exists')\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 isParentAComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentAComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentAComponentTheme\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 // prettier-ignore\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') [ console.groupCollapsed('ThemeManager.getState()', props, { parentName, parentBaseTheme, base, min, max, isParentAComponentTheme }), console.trace(), console.groupEnd() ]\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 potentials.push(\n `${prefix.slice(\n 0,\n prefix.indexOf(THEME_NAME_SEPARATOR)\n )}_${nextName}_${componentName}`\n )\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 // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose')\n console.log('getState found', found, 'from', potentials, 'parentName', parentName)\n\n if (found) {\n // optimization return null if not changed\n if (found === parentName) {\n break\n }\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props.inverse),\n parentName,\n }\n break\n }\n }\n\n if (parentManager) {\n cache.set(props, [parentManager, result])\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"],
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,iBAAi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