@rootnative/core 0.0.0-alpha.3 → 0.0.0-alpha.30

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/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- import { T as Theme, a as TopAppBarTokens, B as BaseTheme, M as Motion, S as Shape } from './types-C8j9GvU_.mjs';
2
- export { C as Colors, E as Elevation, b as ElevationLevel, F as FontWeight, c as MaterialTheme, d as MotionSpring, e as ShadowOffset, f as Spacing, g as StateLayer, h as TextStyle, i as Typography } from './types-C8j9GvU_.mjs';
3
- import { TransitionConfig, NamedTransitions } from '@rootnative/inertia';
1
+ import { T as Theme, a as TopAppBarTokens, B as BaseTheme, M as Motion, S as Shape } from './types-BQpoSlhx.mjs';
2
+ export { C as Colors, E as Elevation, b as ElevationLevel, F as FontWeight, c as MaterialTheme, d as MotionSpring, e as ShadowOffset, f as Spacing, g as StateLayer, h as Typography, i as TypographyToken } from './types-BQpoSlhx.mjs';
3
+ import { TransitionConfig, NamedTransitions, MotionConfigValue } from '@rootnative/inertia';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
  import * as React from 'react';
6
+ import { ScaledSize } from 'react-native';
6
7
 
7
8
  declare const lightTheme: Theme;
8
9
 
