@oxyhq/bloom 0.43.0 → 0.44.1

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 (51) hide show
  1. package/lib/commonjs/bottom-sheet/BottomSheetBase.js +9 -1
  2. package/lib/commonjs/bottom-sheet/BottomSheetBase.js.map +1 -1
  3. package/lib/commonjs/theme/BloomThemeProvider.js +31 -14
  4. package/lib/commonjs/theme/BloomThemeProvider.js.map +1 -1
  5. package/lib/commonjs/theme/apply-dark-class.js +12 -3
  6. package/lib/commonjs/theme/apply-dark-class.js.map +1 -1
  7. package/lib/commonjs/theme/native-root-vars.js +5 -0
  8. package/lib/commonjs/theme/native-root-vars.js.map +1 -1
  9. package/lib/commonjs/theme/native-root-vars.native.js +13 -3
  10. package/lib/commonjs/theme/native-root-vars.native.js.map +1 -1
  11. package/lib/commonjs/theme/native-root-vars.web.js +5 -0
  12. package/lib/commonjs/theme/native-root-vars.web.js.map +1 -1
  13. package/lib/module/bottom-sheet/BottomSheetBase.js +9 -1
  14. package/lib/module/bottom-sheet/BottomSheetBase.js.map +1 -1
  15. package/lib/module/theme/BloomThemeProvider.js +33 -16
  16. package/lib/module/theme/BloomThemeProvider.js.map +1 -1
  17. package/lib/module/theme/apply-dark-class.js +11 -3
  18. package/lib/module/theme/apply-dark-class.js.map +1 -1
  19. package/lib/module/theme/native-root-vars.js +4 -0
  20. package/lib/module/theme/native-root-vars.js.map +1 -1
  21. package/lib/module/theme/native-root-vars.native.js +12 -3
  22. package/lib/module/theme/native-root-vars.native.js.map +1 -1
  23. package/lib/module/theme/native-root-vars.web.js +4 -0
  24. package/lib/module/theme/native-root-vars.web.js.map +1 -1
  25. package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts +11 -1
  26. package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/theme/apply-dark-class.d.ts +7 -0
  28. package/lib/typescript/commonjs/theme/apply-dark-class.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/theme/native-root-vars.d.ts +2 -0
  30. package/lib/typescript/commonjs/theme/native-root-vars.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/theme/native-root-vars.native.d.ts +8 -0
  32. package/lib/typescript/commonjs/theme/native-root-vars.native.d.ts.map +1 -1
  33. package/lib/typescript/commonjs/theme/native-root-vars.web.d.ts +2 -0
  34. package/lib/typescript/commonjs/theme/native-root-vars.web.d.ts.map +1 -1
  35. package/lib/typescript/module/theme/BloomThemeProvider.d.ts +11 -1
  36. package/lib/typescript/module/theme/BloomThemeProvider.d.ts.map +1 -1
  37. package/lib/typescript/module/theme/apply-dark-class.d.ts +7 -0
  38. package/lib/typescript/module/theme/apply-dark-class.d.ts.map +1 -1
  39. package/lib/typescript/module/theme/native-root-vars.d.ts +2 -0
  40. package/lib/typescript/module/theme/native-root-vars.d.ts.map +1 -1
  41. package/lib/typescript/module/theme/native-root-vars.native.d.ts +8 -0
  42. package/lib/typescript/module/theme/native-root-vars.native.d.ts.map +1 -1
  43. package/lib/typescript/module/theme/native-root-vars.web.d.ts +2 -0
  44. package/lib/typescript/module/theme/native-root-vars.web.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/src/bottom-sheet/BottomSheetBase.tsx +8 -0
  47. package/src/theme/BloomThemeProvider.tsx +53 -17
  48. package/src/theme/apply-dark-class.ts +15 -8
  49. package/src/theme/native-root-vars.native.ts +17 -8
  50. package/src/theme/native-root-vars.ts +5 -0
  51. package/src/theme/native-root-vars.web.ts +5 -0
