@oxy.so/bloom 7.26.2 → 7.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/docs/adoption-matrix.mdx +2 -2
  2. package/docs/design-tokens.mdx +58 -15
  3. package/lib/commonjs/layout/ScrollArea.js +2 -4
  4. package/lib/commonjs/layout/ScrollArea.js.map +1 -1
  5. package/lib/commonjs/multi-agent-chat/ScrollSurface.js +1 -2
  6. package/lib/commonjs/multi-agent-chat/ScrollSurface.js.map +1 -1
  7. package/lib/commonjs/portal/Portal.js +11 -2
  8. package/lib/commonjs/portal/Portal.js.map +1 -1
  9. package/lib/commonjs/portal/Portal.web.js +10 -1
  10. package/lib/commonjs/portal/Portal.web.js.map +1 -1
  11. package/lib/commonjs/styles/styled-primitives.js +2 -1
  12. package/lib/commonjs/styles/styled-primitives.js.map +1 -1
  13. package/lib/commonjs/theme/BloomThemeProvider.js +30 -4
  14. package/lib/commonjs/theme/BloomThemeProvider.js.map +1 -1
  15. package/lib/commonjs/theme/color-scope/ColorScope.js +14 -27
  16. package/lib/commonjs/theme/color-scope/ColorScope.js.map +1 -1
  17. package/lib/commonjs/theme/color-scope/ColorScope.web.js +15 -23
  18. package/lib/commonjs/theme/color-scope/ColorScope.web.js.map +1 -1
  19. package/lib/commonjs/theme/color-scope/ThemeScopeBridge.js +36 -0
  20. package/lib/commonjs/theme/color-scope/ThemeScopeBridge.js.map +1 -0
  21. package/lib/commonjs/theme/color-scope/context.js +11 -0
  22. package/lib/commonjs/theme/color-scope/context.js.map +1 -0
  23. package/lib/commonjs/theme/color-scope/resolve-scope.js +86 -0
  24. package/lib/commonjs/theme/color-scope/resolve-scope.js.map +1 -0
  25. package/lib/commonjs/theme/color-scope/types.js +6 -0
  26. package/lib/commonjs/theme/color-scope/types.js.map +1 -0
  27. package/lib/commonjs/theme/color-scope/use-scope.js +44 -0
  28. package/lib/commonjs/theme/color-scope/use-scope.js.map +1 -0
  29. package/lib/commonjs/theme/seed-scope/SeedScope.js +26 -1
  30. package/lib/commonjs/theme/seed-scope/SeedScope.js.map +1 -1
  31. package/lib/commonjs/theme/seed-scope/SeedScope.web.js +26 -1
  32. package/lib/commonjs/theme/seed-scope/SeedScope.web.js.map +1 -1
  33. package/lib/module/layout/ScrollArea.js +2 -4
  34. package/lib/module/layout/ScrollArea.js.map +1 -1
  35. package/lib/module/multi-agent-chat/ScrollSurface.js +1 -2
  36. package/lib/module/multi-agent-chat/ScrollSurface.js.map +1 -1
  37. package/lib/module/portal/Portal.js +11 -2
  38. package/lib/module/portal/Portal.js.map +1 -1
  39. package/lib/module/portal/Portal.web.js +11 -2
  40. package/lib/module/portal/Portal.web.js.map +1 -1
  41. package/lib/module/styles/styled-primitives.js +2 -1
  42. package/lib/module/styles/styled-primitives.js.map +1 -1
  43. package/lib/module/theme/BloomThemeProvider.js +30 -4
  44. package/lib/module/theme/BloomThemeProvider.js.map +1 -1
  45. package/lib/module/theme/color-scope/ColorScope.js +15 -28
  46. package/lib/module/theme/color-scope/ColorScope.js.map +1 -1
  47. package/lib/module/theme/color-scope/ColorScope.web.js +15 -23
  48. package/lib/module/theme/color-scope/ColorScope.web.js.map +1 -1
  49. package/lib/module/theme/color-scope/ThemeScopeBridge.js +32 -0
  50. package/lib/module/theme/color-scope/ThemeScopeBridge.js.map +1 -0
  51. package/lib/module/theme/color-scope/context.js +8 -0
  52. package/lib/module/theme/color-scope/context.js.map +1 -0
  53. package/lib/module/theme/color-scope/resolve-scope.js +82 -0
  54. package/lib/module/theme/color-scope/resolve-scope.js.map +1 -0
  55. package/lib/module/theme/color-scope/types.js +4 -0
  56. package/lib/module/theme/color-scope/types.js.map +1 -0
  57. package/lib/module/theme/color-scope/use-scope.js +40 -0
  58. package/lib/module/theme/color-scope/use-scope.js.map +1 -0
  59. package/lib/module/theme/seed-scope/SeedScope.js +26 -1
  60. package/lib/module/theme/seed-scope/SeedScope.js.map +1 -1
  61. package/lib/module/theme/seed-scope/SeedScope.web.js +26 -1
  62. package/lib/module/theme/seed-scope/SeedScope.web.js.map +1 -1
  63. package/lib/typescript/commonjs/accordion/Accordion.d.ts +25 -14
  64. package/lib/typescript/commonjs/accordion/Accordion.d.ts.map +1 -1
  65. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.d.ts +7 -4
  66. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/layout/ScrollArea.d.ts.map +1 -1
  68. package/lib/typescript/commonjs/multi-agent-chat/ScrollSurface.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/portal/Portal.d.ts.map +1 -1
  70. package/lib/typescript/commonjs/portal/Portal.web.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/rating/RatingBar.d.ts +16 -7
  72. package/lib/typescript/commonjs/rating/RatingBar.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/stat-bar/Meter.d.ts +10 -5
  74. package/lib/typescript/commonjs/stat-bar/Meter.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/styles/styled-primitives.d.ts.map +1 -1
  76. package/lib/typescript/commonjs/text-field/FieldBox.d.ts +5 -1
  77. package/lib/typescript/commonjs/text-field/FieldBox.d.ts.map +1 -1
  78. package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/theme/color-scope/ColorScope.d.ts +7 -2
  80. package/lib/typescript/commonjs/theme/color-scope/ColorScope.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/theme/color-scope/ColorScope.web.d.ts +7 -2
  82. package/lib/typescript/commonjs/theme/color-scope/ColorScope.web.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/theme/color-scope/ThemeScopeBridge.d.ts +9 -0
  84. package/lib/typescript/commonjs/theme/color-scope/ThemeScopeBridge.d.ts.map +1 -0
  85. package/lib/typescript/commonjs/theme/color-scope/context.d.ts +14 -0
  86. package/lib/typescript/commonjs/theme/color-scope/context.d.ts.map +1 -0
  87. package/lib/typescript/commonjs/theme/color-scope/index.d.ts +1 -0
  88. package/lib/typescript/commonjs/theme/color-scope/index.d.ts.map +1 -1
  89. package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts +1 -0
  90. package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts.map +1 -1
  91. package/lib/typescript/commonjs/theme/color-scope/resolve-scope.d.ts +5 -0
  92. package/lib/typescript/commonjs/theme/color-scope/resolve-scope.d.ts.map +1 -0
  93. package/lib/typescript/commonjs/theme/color-scope/types.d.ts +4 -0
  94. package/lib/typescript/commonjs/theme/color-scope/types.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/theme/color-scope/use-scope.d.ts +9 -0
  96. package/lib/typescript/commonjs/theme/color-scope/use-scope.d.ts.map +1 -0
  97. package/lib/typescript/commonjs/theme/index.d.ts +1 -1
  98. package/lib/typescript/commonjs/theme/index.d.ts.map +1 -1
  99. package/lib/typescript/commonjs/theme/index.web.d.ts +1 -1
  100. package/lib/typescript/commonjs/theme/index.web.d.ts.map +1 -1
  101. package/lib/typescript/commonjs/theme/seed-scope/SeedScope.d.ts.map +1 -1
  102. package/lib/typescript/commonjs/theme/seed-scope/SeedScope.web.d.ts.map +1 -1
  103. package/lib/typescript/module/accordion/Accordion.d.ts +25 -14
  104. package/lib/typescript/module/accordion/Accordion.d.ts.map +1 -1
  105. package/lib/typescript/module/collapsible/CollapsibleFrame.d.ts +7 -4
  106. package/lib/typescript/module/collapsible/CollapsibleFrame.d.ts.map +1 -1
  107. package/lib/typescript/module/layout/ScrollArea.d.ts.map +1 -1
  108. package/lib/typescript/module/multi-agent-chat/ScrollSurface.d.ts.map +1 -1
  109. package/lib/typescript/module/portal/Portal.d.ts.map +1 -1
  110. package/lib/typescript/module/portal/Portal.web.d.ts.map +1 -1
  111. package/lib/typescript/module/rating/RatingBar.d.ts +16 -7
  112. package/lib/typescript/module/rating/RatingBar.d.ts.map +1 -1
  113. package/lib/typescript/module/stat-bar/Meter.d.ts +10 -5
  114. package/lib/typescript/module/stat-bar/Meter.d.ts.map +1 -1
  115. package/lib/typescript/module/styles/styled-primitives.d.ts.map +1 -1
  116. package/lib/typescript/module/text-field/FieldBox.d.ts +5 -1
  117. package/lib/typescript/module/text-field/FieldBox.d.ts.map +1 -1
  118. package/lib/typescript/module/theme/BloomThemeProvider.d.ts.map +1 -1
  119. package/lib/typescript/module/theme/color-scope/ColorScope.d.ts +7 -2
  120. package/lib/typescript/module/theme/color-scope/ColorScope.d.ts.map +1 -1
  121. package/lib/typescript/module/theme/color-scope/ColorScope.web.d.ts +7 -2
  122. package/lib/typescript/module/theme/color-scope/ColorScope.web.d.ts.map +1 -1
  123. package/lib/typescript/module/theme/color-scope/ThemeScopeBridge.d.ts +9 -0
  124. package/lib/typescript/module/theme/color-scope/ThemeScopeBridge.d.ts.map +1 -0
  125. package/lib/typescript/module/theme/color-scope/context.d.ts +14 -0
  126. package/lib/typescript/module/theme/color-scope/context.d.ts.map +1 -0
  127. package/lib/typescript/module/theme/color-scope/index.d.ts +1 -0
  128. package/lib/typescript/module/theme/color-scope/index.d.ts.map +1 -1
  129. package/lib/typescript/module/theme/color-scope/index.web.d.ts +1 -0
  130. package/lib/typescript/module/theme/color-scope/index.web.d.ts.map +1 -1
  131. package/lib/typescript/module/theme/color-scope/resolve-scope.d.ts +5 -0
  132. package/lib/typescript/module/theme/color-scope/resolve-scope.d.ts.map +1 -0
  133. package/lib/typescript/module/theme/color-scope/types.d.ts +4 -0
  134. package/lib/typescript/module/theme/color-scope/types.d.ts.map +1 -0
  135. package/lib/typescript/module/theme/color-scope/use-scope.d.ts +9 -0
  136. package/lib/typescript/module/theme/color-scope/use-scope.d.ts.map +1 -0
  137. package/lib/typescript/module/theme/index.d.ts +1 -1
  138. package/lib/typescript/module/theme/index.d.ts.map +1 -1
  139. package/lib/typescript/module/theme/index.web.d.ts +1 -1
  140. package/lib/typescript/module/theme/index.web.d.ts.map +1 -1
  141. package/lib/typescript/module/theme/seed-scope/SeedScope.d.ts.map +1 -1
  142. package/lib/typescript/module/theme/seed-scope/SeedScope.web.d.ts.map +1 -1
  143. package/package.json +4 -4
  144. package/src/layout/ScrollArea.tsx +2 -4
  145. package/src/multi-agent-chat/ScrollSurface.tsx +1 -4
  146. package/src/portal/Portal.tsx +19 -12
  147. package/src/portal/Portal.web.tsx +7 -2
  148. package/src/styles/styled-primitives.ts +3 -2
  149. package/src/theme/BloomThemeProvider.tsx +14 -2
  150. package/src/theme/color-scope/ColorScope.tsx +20 -31
  151. package/src/theme/color-scope/ColorScope.web.tsx +18 -37
  152. package/src/theme/color-scope/ThemeScopeBridge.tsx +30 -0
  153. package/src/theme/color-scope/context.ts +20 -0
  154. package/src/theme/color-scope/index.ts +1 -0
  155. package/src/theme/color-scope/index.web.ts +1 -0
  156. package/src/theme/color-scope/resolve-scope.ts +82 -0
  157. package/src/theme/color-scope/types.ts +4 -0
  158. package/src/theme/color-scope/use-scope.ts +46 -0
  159. package/src/theme/index.ts +1 -1
  160. package/src/theme/index.web.ts +1 -1
  161. package/src/theme/seed-scope/SeedScope.tsx +11 -1
  162. package/src/theme/seed-scope/SeedScope.web.tsx +11 -1