@@ -84,19 +85,141 @@ interface IconRenderProps {
84
85
  * etc. without forking components.
85
86
  */
86
87
  type IconResolver = (name: string, props: IconRenderProps) => React.ReactNode;
87
- declare const IconResolverContext: React.Context<IconResolver | null>;
88
+ /**
89
+ * Anything a component will accept for an icon prop:
90
+ *
91
+ * - **string** — a name resolved via the `iconResolver` registered on
92
+ * `ThemeProvider`. Renders nothing, with one warning, when no
93
+ * resolver is set.
94
+ * - **ReactElement** — a pre-rendered icon. The caller is responsible for
95
+ * passing size and color; the component will not override them.
96
+ * - **(props) => ReactNode** — a render function that receives the
97
+ * component's resolved size and color. Useful for plugging in Lucide,
98
+ * SF Symbols, or custom SVGs without losing theme integration.
99
+ */
100
+ type IconSource = string | React.ReactElement | ((props: IconRenderProps) => React.ReactNode);
88
101
 
102
+ /**
103
+ * What the app asks for. `'system'` follows the OS setting and keeps
104
+ * following it as the OS changes; `'light'` / `'dark'` pin the scheme.
105
+ */
106
+ type ThemeMode = 'system' | 'light' | 'dark';
107
+ /** What the app actually renders. `'system'` is always resolved away. */
108
+ type ColorScheme = 'light' | 'dark';
109
+ /**
110
+ * Persists the user's mode choice across launches. Deliberately structural
111
+ * rather than a dependency on any one storage library: pass an
112
+ * AsyncStorage-shaped object, MMKV, `localStorage`, SecureStore, or your own
113
+ * wrapper. `@rootnative/core` takes no storage dependency of its own.
114
+ *
115
+ * Both methods may be sync or async — the provider awaits either.
116
+ *
117
+ * @example
118
+ * import AsyncStorage from '@react-native-async-storage/async-storage'
119
+ *
120
+ * <ThemeProvider theme={{ light, dark }} storage={AsyncStorage}>
121
+ */
122
+ interface ThemeModeStorage {
123
+ getItem: (key: string) => string | null | Promise<string | null>;
124
+ setItem: (key: string, value: string) => unknown | Promise<unknown>;
125
+ }
126
+ interface ThemeModeContextValue {
127
+ /** The requested mode, including `'system'`. */
128
+ mode: ThemeMode;
129
+ /**
130
+ * The resolved scheme actually in use. `mode: 'system'` resolves this from
131
+ * the OS; `'light'` / `'dark'` pass straight through. Use this to sync
132
+ * anything outside the theme — most commonly the status bar.
133
+ */
134
+ scheme: ColorScheme;
135
+ /** Sets the mode, and persists it when a `storage` is configured. */
136
+ setMode: (mode: ThemeMode) => void;
137
+ /**
138
+ * `false` until a persisted mode has been read back from `storage`. Always
139
+ * `true` when no `storage` is configured, since there is nothing to wait
140
+ * for. Gate a splash screen on this to avoid a light-to-dark flash on
141
+ * launch.
142
+ */
143
+ isReady: boolean;
144
+ }
145
+
146
+ /**
147
+ * A light/dark pair. Matches what `createMaterialTheme()` returns, so its
148
+ * result can be renamed straight into the prop:
149
+ * `const { lightTheme: light, darkTheme: dark } = createMaterialTheme(seed)`.
150
+ */
151
+ interface ThemePair {
152
+ light: BaseTheme;
153
+ dark: BaseTheme;
154
+ }
89
155
  interface ThemeProviderProps {
90
156
  /**
91
157
  * Theme object to provide to all child components via context.
92
158
  * Accepts any theme extending `BaseTheme` — Material, Apple, or custom.
159
+ *
160
+ * Pass a `{ light, dark }` pair to enable light/dark switching: the provider
161
+ * then resolves which one to use from `mode` plus the OS setting, and
162
+ * `useThemeMode()` becomes available to descendants.
163
+ *
93
164
  * @default lightTheme (Material Design 3)
94
165
  */
95
- theme?: BaseTheme;
166
+ theme?: BaseTheme | ThemePair;
167
+ /**
168
+ * Which theme of the pair to use. `'system'` follows the OS and keeps
169
+ * following it; `'light'` / `'dark'` pin it. Ignored when `theme` is a
170
+ * single theme.
171
+ *
172
+ * Leave uncontrolled (the default) and drive it with `setMode()` from
173
+ * `useThemeMode()`. Pass it to control the mode from your own state — the
174
+ * provider then never changes it on its own, so pair it with `onModeChange`.
175
+ *
176
+ * On a static web export, `'system'` renders light on the server and while
177
+ * the client hydrates, then switches to the OS scheme on the render after
178
+ * hydration. The server cannot know the scheme, so a dark-scheme reader sees
179
+ * the light theme until hydration ends. `schemeGuardCss` from
180
+ * `@rootnative/core/static-export` hides that light paint.
181
+ *
182
+ * A nested provider with a pair, under a parent provider with a pair,
183
+ * follows the mode of the parent when it gets none of `mode`, `defaultMode`
184
+ * and `storage`. Its `setMode()` then sets the mode of the parent.
185
+ *
186
+ * @default 'system'
187
+ */
188
+ mode?: ThemeMode;
189
+ /**
190
+ * Initial mode for the uncontrolled case. A persisted value from `storage`
191
+ * wins over this once it loads. On a nested provider, setting it gives the
192
+ * provider a mode of its own.
193
+ *
194
+ * @default 'system'
195
+ */
196
+ defaultMode?: ThemeMode;
197
+ /** Called whenever `setMode()` runs, controlled or not. */
198
+ onModeChange?: (mode: ThemeMode) => void;
199
+ /**
200
+ * Persists the mode across launches. Any object with `getItem`/`setItem` —
201
+ * AsyncStorage, MMKV, `localStorage`. `@rootnative/core` takes no storage
202
+ * dependency of its own, so nothing is persisted unless you pass this.
203
+ *
204
+ * Ignored when `mode` is controlled: your own state is then the source of
205
+ * truth and persisting behind it would fight it.
206
+ *
207
+ * On a nested provider, setting it gives the provider a mode of its own.
208
+ * Every provider uses the same storage key, so a nested provider with
209
+ * `storage` overwrites the mode that the root provider stored.
210
+ *
211
+ * @example
212
+ * import AsyncStorage from '@react-native-async-storage/async-storage'
213
+ *
214
+ * <ThemeProvider theme={{ light, dark }} storage={AsyncStorage}>
215
+ */
216
+ storage?: ThemeModeStorage;
96
217
  /**
97
218
  * Resolves string icon names (e.g. `leadingIcon="check"`) to icon nodes.
98
219
  * Set this once at the app root to use SF Symbols, Lucide, custom SVGs,
99
- * etc. instead of the default `MaterialCommunityIcons`.
220
+ * etc. `mdiResolver` from `@rootnative/components/mdi` gives MaterialDesignIcons.
221
+ *
222
+ * A nested provider without it uses the resolver of its parent.
100
223
  *
101
224
  * @example
102
225
  * import { Check, ArrowRight } from 'lucide-react-native'
@@ -128,14 +251,34 @@ interface ThemeProviderProps {
128
251
  * </ThemeProvider>
129
252
  *
130
253
  * @example
254
+ * // Light/dark, following the OS
255
+ * import { ThemeProvider, lightTheme, darkTheme } from '@rootnative/core'
256
+ *
257
+ * <ThemeProvider theme={{ light: lightTheme, dark: darkTheme }}>
258
+ * <App />
259
+ * </ThemeProvider>
260
+ *
261
+ * @example
131
262
  * // Custom or Apple theme
132
263
  * import { ThemeProvider } from '@rootnative/core'
133
264
  *
134
265
  * <ThemeProvider theme={myTheme}>
135
266
  * <App />
136
267
  * </ThemeProvider>
268
+ *
269
+ * @example
270
+ * // A nested pair for one screen. It follows the mode and the icon resolver
271
+ * // of the root provider.
272
+ * const { lightTheme: light, darkTheme: dark } = createMaterialTheme(seed)
273
+ *
274
+ * <ThemeProvider theme={{ light, dark }}>
275
+ * <Screen />
276
+ * </ThemeProvider>
137
277
  */
138
- declare function ThemeProvider({ theme, iconResolver, children, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
278
+ declare function ThemeProvider({ theme, mode: controlledMode, defaultMode, onModeChange, storage, iconResolver, children, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
279
+
280
+ /** Storage key for the persisted mode. Namespaced to avoid app collisions. */
281
+ declare const THEME_MODE_STORAGE_KEY = "rootnative.theme-mode";
139
282
 
140
283
  /**
141
284
  * Returns the current theme from the nearest `ThemeProvider`.
@@ -154,13 +297,75 @@ declare function ThemeProvider({ theme, iconResolver, children, }: ThemeProvider
154
297
  */
155
298
  declare function useTheme<T extends BaseTheme = Theme>(): T;
156
299
 
300
+ /**
301
+ * Reads and controls the light/dark mode of the nearest `ThemeProvider`.
302
+ *
303
+ * Requires a provider configured with a theme *pair* — `theme={{ light, dark }}`.
304
+ * A provider given a single theme has no mode to report, so this throws rather
305
+ * than inventing one.
306
+ *
307
+ * @example
308
+ * const { mode, scheme, setMode } = useThemeMode()
309
+ *
310
+ * <StatusBar style={scheme === 'dark' ? 'light' : 'dark'} />
311
+ * <Button onPress={() => setMode(scheme === 'dark' ? 'light' : 'dark')} />
312
+ */
313
+ declare function useThemeMode(): ThemeModeContextValue;
314
+
157
315
  /**
158
316
  * Returns the icon resolver registered on the nearest `ThemeProvider`,
159
- * or `null` if none was provided. Components fall back to
160
- * `@expo/vector-icons/MaterialCommunityIcons` when no resolver is set.
317
+ * or `null` if none was provided. A string icon renders nothing and logs one
318
+ * warning when no resolver is set.
161
319
  */
162
320
  declare function useIconResolver(): IconResolver | null;
163
321
 
322
+ /**
323
+ * Everything a `ThemeProvider` gives its descendants, read at one place in
324
+ * the tree so that it can be provided again at another. Treat it as opaque:
325
+ * read it with `useThemeScope()` and hand it to `ThemeScopeProvider`.
326
+ */
327
+ interface ThemeScope {
328
+ /** The resolved theme at the call site. */
329
+ readonly theme: BaseTheme;
330
+ /** The mode value at the call site; `null` under a single-theme provider. */
331
+ readonly mode: ThemeModeContextValue | null;
332
+ /** The icon resolver at the call site; `null` when none is set. */
333
+ readonly iconResolver: IconResolver | null;
334
+ /** The merged motion config at the call site. */
335
+ readonly motion: MotionConfigValue;
336
+ }
337
+ /**
338
+ * Reads the theme, the mode, the icon resolver and the motion config of the
339
+ * nearest providers, as one value for `ThemeScopeProvider`.
340
+ *
341
+ * Use the pair when you render content at another place in the tree, for
342
+ * example through a portal. The content then reads the theme of the place
343
+ * where you wrote it, not the theme of the place where it renders.
344
+ * `@rootnative/components` does this in `Portal`, so every overlay follows
345
+ * the provider it is written under.
346
+ *
347
+ * @example
348
+ * function MyPortal({ children }) {
349
+ * const scope = useThemeScope()
350
+ * return createPortal(
351
+ * <ThemeScopeProvider scope={scope}>{children}</ThemeScopeProvider>,
352
+ * host,
353
+ * )
354
+ * }
355
+ */
356
+ declare function useThemeScope(): ThemeScope;
357
+ interface ThemeScopeProviderProps {
358
+ /** The value that `useThemeScope()` returned at the place to copy. */
359
+ scope: ThemeScope;
360
+ children: React.ReactNode;
361
+ }
362
+ /**
363
+ * Provides a `ThemeScope` to its descendants, as if the providers at the
364
+ * place that read it stood here. A `ThemeProvider` below it inherits from it
365
+ * the same way it inherits from a real parent provider.
366
+ */
367
+ declare function ThemeScopeProvider({ scope, children, }: ThemeScopeProviderProps): react_jsx_runtime.JSX.Element;
368
+
164
369
  /**
165
370
  * Material Design 3 window size classes.
166
371
  * @see https://m3.material.io/foundations/layout/applying-layout/window-size-classes
@@ -177,6 +382,30 @@ declare const breakpoints: {
177
382
  * Returns the current Material Design 3 window size class based on viewport width.
178
383
  * Reactively updates when the window is resized.
179
384
  *
385
+ * **Hydration-safe by construction.** A static export renders on a server with
386
+ * no DOM, where react-native-web's `Dimensions` is hard-wired to `width: 0`,
387
+ * so every breakpoint resolves to `compact` and that is what ships in the
388
+ * HTML. On the client `Dimensions` reports the real width immediately, so
389
+ * without care the first client render disagrees with the markup it is
390
+ * hydrating — and **React does not repair that**. Measured against React
391
+ * 19.2.3: a `className` / `style` mismatch is adopted from the server DOM,
392
+ * left on screen, and reported through *zero* recoverable errors. A tablet
393
+ * gets the phone layout, permanently, with no console signal.
394
+ *
395
+ * So this hook reports `compact` for as long as the client is hydrating,
396
+ * matching the markup exactly, and switches to the measured breakpoint on the
397
+ * re-render React schedules once hydration finishes. The correction is an
398
+ * ordinary update, which *does* patch the DOM. The guard lives in this
399
+ * package's `useWindowDimensions`, which this hook reads. Use that hook, not
400
+ * the `react-native` one, when a layout needs the raw width.
401
+ *
402
+ * **It costs nothing where there is no hydration.** On native, and on a
403
+ * single-page web build, `getServerSnapshot` is never called, so the measured
404
+ * breakpoint is returned from the first render with no extra pass. Consumers
405
+ * need no `useHydrated` gate of their own, and neither does `Grid`, which
406
+ * resolves a breakpoint map internally and gives a consumer nowhere to put
407
+ * one.
408
+ *
180
409
  * @example
181
410
  * const breakpoint = useBreakpoint()
182
411
  * const columns = breakpoint === 'compact' ? 2 : 4
@@ -195,6 +424,34 @@ type BreakpointValues<T> = Partial<Record<Breakpoint, T>> & Record<'compact', T>
195
424
  */
196
425
  declare function useBreakpointValue<T>(values: BreakpointValues<T>): T;
197
426
 
427
+ /**
428
+ * Returns the window size, the same as `useWindowDimensions` from
429
+ * `react-native`, but safe to use in a static web export.
430
+ *
431
+ * **Use this instead of the `react-native` hook for any value that reaches a
432
+ * style or the tree.** A static export (`web.output: 'static'`) renders on a
433
+ * server with no DOM, where react-native-web measures a 0 by 0 window. The
434
+ * client measures the real window on its first render, so the `react-native`
435
+ * hook disagrees with the markup it hydrates, and React 19 keeps the server's
436
+ * style with no error. A carousel slot sized from the width, or a hero height
437
+ * set as a fraction of it, then keeps the layout of a 0 wide window until the
438
+ * reader resizes the window.
439
+ *
440
+ * This hook returns the server's 0 by 0 window while the client hydrates, and
441
+ * the measured window on the re-render React schedules after hydration. That
442
+ * re-render is an ordinary update, which does patch the DOM. On native, and on
443
+ * a single-page web build, nothing hydrates, so the measured window comes back
444
+ * from the first render with no extra pass.
445
+ *
446
+ * `useBreakpoint` reads this hook, so a breakpoint and a raw width cannot
447
+ * disagree during hydration.
448
+ *
449
+ * @example
450
+ * const { width } = useWindowDimensions()
451
+ * const heroHeight = width * 0.56
452
+ */
453
+ declare function useWindowDimensions(): ScaledSize;
454
+
198
455
  /**
199
456
  * Material Design 3 preset — groups all MD3-specific theme values.
200
457
  *
@@ -211,4 +468,4 @@ declare const material: {
211
468
  readonly defaultTopAppBarTokens: TopAppBarTokens;
212
469
  };
213
470
 
214
- export { BaseTheme, type Breakpoint, type BreakpointValues, type IconRenderProps, type IconResolver, IconResolverContext, Motion, Shape, Theme, ThemeProvider, type ThemeProviderProps, TopAppBarTokens, applyRoundness, breakpoints, darkTheme, defaultTopAppBarTokens, defineTheme, lightTheme, material, motionTransitions, useBreakpoint, useBreakpointValue, useIconResolver, useTheme };
471
+ export { BaseTheme, type Breakpoint, type BreakpointValues, type ColorScheme, type IconRenderProps, type IconResolver, type IconSource, Motion, Shape, THEME_MODE_STORAGE_KEY, Theme, type ThemeMode, type ThemeModeContextValue, type ThemeModeStorage, type ThemePair, ThemeProvider, type ThemeProviderProps, type ThemeScope, ThemeScopeProvider, type ThemeScopeProviderProps, TopAppBarTokens, applyRoundness, breakpoints, darkTheme, defaultTopAppBarTokens, defineTheme, lightTheme, material, motionTransitions, useBreakpoint, useBreakpointValue, useIconResolver, useTheme, useThemeMode, useThemeScope, useWindowDimensions };
package/dist/index.mjs CHANGED
@@ -3,7 +3,12 @@ import {
3
3
  defaultTopAppBarTokens,
4
4
  defaultTypography,
5
5
  lightTheme
6
- } from "./chunk-QQ3ME6R7.mjs";
6
+ } from "./chunk-Y5CU4C2C.mjs";
7
+ import {
8
+ THEME_MODE_STORAGE_KEY,
9
+ THEME_READY_ATTRIBUTE
10
+ } from "./chunk-OK7DBCK4.mjs";
11
+ import "./chunk-Y6FXYEAI.mjs";
7
12
 
8
13
  // src/theme/dark.ts
9
14
  var darkTheme = {
@@ -210,7 +215,31 @@ function motionTransitions(motion) {
210
215
 
211
216
  // src/provider/ThemeProvider.tsx
212
217
  import { MotionConfig } from "@rootnative/inertia";
213
- import * as React3 from "react";
218
+ import * as React4 from "react";
219
+ import { useColorScheme } from "react-native";
220
+
221
+ // src/internal/useIsHydrating.ts
222
+ import { useSyncExternalStore } from "react";
223
+ var subscribeToNothing = () => () => {
224
+ };
225
+ var notHydrating = () => false;
226
+ var isHydratingOnServer = () => true;
227
+ function useIsHydrating() {
228
+ return useSyncExternalStore(
229
+ subscribeToNothing,
230
+ notHydrating,
231
+ isHydratingOnServer
232
+ );
233
+ }
234
+
235
+ // src/internal/useMarkThemeReady.ts
236
+ import { useEffect } from "react";
237
+ function useMarkThemeReady(isFinal) {
238
+ useEffect(() => {
239
+ if (!isFinal || typeof document === "undefined") return;
240
+ document.documentElement.setAttribute(THEME_READY_ATTRIBUTE, "");
241
+ }, [isFinal]);
242
+ }
214
243
 
215
244
  // src/provider/IconResolverContext.ts
216
245
  import * as React from "react";
@@ -222,35 +251,188 @@ var IconResolverContext = React.createContext(
222
251
  import * as React2 from "react";
223
252
  var ThemeContext = React2.createContext(lightTheme);
224
253
 
254
+ // src/provider/ThemeModeContext.ts
255
+ import * as React3 from "react";
256
+ var ThemeModeContext = React3.createContext(null);
257
+
225
258
  // src/provider/ThemeProvider.tsx
226
259
  import { jsx } from "react/jsx-runtime";
260
+ function isThemePair(theme) {
261
+ return !("colors" in theme);
262
+ }
263
+ function isThemeMode(value) {
264
+ return value === "system" || value === "light" || value === "dark";
265
+ }
227
266
  function ThemeProvider({
228
267
  theme,
268
+ mode: controlledMode,
269
+ defaultMode,
270
+ onModeChange,
271
+ storage,
229
272
  iconResolver,
230
273
  children
231
274
  }) {
232
- const resolvedTheme = theme != null ? theme : lightTheme;
233
- const transitions = React3.useMemo(
275
+ const pair = theme && isThemePair(theme) ? theme : null;
276
+ const parentModeValue = React4.useContext(ThemeModeContext);
277
+ const parentIconResolver = React4.useContext(IconResolverContext);
278
+ const inheritedMode = pair && controlledMode === void 0 && defaultMode === void 0 && storage === void 0 ? parentModeValue : null;
279
+ const measuredScheme = useColorScheme();
280
+ const isHydrating = useIsHydrating();
281
+ const systemScheme = isHydrating ? "light" : measuredScheme;
282
+ const [uncontrolledMode, setUncontrolledMode] = React4.useState(
283
+ defaultMode != null ? defaultMode : "system"
284
+ );
285
+ const isControlled = controlledMode !== void 0;
286
+ const ownMode = isControlled ? controlledMode : uncontrolledMode;
287
+ const [isReady, setIsReady] = React4.useState(
288
+ () => !storage || isControlled || !pair
289
+ );
290
+ const storageRef = React4.useRef(storage);
291
+ React4.useEffect(() => {
292
+ storageRef.current = storage;
293
+ });
294
+ const shouldLoad = Boolean(storage) && !isControlled && Boolean(pair);
295
+ React4.useEffect(() => {
296
+ if (!shouldLoad) {
297
+ setIsReady(true);
298
+ return;
299
+ }
300
+ let cancelled = false;
301
+ const load = async () => {
302
+ var _a;
303
+ try {
304
+ const stored = await ((_a = storageRef.current) == null ? void 0 : _a.getItem(THEME_MODE_STORAGE_KEY));
305
+ if (!cancelled && isThemeMode(stored)) {
306
+ setUncontrolledMode(stored);
307
+ }
308
+ } catch {
309
+ } finally {
310
+ if (!cancelled) {
311
+ setIsReady(true);
312
+ }
313
+ }
314
+ };
315
+ void load();
316
+ return () => {
317
+ cancelled = true;
318
+ };
319
+ }, [shouldLoad]);
320
+ const setParentMode = inheritedMode == null ? void 0 : inheritedMode.setMode;
321
+ const setMode = React4.useCallback(
322
+ (nextMode) => {
323
+ var _a;
324
+ if (setParentMode) {
325
+ setParentMode(nextMode);
326
+ onModeChange == null ? void 0 : onModeChange(nextMode);
327
+ return;
328
+ }
329
+ if (!isControlled) {
330
+ setUncontrolledMode(nextMode);
331
+ }
332
+ onModeChange == null ? void 0 : onModeChange(nextMode);
333
+ if (!isControlled) {
334
+ try {
335
+ const result = (_a = storageRef.current) == null ? void 0 : _a.setItem(
336
+ THEME_MODE_STORAGE_KEY,
337
+ nextMode
338
+ );
339
+ void Promise.resolve(result).catch(() => {
340
+ });
341
+ } catch {
342
+ }
343
+ }
344
+ },
345
+ [setParentMode, isControlled, onModeChange]
346
+ );
347
+ const ownScheme = ownMode === "system" ? systemScheme === "dark" ? "dark" : "light" : ownMode;
348
+ const mode = inheritedMode ? inheritedMode.mode : ownMode;
349
+ const scheme = inheritedMode ? inheritedMode.scheme : ownScheme;
350
+ const ready = inheritedMode ? inheritedMode.isReady : isReady;
351
+ useMarkThemeReady(!isHydrating && ready);
352
+ const resolvedTheme = pair ? scheme === "dark" ? pair.dark : pair.light : theme != null ? theme : lightTheme;
353
+ const modeValue = React4.useMemo(
354
+ () => pair ? { mode, scheme, setMode, isReady: ready } : null,
355
+ [pair, mode, scheme, setMode, ready]
356
+ );
357
+ const transitions = React4.useMemo(
234
358
  () => motionTransitions(resolvedTheme.motion),
235
359
  [resolvedTheme.motion]
236
360
  );
237
- return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: resolvedTheme, children: /* @__PURE__ */ jsx(IconResolverContext.Provider, { value: iconResolver != null ? iconResolver : null, children: /* @__PURE__ */ jsx(MotionConfig, { transitions, children }) }) });
361
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: resolvedTheme, children: /* @__PURE__ */ jsx(ThemeModeContext.Provider, { value: modeValue, children: /* @__PURE__ */ jsx(
362
+ IconResolverContext.Provider,
363
+ {
364
+ value: iconResolver != null ? iconResolver : parentIconResolver,
365
+ children: /* @__PURE__ */ jsx(MotionConfig, { transitions, children })
366
+ }
367
+ ) }) });
238
368
  }
239
369
 
240
370
  // src/provider/useTheme.ts
241
- import { useContext } from "react";
371
+ import { useContext as useContext2 } from "react";
242
372
  function useTheme() {
243
- return useContext(ThemeContext);
373
+ return useContext2(ThemeContext);
374
+ }
375
+
376
+ // src/provider/useThemeMode.ts
377
+ import { useContext as useContext3 } from "react";
378
+ function useThemeMode() {
379
+ const value = useContext3(ThemeModeContext);
380
+ if (value === null) {
381
+ throw new Error(
382
+ "useThemeMode() requires a <ThemeProvider theme={{ light, dark }}>. A provider with a single theme has no light/dark mode to control."
383
+ );
384
+ }
385
+ return value;
244
386
  }
245
387
 
246
388
  // src/provider/useIconResolver.ts
247
- import { useContext as useContext2 } from "react";
389
+ import { useContext as useContext4 } from "react";
248
390
  function useIconResolver() {
249
- return useContext2(IconResolverContext);
391
+ return useContext4(IconResolverContext);
392
+ }
393
+
394
+ // src/provider/ThemeScope.tsx
395
+ import { MotionConfig as MotionConfig2, useMotionConfig } from "@rootnative/inertia";
396
+ import * as React5 from "react";
397
+ import { jsx as jsx2 } from "react/jsx-runtime";
398
+ function useThemeScope() {
399
+ const theme = React5.useContext(ThemeContext);
400
+ const mode = React5.useContext(ThemeModeContext);
401
+ const iconResolver = React5.useContext(IconResolverContext);
402
+ const motion = useMotionConfig();
403
+ return React5.useMemo(
404
+ () => ({ theme, mode, iconResolver, motion }),
405
+ [theme, mode, iconResolver, motion]
406
+ );
407
+ }
408
+ function ThemeScopeProvider({
409
+ scope,
410
+ children
411
+ }) {
412
+ return /* @__PURE__ */ jsx2(ThemeContext.Provider, { value: scope.theme, children: /* @__PURE__ */ jsx2(ThemeModeContext.Provider, { value: scope.mode, children: /* @__PURE__ */ jsx2(IconResolverContext.Provider, { value: scope.iconResolver, children: /* @__PURE__ */ jsx2(
413
+ MotionConfig2,
414
+ {
415
+ reducedMotion: scope.motion.reducedMotion,
416
+ transitions: scope.motion.transitions,
417
+ children
418
+ }
419
+ ) }) }) });
420
+ }
421
+
422
+ // src/responsive/useWindowDimensions.ts
423
+ import { useWindowDimensions as useMeasuredWindowDimensions } from "react-native";
424
+ var SERVER_WINDOW = Object.freeze({
425
+ width: 0,
426
+ height: 0,
427
+ scale: 1,
428
+ fontScale: 1
429
+ });
430
+ function useWindowDimensions() {
431
+ const measured = useMeasuredWindowDimensions();
432
+ return useIsHydrating() ? SERVER_WINDOW : measured;
250
433
  }
251
434
 
252
435
  // src/responsive/useBreakpoint.ts
253
- import { useWindowDimensions } from "react-native";
254
436
  var breakpoints = {
255
437
  compact: 0,
256
438
  medium: 600,
@@ -295,8 +477,9 @@ var material = {
295
477
  defaultTopAppBarTokens
296
478
  };
297
479
  export {
298
- IconResolverContext,
480
+ THEME_MODE_STORAGE_KEY,
299
481
  ThemeProvider,
482
+ ThemeScopeProvider,
300
483
  applyRoundness,
301
484
  breakpoints,
302
485
  darkTheme,
@@ -308,5 +491,8 @@ export {
308
491
  useBreakpoint,
309
492
  useBreakpointValue,
310
493
  useIconResolver,
311
- useTheme
494
+ useTheme,
495
+ useThemeMode,
496
+ useThemeScope,
497
+ useWindowDimensions
312
498
  };