@@ -24,11 +24,13 @@ import {
24
24
  import { useControllableState } from '../hooks/useControllableState';
25
25
  import { FontLoader } from '../fonts/FontLoader';
26
26
 
27
- import { applyDarkClass, applyColorPresetVars } from './apply-dark-class';
27
+ import { applyDarkClass, applyVarsToDocument } from './apply-dark-class';
28
28
  import { buildTheme } from './build-theme';
29
+ import { buildThemeFromSeed } from './build-theme-from-seed';
30
+ import { buildSeedScopeVars } from './color-scope/seed-scope';
29
31
  import { type AppColorName } from './color-presets';
30
32
  import { buildScopeVars, getVariableContextProvider } from './color-scope/style-builder';
31
- import { applyNativeRootVars } from './native-root-vars';
33
+ import { applyVarsToRootVariables } from './native-root-vars';
32
34
  import {
33
35
  readPersistedTheme,
34
36
  readPersistedThemeSync,
@@ -151,6 +153,17 @@ export interface BloomThemeProviderProps {
151
153
  */
152
154
  tertiaryColor?: string;
153
155
 
156
+ /**
157
+ * Optional DYNAMIC seed colour, `#rrggbb`. When set, the WHOLE app themes from
158
+ * this seed instead of the named `colorPreset` (via the same colour engine the
159
+ * preset path uses) — driving app-wide dynamic theming (e.g. tint everything to
160
+ * the artwork the user is viewing/hovering). `secondaryColor`/`tertiaryColor`
161
+ * act as this seed's pinned secondary/tertiary accents (e.g. the 2nd/3rd colours
162
+ * extracted from that artwork). Omit / pass `undefined` to fall back to the
163
+ * preset — so clearing it restores the app's default theme.
164
+ */
165
+ seed?: string;
166
+
154
167
  children: React.ReactNode;
155
168
  }
156
169
 
@@ -314,6 +327,7 @@ export function BloomThemeProvider({
314
327
  nativeWrapperStyle,
315
328
  secondaryColor,
316
329
  tertiaryColor,
330
+ seed,
317
331
  children,
318
332
  }: BloomThemeProviderProps) {
319
333
  const rnScheme = useRNColorScheme();
@@ -349,45 +363,67 @@ export function BloomThemeProvider({
349
363
  // Apply native color scheme, dark class, and CSS vars whenever the resolved
350
364
  // mode or preset changes. `useIsomorphicLayoutEffect` runs before paint on
351
365
  // both native and web, eliminating the previous render-time side effect.
366
+ // The single `--x -> value` record + JS theme for the ACTIVE source, computed
367
+ // ONCE and applied identically to web (document), native (rootVariables +
368
+ // VariableContext), and the JS `theme` context. The source is a DYNAMIC seed
369
+ // (whole-app dynamic theming — `secondaryColor`/`tertiaryColor` pin this seed's
370
+ // accents) when `seed` is set, else the named preset. Both go through the same
371
+ // colour engine, so there is one code path — no seed/preset duplication.
372
+ const themeVars = useMemo(
373
+ () =>
374
+ seed
375
+ ? buildSeedScopeVars({ seed, mode: resolved, secondarySeed: secondaryColor, tertiarySeed: tertiaryColor })
376
+ : buildScopeVars(colorPreset, resolved, explicitAccents),
377
+ [seed, secondaryColor, tertiaryColor, colorPreset, resolved, explicitAccents],
378
+ );
379
+ const themeColors = useMemo(
380
+ () =>
381
+ seed
382
+ ? buildThemeFromSeed(seed, resolved, undefined, undefined, {
383
+ secondarySeed: secondaryColor,
384
+ tertiarySeed: tertiaryColor,
385
+ })
386
+ : buildTheme(colorPreset, resolved, isAdaptive, explicitAccents),
387
+ [seed, secondaryColor, tertiaryColor, colorPreset, resolved, isAdaptive, explicitAccents],
388
+ );
389
+
352
390
  useIsomorphicLayoutEffect(() => {
353
391
  setColorSchemeSafe(effectiveMode);
354
392
  applyDarkClass(resolved);
355
- applyColorPresetVars(colorPreset, resolved, explicitAccents);
356
- }, [effectiveMode, resolved, colorPreset, explicitAccents]);
393
+ applyVarsToDocument(themeVars);
394
+ }, [effectiveMode, resolved, themeVars]);
357
395
 
358
- // Native only: publish the preset vars into react-native-css's GLOBAL root
396
+ // Native only: publish the same vars into react-native-css's GLOBAL root
359
397
  // variable family so they reach the ENTIRE app tree — navigator screens and
360
398
  // every portal/modal/bottom-sheet that paints outside the provider's React
361
399
  // subtree (and therefore never sees the `VariableContextProvider` vars below).
362
400
  // Web writes the same vars to `document.documentElement` above, so this no-ops
363
- // there. Runs before paint via `useIsomorphicLayoutEffect`, matching the
364
- // sibling `applyColorPresetVars` side effect.
401
+ // there. Runs before paint via `useIsomorphicLayoutEffect`.
365
402
  useIsomorphicLayoutEffect(() => {
366
- applyNativeRootVars(colorPreset, resolved, explicitAccents);
367
- }, [colorPreset, resolved, explicitAccents]);
403
+ applyVarsToRootVariables(themeVars);
404
+ }, [themeVars]);
368
405
 
369
406
  const contextValue = useMemo<BloomThemeContextValue>(
370
407
  () => ({
371
- theme: buildTheme(colorPreset, resolved, isAdaptive, explicitAccents),
408
+ theme: themeColors,
372
409
  mode,
373
410
  colorPreset,
374
411
  setMode,
375
412
  setColorPreset,
376
413
  resetTheme,
377
414
  }),
378
- [colorPreset, resolved, isAdaptive, explicitAccents, mode, setMode, setColorPreset, resetTheme],
415
+ [themeColors, mode, colorPreset, setMode, setColorPreset, resetTheme],
379
416
  );
380
417
 
381
418
  const shouldAwait = awaitHydration ?? Boolean(persistKey && storage);
382
419
  const isGated = shouldAwait && !hydrated;
383
420
 
384
- // The full `--name -> value` record for the active preset. On native this is
385
- // handed to `VariableContextProvider` so descendants resolve `var(--primary)`
386
- // etc. through react-native-css's real VariableContext. Web writes these to
387
- // `document.documentElement` via `applyColorPresetVars`, so it's unused there.
421
+ // On native, the same record is handed to `VariableContextProvider` so
422
+ // descendants resolve `var(--primary)` etc. through react-native-css's real
423
+ // VariableContext. Web writes them to `document.documentElement` above.
388
424
  const nativeVars = useMemo(
389
- () => (Platform.OS === 'web' ? null : buildScopeVars(colorPreset, resolved, explicitAccents)),
390
- [colorPreset, resolved, explicitAccents],
425
+ () => (Platform.OS === 'web' ? null : themeVars),
426
+ [themeVars],
391
427
  );
392
428
  const VariableProvider = getVariableContextProvider();
393
429
 
@@ -26,18 +26,25 @@ export function applyDarkClass(resolved: 'light' | 'dark') {
26
26
  * Includes extended tokens (card, chart-*, content-area, sidebar-*) so consumer
27
27
  * apps don't need to synthesize them.
28
28
  */
29
+ /**
30
+ * Write a pre-computed `--x -> value` record to the document root (web only).
31
+ * The single web writer primitive: both the preset path (`applyColorPresetVars`)
32
+ * and `BloomThemeProvider`'s dynamic-seed path feed their already-resolved vars
33
+ * through here, so the "write to document" logic lives in exactly one place.
34
+ */
35
+ export function applyVarsToDocument(vars: Record<string, string>) {
36
+ if (Platform.OS !== 'web' || typeof document === 'undefined') return;
37
+ const root = document.documentElement.style;
38
+ for (const [key, value] of Object.entries(vars)) {
39
+ root.setProperty(key, value);
40
+ }
41
+ }
42
+
29
43
  export function applyColorPresetVars(
30
44
  preset: AppColorName,
31
45
  resolved: 'light' | 'dark',
32
46
  accents?: ExplicitAccents,
33
47
  ) {
34
- if (Platform.OS !== 'web' || typeof document === 'undefined') return;
35
48
  if (!APP_COLOR_PRESETS[preset]) return;
36
-
37
- const vars = getResolvedTokens(preset, resolved, accents);
38
- const root = document.documentElement.style;
39
-
40
- for (const [key, value] of Object.entries(vars)) {
41
- root.setProperty(key, value);
42
- }
49
+ applyVarsToDocument(getResolvedTokens(preset, resolved, accents));
43
50
  }
@@ -122,17 +122,26 @@ import { getResolvedTokens } from './token-registry';
122
122
  * Defensive guard: if a host ships a react-native-css build that doesn't expose
123
123
  * `rootVariables` as a callable (it always does on @3), we bail rather than throw.
124
124
  */
125
- export function applyNativeRootVars(
126
- colorPreset: AppColorName,
127
- mode: 'light' | 'dark',
128
- accents?: ExplicitAccents,
129
- ): void {
125
+ /**
126
+ * Write a pre-computed `--x -> value` record into react-native-css's global
127
+ * `rootVariables` family. The single native writer primitive: both the preset
128
+ * path (`applyNativeRootVars`) and `BloomThemeProvider`'s dynamic-seed path feed
129
+ * their already-resolved vars through here, so the global-write logic lives in
130
+ * exactly one place.
131
+ */
132
+ export function applyVarsToRootVariables(vars: Record<string, string>): void {
130
133
  if (typeof rootVariables !== 'function') return;
131
-
132
- const vars = getResolvedTokens(colorPreset, mode, accents);
133
134
  for (const [key, value] of Object.entries(vars)) {
134
- // The family is keyed by the bare name; `getResolvedTokens` keys include `--`.
135
+ // The family is keyed by the bare name; the var keys include `--`.
135
136
  const name = key.startsWith('--') ? key.slice(2) : key;
136
137
  rootVariables(name).set([[value]]);
137
138
  }
138
139
  }
140
+
141
+ export function applyNativeRootVars(
142
+ colorPreset: AppColorName,
143
+ mode: 'light' | 'dark',
144
+ accents?: ExplicitAccents,
145
+ ): void {
146
+ applyVarsToRootVariables(getResolvedTokens(colorPreset, mode, accents));
147
+ }
@@ -31,6 +31,11 @@ import type { ExplicitAccents } from './preset-vars';
31
31
  * The signature is intentionally identical to those variants so the import site in
32
32
  * `BloomThemeProvider` is platform-agnostic.
33
33
  */
34
+ /** Neutral-default no-op of the native root-vars writer primitive. */
35
+ export function applyVarsToRootVariables(_vars: Record<string, string>): void {
36
+ // Intentionally empty — the native variant does the real work.
37
+ }
38
+
34
39
  export function applyNativeRootVars(
35
40
  _colorPreset: AppColorName,
36
41
  _mode: 'light' | 'dark',
@@ -18,6 +18,11 @@ import type { ExplicitAccents } from './preset-vars';
18
18
  * The signature is intentionally identical to the plain variant so the import
19
19
  * site in `BloomThemeProvider` is platform-agnostic.
20
20
  */
21
+ /** Web no-op of the native root-vars writer primitive (web writes to the document). */
22
+ export function applyVarsToRootVariables(_vars: Record<string, string>): void {
23
+ // Intentionally empty — web applies vars to `document.documentElement`.
24
+ }
25
+
21
26
  export function applyNativeRootVars(
22
27
  _colorPreset: AppColorName,
23
28
  _mode: 'light' | 'dark',