@pyreon/rocketstyle 0.11.2 → 0.11.3

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/lib/index.js CHANGED
@@ -201,20 +201,33 @@ const createLocalProvider = (WrappedComponent) => {
201
201
  //#region src/hooks/useTheme.ts
202
202
  /**
203
203
  * Retrieves the current theme object and resolved mode from context.
204
- * Supports mode inversion so nested components can flip between
205
- * light and dark without a new provider.
206
204
  *
207
- * In Pyreon, components run once no useMemo needed.
205
+ * Returns an object with getter properties so that mode/isDark/isLight
206
+ * are evaluated lazily on each access. This supports reactive mode
207
+ * switching via PyreonUI — when PyreonUI provides `get mode()` getters,
208
+ * rocketstyle picks up changes on every styled component re-evaluation.
209
+ *
210
+ * Without getters, destructuring would capture the mode value once at
211
+ * setup time, making theme switching permanently broken.
208
212
  */
209
213
  const useThemeAttrs = ({ inversed }) => {
210
- const { theme = {}, mode: ctxMode = "light", isDark: ctxDark } = useContext(context) || {};
211
- const mode = inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode;
212
- const isDark = inversed ? !ctxDark : ctxDark;
214
+ const ctx = useContext(context) || {};
213
215
  return {
214
- theme,
215
- mode,
216
- isDark,
217
- isLight: !isDark
216
+ get theme() {
217
+ return ctx.theme ?? {};
218
+ },
219
+ get mode() {
220
+ const ctxMode = ctx.mode ?? "light";
221
+ return inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode;
222
+ },
223
+ get isDark() {
224
+ const ctxDark = ctx.isDark ?? false;
225
+ return inversed ? !ctxDark : ctxDark;
226
+ },
227
+ get isLight() {
228
+ const ctxDark = ctx.isDark ?? false;
229
+ return !(inversed ? !ctxDark : ctxDark);
230
+ }
218
231
  };
219
232
  };
220
233
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyreon/rocketstyle",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/pyreon/pyreon",
@@ -44,13 +44,13 @@
44
44
  "typecheck": "tsc --noEmit"
45
45
  },
46
46
  "peerDependencies": {
47
- "@pyreon/core": "^0.11.2",
48
- "@pyreon/reactivity": "^0.11.2",
49
- "@pyreon/ui-core": "^0.11.2",
50
- "@pyreon/styler": "^0.11.2"
47
+ "@pyreon/core": "^0.11.3",
48
+ "@pyreon/reactivity": "^0.11.3",
49
+ "@pyreon/ui-core": "^0.11.3",
50
+ "@pyreon/styler": "^0.11.3"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@vitus-labs/tools-rolldown": "^1.15.3",
54
- "@pyreon/typescript": "^0.11.2"
54
+ "@pyreon/typescript": "^0.11.3"
55
55
  }
56
56
  }
@@ -14,23 +14,38 @@ type UseThemeAttrs = ({ inversed }: { inversed?: boolean | undefined }) => Conte
14
14
 
15
15
  /**
16
16
  * Retrieves the current theme object and resolved mode from context.
17
- * Supports mode inversion so nested components can flip between
18
- * light and dark without a new provider.
19
17
  *
20
- * In Pyreon, components run once no useMemo needed.
18
+ * Returns an object with getter properties so that mode/isDark/isLight
19
+ * are evaluated lazily on each access. This supports reactive mode
20
+ * switching via PyreonUI — when PyreonUI provides `get mode()` getters,
21
+ * rocketstyle picks up changes on every styled component re-evaluation.
22
+ *
23
+ * Without getters, destructuring would capture the mode value once at
24
+ * setup time, making theme switching permanently broken.
21
25
  */
22
26
  const useThemeAttrs: UseThemeAttrs = ({ inversed }) => {
23
- const {
24
- theme = {},
25
- mode: ctxMode = "light",
26
- isDark: ctxDark,
27
- } = useContext<Context>(context) || {}
28
-
29
- const mode = inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode
30
- const isDark = inversed ? !ctxDark : ctxDark
31
- const isLight = !isDark
27
+ // Keep the context object reference — read its properties lazily via getters.
28
+ // PyreonUI provides { get mode() {...} } so each access re-evaluates.
29
+ const ctx = useContext<Context>(context) || ({} as Partial<Context>)
32
30
 
33
- return { theme, mode, isDark, isLight }
31
+ return {
32
+ get theme() {
33
+ return ctx.theme ?? ({} as Record<string, unknown>)
34
+ },
35
+ get mode() {
36
+ const ctxMode = ctx.mode ?? "light"
37
+ return inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode
38
+ },
39
+ get isDark() {
40
+ const ctxDark = ctx.isDark ?? false
41
+ return inversed ? !ctxDark : ctxDark
42
+ },
43
+ get isLight() {
44
+ const ctxDark = ctx.isDark ?? false
45
+ const isDark = inversed ? !ctxDark : ctxDark
46
+ return !isDark
47
+ },
48
+ }
34
49
  }
35
50
 
36
51
  export default useThemeAttrs