@@ -1,7 +1,9 @@
1
1
  import React, { Children, cloneElement, isValidElement, useContext, useMemo } from 'react';
2
2
 
3
- import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemeProvider';
4
- import { buildTheme } from '../build-theme';
3
+ import { BloomThemeContext } from '../BloomThemeProvider';
4
+ import { ThemeScopeContext } from './context';
5
+ import { useScope } from './use-scope';
6
+ import type { BloomColorScopeTokens } from './types';
5
7
  import type { AppColorName } from '../color-presets';
6
8
  import { buildScopeVars } from './style-builder';
7
9
 
@@ -11,10 +13,7 @@ import { buildScopeVars } from './style-builder';
11
13
  * utilities. Scoped onto an element's inline `style`, profile-level NativeWind
12
14
  * classes resolve against the subtree preset instead of the document root.
13
15
  */
14
- function buildWebScopeVars(
15
- colorPreset: AppColorName,
16
- mode: 'light' | 'dark',
17
- ): React.CSSProperties {
16
+ function buildWebScopeVars(colorPreset: AppColorName, mode: 'light' | 'dark'): React.CSSProperties {
18
17
  return buildScopeVars(colorPreset, mode) as React.CSSProperties;
19
18
  }
20
19
 
@@ -27,7 +26,11 @@ export interface BloomColorScopeProps {
27
26
  * tree is identical either way, so a preset that arrives late cannot remount
28
27
  * the subtree. `ColorScope.tsx` carries the full account.
29
28
  */
30
- colorPreset: AppColorName | undefined;
29
+ colorPreset?: AppColorName;
30
+ /** Local resolved mode; does not change the app mode, storage or document. */
31
+ mode?: 'light' | 'dark';
32
+ /** Exact canonical colors. Unspecified roles inherit the selected preset or parent scope. */
33
+ tokens?: BloomColorScopeTokens;
31
34
  /**
32
35
  * When `true`, do not render a wrapping `<div>`. The single child is cloned
33
36
  * with the scope's CSS vars merged into its `style` prop (Radix-style).
@@ -55,13 +58,7 @@ export interface BloomColorScopeProps {
55
58
  * So the array form is used only when the child's own style is already
56
59
  * RN-shaped; every other child gets a plain object, which both runtimes accept.
57
60
  */
58
- type WebStyle =
59
- | React.CSSProperties
60
- | number
61
- | null
62
- | undefined
63
- | false
64
- | ReadonlyArray<WebStyle>;
61
+ type WebStyle = React.CSSProperties | number | null | undefined | false | ReadonlyArray<WebStyle>;
65
62
 
66
63
  interface StyleableProps {
67
64
  style?: WebStyle;
@@ -69,32 +66,14 @@ interface StyleableProps {
69
66
 
70
67
  export function BloomColorScope({
71
68
  colorPreset,
69
+ mode,
70
+ tokens,
72
71
  asChild = false,
73
72
  style,
74
73
  children,
75
74
  }: BloomColorScopeProps) {
76
- // All hooks are called UNCONDITIONALLY, in the same order on every render —
77
- // never gate a hook behind an early return (rules of hooks). The conditional
78
- // no-op/throw behavior is applied AFTER every hook has run, using the values
79
- // the hooks produced. `resolvedMode` falls back harmlessly when the provider
80
- // is absent (that render path throws below anyway).
81
- const parent = useContext(BloomThemeContext);
82
- const resolvedMode = parent?.theme.mode ?? 'light';
83
-
84
- const contextValue = useMemo<BloomThemeContextValue | null>(() => {
85
- if (!parent || !colorPreset) return null;
86
- const theme = buildTheme(colorPreset, resolvedMode);
87
- return { ...parent, theme, colorPreset };
88
- }, [colorPreset, resolvedMode, parent]);
89
-
90
- const varsStyle = useMemo<React.CSSProperties | null>(
91
- () => (colorPreset ? buildWebScopeVars(colorPreset, resolvedMode) : null),
92
- [colorPreset, resolvedMode],
93
- );
94
-
95
- if (!parent) {
96
- throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
97
- }
75
+ const { context, state, vars } = useScope(colorPreset, mode, tokens);
76
+ const varsStyle = vars as React.CSSProperties | undefined;
98
77
 
99
78
  let content: React.ReactNode;
100
79
  if (asChild) {
@@ -122,7 +101,9 @@ export function BloomColorScope({
122
101
  }
123
102
 
124
103
  return (
125
- <BloomThemeContext.Provider value={contextValue ?? parent}>{content}</BloomThemeContext.Provider>
104
+ <BloomThemeContext.Provider value={context}>
105
+ <ThemeScopeContext.Provider value={state}>{content}</ThemeScopeContext.Provider>
106
+ </BloomThemeContext.Provider>
126
107
  );
127
108
  }
128
109
 
@@ -0,0 +1,30 @@
1
+ import React, { useContext } from 'react';
2
+ import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemeProvider';
3
+ import { ThemeScopeContext, type ScopeState } from './context';
4
+ import { getVariableContextProvider } from './style-builder';
5
+
6
+ /** Re-publish the source scope when a native portal renders under an unrelated outlet. */
7
+ export function ThemeScopeBridge({
8
+ theme,
9
+ scope,
10
+ children,
11
+ }: React.PropsWithChildren<{
12
+ theme: BloomThemeContextValue | null;
13
+ scope: ScopeState | null;
14
+ }>) {
15
+ const outletTheme = useContext(BloomThemeContext);
16
+ const outletScope = useContext(ThemeScopeContext);
17
+ const sourceTheme = theme ?? outletTheme;
18
+ const sourceScope = scope ?? outletScope;
19
+ const Variables = getVariableContextProvider();
20
+ const content = Variables ? (
21
+ <Variables value={sourceScope?.vars ?? {}}>{children}</Variables>
22
+ ) : (
23
+ children
24
+ );
25
+ return (
26
+ <BloomThemeContext.Provider value={sourceTheme}>
27
+ <ThemeScopeContext.Provider value={sourceScope}>{content}</ThemeScopeContext.Provider>
28
+ </BloomThemeContext.Provider>
29
+ );
30
+ }
@@ -0,0 +1,20 @@
1
+ import { createContext } from 'react';
2
+ import type { Theme } from '../types';
3
+
4
+ export interface ScopePalette {
5
+ theme: Theme;
6
+ vars: Record<string, string>;
7
+ }
8
+
9
+ /** Private resolved source, retained through scopes and portal outlets. */
10
+ export interface ScopeState extends ScopePalette {
11
+ resolveMode: (mode: 'light' | 'dark') => ScopePalette;
12
+ }
13
+
14
+ declare global {
15
+ // eslint-disable-next-line no-var
16
+ var __oxy_so_bloom_scope_context__: React.Context<ScopeState | null> | undefined;
17
+ }
18
+
19
+ export const ThemeScopeContext = (globalThis.__oxy_so_bloom_scope_context__ ??=
20
+ createContext<ScopeState | null>(null));
@@ -1,2 +1,3 @@
1
1
  export { BloomColorScope, useColorScopeStyle } from './ColorScope';
2
2
  export type { BloomColorScopeProps } from './ColorScope';
3
+ export type { BloomColorScopeTokens } from './types';
@@ -5,3 +5,4 @@
5
5
 
6
6
  export { BloomColorScope, useColorScopeStyle } from './ColorScope.web';
7
7
  export type { BloomColorScopeProps } from './ColorScope.web';
8
+ export type { BloomColorScopeTokens } from './types';
@@ -0,0 +1,82 @@
1
+ import { processColor } from 'react-native';
2
+ import { CANONICAL_TOKENS, type CanonicalToken } from '../token-registry';
3
+ import { chartColorsFromTokens } from '../chart-colors';
4
+ import type { ThemeColors } from '../types';
5
+ import type { ScopePalette } from './context';
6
+ import { withScopeAliases } from './seed-scope';
7
+ import type { BloomColorScopeTokens } from './types';
8
+
9
+ /** All JS aliases of an exact canonical override share the same supplied value. */
10
+ const COLOR_FIELDS = {
11
+ background: ['background', 'primaryDark'],
12
+ foreground: ['text'],
13
+ surface: ['backgroundSecondary', 'primaryLight'],
14
+ popover: ['backgroundTertiary'],
15
+ 'muted-foreground': ['textSecondary', 'textTertiary', 'icon'],
16
+ border: ['border'],
17
+ input: ['borderLight'],
18
+ primary: ['primary', 'tint', 'iconActive'],
19
+ 'primary-foreground': ['primaryForeground'],
20
+ 'primary-subtle': ['primarySubtle'],
21
+ 'primary-text': ['primarySubtleForeground'],
22
+ secondary: ['secondary'],
23
+ 'secondary-foreground': ['secondaryForeground'],
24
+ 'secondary-subtle': ['secondarySubtle'],
25
+ 'secondary-text': ['secondarySubtleForeground'],
26
+ tertiary: ['tertiary'],
27
+ 'tertiary-foreground': ['tertiaryForeground'],
28
+ 'tertiary-subtle': ['tertiarySubtle'],
29
+ 'tertiary-text': ['tertiarySubtleForeground'],
30
+ success: ['success'],
31
+ 'success-foreground': ['successForeground'],
32
+ 'success-subtle': ['successSubtle'],
33
+ 'success-text': ['successSubtleForeground'],
34
+ error: ['error', 'negative'],
35
+ 'error-foreground': ['errorForeground', 'negativeForeground'],
36
+ 'error-subtle': ['errorSubtle', 'negativeSubtle'],
37
+ 'error-text': ['errorSubtleForeground', 'negativeSubtleForeground'],
38
+ warning: ['warning'],
39
+ 'warning-foreground': ['warningForeground'],
40
+ 'warning-subtle': ['warningSubtle'],
41
+ 'warning-text': ['warningSubtleForeground'],
42
+ info: ['info'],
43
+ 'info-foreground': ['infoForeground'],
44
+ 'info-subtle': ['infoSubtle'],
45
+ 'info-text': ['infoSubtleForeground'],
46
+ muted: ['contrast50'],
47
+ card: ['card'],
48
+ } satisfies Partial<Record<CanonicalToken, readonly (keyof ThemeColors)[]>>;
49
+
50
+ /** Preserve unspecified roles; rebuild the full CSS alias layer after exact overrides. */
51
+ export function applyScopeTokens(
52
+ base: ScopePalette,
53
+ overrides?: BloomColorScopeTokens,
54
+ ): ScopePalette {
55
+ if (!overrides || Object.keys(overrides).length === 0) return base;
56
+ const vars = { ...base.vars };
57
+ const colors = { ...base.theme.colors };
58
+ let changedCharts = false;
59
+ for (const [name, value] of Object.entries(overrides)) {
60
+ if (value === undefined) continue;
61
+ if (!(CANONICAL_TOKENS as readonly string[]).includes(name)) {
62
+ throw new Error(`BloomColorScope: unknown canonical token "${name}".`);
63
+ }
64
+ if (typeof value !== 'string' || !value.trim() || processColor(value) == null) {
65
+ throw new Error(`BloomColorScope: "${name}" requires a resolved color value.`);
66
+ }
67
+ vars[`--${name}`] = value;
68
+ const fields = COLOR_FIELDS[name as keyof typeof COLOR_FIELDS];
69
+ for (const field of fields ?? []) colors[field] = value;
70
+ if (name.startsWith('chart-')) changedCharts = true;
71
+ }
72
+ return {
73
+ vars: withScopeAliases(
74
+ Object.fromEntries(Object.entries(vars).filter(([name]) => !name.startsWith('--color-'))),
75
+ ),
76
+ theme: {
77
+ ...base.theme,
78
+ colors,
79
+ ...(changedCharts ? { chartColors: chartColorsFromTokens(vars) } : {}),
80
+ },
81
+ };
82
+ }
@@ -0,0 +1,4 @@
1
+ import type { CanonicalToken } from '../token-registry';
2
+
3
+ /** Exact cross-platform color values, keyed by Bloom's canonical token names. */
4
+ export type BloomColorScopeTokens = Readonly<Partial<Record<CanonicalToken, string>>>;
@@ -0,0 +1,46 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import { BloomThemeContext } from '../BloomThemeProvider';
3
+ import { buildTheme } from '../build-theme';
4
+ import type { AppColorName } from '../color-presets';
5
+ import { ThemeScopeContext, type ScopePalette, type ScopeState } from './context';
6
+ import { buildScopeVars } from './style-builder';
7
+ import { applyScopeTokens } from './resolve-scope';
8
+ import type { BloomColorScopeTokens } from './types';
9
+
10
+ export function useScope(
11
+ colorPreset?: AppColorName,
12
+ mode?: 'light' | 'dark',
13
+ tokens?: BloomColorScopeTokens,
14
+ ) {
15
+ const parent = useContext(BloomThemeContext);
16
+ const inherited = useContext(ThemeScopeContext);
17
+ const active = colorPreset !== undefined || mode !== undefined || tokens !== undefined;
18
+ const state = useMemo<ScopeState | null>(() => {
19
+ if (!parent || !active) return inherited;
20
+ const resolveMode = (resolved: 'light' | 'dark'): ScopePalette => {
21
+ const base =
22
+ colorPreset !== undefined || !inherited
23
+ ? {
24
+ theme: buildTheme(colorPreset ?? parent.colorPreset, resolved),
25
+ vars: buildScopeVars(colorPreset ?? parent.colorPreset, resolved),
26
+ }
27
+ : inherited.resolveMode(resolved);
28
+ return applyScopeTokens(base, tokens);
29
+ };
30
+ return { ...resolveMode(mode ?? parent.theme.mode), resolveMode };
31
+ }, [parent, inherited, active, colorPreset, mode, tokens]);
32
+ const context = useMemo(
33
+ () =>
34
+ parent && active && state
35
+ ? {
36
+ ...parent,
37
+ theme: state.theme,
38
+ colorPreset: colorPreset ?? parent.colorPreset,
39
+ mode: mode ?? parent.mode,
40
+ }
41
+ : parent,
42
+ [parent, active, state, colorPreset, mode],
43
+ );
44
+ if (!parent) throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
45
+ return { context: context!, state, vars: active ? state?.vars : undefined };
46
+ }
@@ -4,7 +4,7 @@ export type {
4
4
  BloomThemeContextValue,
5
5
  } from './BloomThemeProvider';
6
6
  export { BloomColorScope, useColorScopeStyle } from './color-scope';
7
- export type { BloomColorScopeProps } from './color-scope';
7
+ export type { BloomColorScopeProps, BloomColorScopeTokens } from './color-scope';
8
8
  export { BloomSeedScope } from './seed-scope';
9
9
  export type { BloomSeedScopeProps } from './seed-scope';
10
10
  export { roleColorsToPresetTokens } from './color-scope/seed-scope';
@@ -9,7 +9,7 @@ export type {
9
9
  BloomThemeContextValue,
10
10
  } from './BloomThemeProvider';
11
11
  export { BloomColorScope, useColorScopeStyle } from './color-scope/index.web';
12
- export type { BloomColorScopeProps } from './color-scope/index.web';
12
+ export type { BloomColorScopeProps, BloomColorScopeTokens } from './color-scope/index.web';
13
13
  export { BloomSeedScope } from './seed-scope/index.web';
14
14
  export type { BloomSeedScopeProps } from './seed-scope/index.web';
15
15
  export { roleColorsToPresetTokens } from './color-scope/seed-scope';
@@ -6,6 +6,7 @@ import { buildSeedScopeVars } from '../color-scope/seed-scope';
6
6
  import { getVariableContextProvider } from '../color-scope/style-builder';
7
7
  import { buildThemeFromSeed } from '../build-theme-from-seed';
8
8
  import type { SchemeVariant } from '../color-engine';
9
+ import { ThemeScopeContext, type ScopeState } from '../color-scope/context';
9
10
 
10
11
  export interface BloomSeedScopeProps {
11
12
  /**
@@ -80,6 +81,15 @@ export function BloomSeedScope({
80
81
  return { ...parent, theme };
81
82
  }, [parent, seed, resolvedMode, variant, contrastLevel, secondarySeed, tertiarySeed]);
82
83
 
84
+ const scopeState = useMemo<ScopeState | null>(() => {
85
+ if (!seed) return null;
86
+ const resolveMode = (mode: 'light' | 'dark') => ({
87
+ theme: buildThemeFromSeed(seed, mode, variant, contrastLevel, { secondarySeed, tertiarySeed }),
88
+ vars: buildSeedScopeVars({ seed, mode, variant, contrastLevel, secondarySeed, tertiarySeed }),
89
+ });
90
+ return { ...resolveMode(resolvedMode), resolveMode };
91
+ }, [seed, resolvedMode, variant, contrastLevel, secondarySeed, tertiarySeed]);
92
+
83
93
  if (!parent) {
84
94
  throw new Error('BloomSeedScope must be used within a <BloomThemeProvider>');
85
95
  }
@@ -109,5 +119,5 @@ export function BloomSeedScope({
109
119
  content
110
120
  );
111
121
 
112
- return <BloomThemeContext.Provider value={contextValue}>{scoped}</BloomThemeContext.Provider>;
122
+ return <BloomThemeContext.Provider value={contextValue}><ThemeScopeContext.Provider value={scopeState}>{scoped}</ThemeScopeContext.Provider></BloomThemeContext.Provider>;
113
123
  }
@@ -4,6 +4,7 @@ import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemePro
4
4
  import { buildSeedScopeVars } from '../color-scope/seed-scope';
5
5
  import { buildThemeFromSeed } from '../build-theme-from-seed';
6
6
  import type { SchemeVariant } from '../color-engine';
7
+ import { ThemeScopeContext, type ScopeState } from '../color-scope/context';
7
8
 
8
9
  export interface BloomSeedScopeProps {
9
10
  /**
@@ -97,6 +98,15 @@ export function BloomSeedScope({
97
98
  return { ...parent, theme };
98
99
  }, [parent, seed, resolvedMode, variant, contrastLevel, secondarySeed, tertiarySeed]);
99
100
 
101
+ const scopeState = useMemo<ScopeState | null>(() => {
102
+ if (!seed) return null;
103
+ const resolveMode = (mode: 'light' | 'dark') => ({
104
+ theme: buildThemeFromSeed(seed, mode, variant, contrastLevel, { secondarySeed, tertiarySeed }),
105
+ vars: buildSeedScopeVars({ seed, mode, variant, contrastLevel, secondarySeed, tertiarySeed }),
106
+ });
107
+ return { ...resolveMode(resolvedMode), resolveMode };
108
+ }, [seed, resolvedMode, variant, contrastLevel, secondarySeed, tertiarySeed]);
109
+
100
110
  if (!parent) {
101
111
  throw new Error('BloomSeedScope must be used within a <BloomThemeProvider>');
102
112
  }
@@ -118,5 +128,5 @@ export function BloomSeedScope({
118
128
  content = <div style={mergedStyle}>{children}</div>;
119
129
  }
120
130
 
121
- return <BloomThemeContext.Provider value={contextValue}>{content}</BloomThemeContext.Provider>;
131
+ return <BloomThemeContext.Provider value={contextValue}><ThemeScopeContext.Provider value={scopeState}>{content}</ThemeScopeContext.Provider></BloomThemeContext.Provider>;
122
132
  }