@oxyhq/bloom 0.7.0 → 0.7.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.
- package/lib/commonjs/react-native-css.d.js +2 -0
- package/lib/commonjs/react-native-css.d.js.map +1 -0
- package/lib/commonjs/theme/BloomThemeProvider.js +39 -7
- package/lib/commonjs/theme/BloomThemeProvider.js.map +1 -1
- package/lib/commonjs/theme/color-presets.js +118 -118
- package/lib/commonjs/theme/color-presets.js.map +1 -1
- package/lib/commonjs/theme/color-scope/index.js +28 -6
- package/lib/commonjs/theme/color-scope/index.js.map +1 -1
- package/lib/commonjs/theme/color-scope/style-builder.js +35 -0
- package/lib/commonjs/theme/color-scope/style-builder.js.map +1 -1
- package/lib/commonjs/theme/native-root-vars.js +105 -0
- package/lib/commonjs/theme/native-root-vars.js.map +1 -0
- package/lib/commonjs/theme/native-root-vars.web.js +27 -0
- package/lib/commonjs/theme/native-root-vars.web.js.map +1 -0
- package/lib/commonjs/theme/preset-vars.js +4 -1
- package/lib/commonjs/theme/preset-vars.js.map +1 -1
- package/lib/module/react-native-css.d.js +2 -0
- package/lib/module/react-native-css.d.js.map +1 -0
- package/lib/module/theme/BloomThemeProvider.js +40 -8
- package/lib/module/theme/BloomThemeProvider.js.map +1 -1
- package/lib/module/theme/color-presets.js +118 -118
- package/lib/module/theme/color-presets.js.map +1 -1
- package/lib/module/theme/color-scope/index.js +29 -7
- package/lib/module/theme/color-scope/index.js.map +1 -1
- package/lib/module/theme/color-scope/style-builder.js +35 -0
- package/lib/module/theme/color-scope/style-builder.js.map +1 -1
- package/lib/module/theme/native-root-vars.js +101 -0
- package/lib/module/theme/native-root-vars.js.map +1 -0
- package/lib/module/theme/native-root-vars.web.js +23 -0
- package/lib/module/theme/native-root-vars.web.js.map +1 -0
- package/lib/module/theme/preset-vars.js +4 -1
- package/lib/module/theme/preset-vars.js.map +1 -1
- package/lib/typescript/commonjs/icons/common.d.ts +8 -8
- package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts +9 -2
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/style-builder.d.ts +32 -0
- package/lib/typescript/commonjs/theme/color-scope/style-builder.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/native-root-vars.d.ts +89 -0
- package/lib/typescript/commonjs/theme/native-root-vars.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/native-root-vars.web.d.ts +20 -0
- package/lib/typescript/commonjs/theme/native-root-vars.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/preset-vars.d.ts.map +1 -1
- package/lib/typescript/module/icons/common.d.ts +8 -8
- package/lib/typescript/module/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/index.d.ts +9 -2
- package/lib/typescript/module/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/style-builder.d.ts +32 -0
- package/lib/typescript/module/theme/color-scope/style-builder.d.ts.map +1 -1
- package/lib/typescript/module/theme/native-root-vars.d.ts +89 -0
- package/lib/typescript/module/theme/native-root-vars.d.ts.map +1 -0
- package/lib/typescript/module/theme/native-root-vars.web.d.ts +20 -0
- package/lib/typescript/module/theme/native-root-vars.web.d.ts.map +1 -0
- package/lib/typescript/module/theme/preset-vars.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/native-root-vars.test.ts +125 -0
- package/src/react-native-css.d.ts +69 -0
- package/src/theme/BloomThemeProvider.tsx +32 -6
- package/src/theme/color-presets.ts +118 -118
- package/src/theme/color-scope/index.tsx +30 -8
- package/src/theme/color-scope/style-builder.ts +40 -0
- package/src/theme/native-root-vars.ts +102 -0
- package/src/theme/native-root-vars.web.ts +22 -0
- package/src/theme/preset-vars.ts +4 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { rootVariables } from 'react-native-css/native-internal';
|
|
2
|
+
|
|
3
|
+
import { buildScopeVars } from './color-scope/style-builder';
|
|
4
|
+
import { type AppColorName } from './color-presets';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Publish the active color preset's CSS custom properties into react-native-css's
|
|
8
|
+
* GLOBAL root-variable family so they reach the ENTIRE native app tree — including
|
|
9
|
+
* content rendered outside the React subtree of `BloomThemeProvider`: expo-router
|
|
10
|
+
* navigator screens, `Portal`s, `Dialog`/`BottomSheet` overlays, and any other host
|
|
11
|
+
* that paints through a separate React root.
|
|
12
|
+
*
|
|
13
|
+
* Why a global write is required (native only)
|
|
14
|
+
* --------------------------------------------
|
|
15
|
+
* react-native-css resolves a `var(--x)` reference (its `varResolver`) in this order:
|
|
16
|
+
* 1. `name in inheritedVariables` — the React-context-inherited vars. This is what
|
|
17
|
+
* `VariableContextProvider` populates, but it is React-context-scoped, so it only
|
|
18
|
+
* reaches *direct descendants* of the provider in the React tree.
|
|
19
|
+
* 2. `inlineVariables[name]` — same-component inline vars.
|
|
20
|
+
* 3. `variables[name]` — resolved inherited vars.
|
|
21
|
+
* 4. `universalVariables(name)` — a GLOBAL observable family.
|
|
22
|
+
* 5. `rootVariables(name)` — a GLOBAL observable family.
|
|
23
|
+
* 6. the declared fallback.
|
|
24
|
+
*
|
|
25
|
+
* `BloomThemeProvider`'s `VariableContextProvider` only feeds path #1, so the navigator
|
|
26
|
+
* host and every portal/modal — which render outside that subtree — never see the
|
|
27
|
+
* preset vars and fall through to `rootVariables`/`universalVariables`. By default those
|
|
28
|
+
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
29
|
+
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
30
|
+
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
31
|
+
* navigator renders monochrome. Writing the triples into `rootVariables` here is the
|
|
32
|
+
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
33
|
+
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
34
|
+
* content resolves the palette identically regardless of React-tree position.
|
|
35
|
+
*
|
|
36
|
+
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
37
|
+
* ---------------------------------------------------------
|
|
38
|
+
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
39
|
+
* Metro bundles BOTH. In `native-internal/root.js` the variable families are plain
|
|
40
|
+
* module-local consts — NOT `globalThis`-guarded the way `StyleCollection` is — so the
|
|
41
|
+
* commonjs `root.js` and the module `root.js` each instantiate their OWN separate
|
|
42
|
+
* `rootVariables` family. The react-native-css renderer (`react-native-css/src/components/View.tsx`
|
|
43
|
+
* → `varResolver`) imports its `root.js` via ESM `import`, i.e. the MODULE build. A
|
|
44
|
+
* runtime `require('react-native-css/native-internal')` resolves the package's `require`
|
|
45
|
+
* export condition → the COMMONJS build → a DIFFERENT family the renderer never
|
|
46
|
+
* subscribes to, so the writes are a silent no-op on device. A static top-level
|
|
47
|
+
* `import` resolves the `import` condition → the MODULE build → the renderer's instance.
|
|
48
|
+
*
|
|
49
|
+
* This plain file is the NATIVE/default variant (Metro selects it on iOS/Android,
|
|
50
|
+
* which have no `.native` override here); the web variant lives in the sibling
|
|
51
|
+
* `native-root-vars.web.ts` no-op, which web bundlers pick over this one. So the
|
|
52
|
+
* static `react-native-css/native-internal` import below is never pulled into a web
|
|
53
|
+
* bundle — only into native. This mirrors Bloom's existing platform-split convention
|
|
54
|
+
* (`color-scope/index.tsx` + `color-scope/index.web.tsx`, `FontLoader.native.tsx`).
|
|
55
|
+
*
|
|
56
|
+
* Keying contract (verified against react-native-css@3.0.7)
|
|
57
|
+
* ---------------------------------------------------------
|
|
58
|
+
* The `rootVariables` family is keyed by the BARE variable name, WITHOUT the leading
|
|
59
|
+
* `--`. The compiler strips it uniformly: a `:root { --primary: ... }` declaration is
|
|
60
|
+
* stored via `rule.v.push([property.slice(2), value])` then routed into
|
|
61
|
+
* `shared.rootVariables[name]`, and `@property --x` goes through
|
|
62
|
+
* `name.startsWith("--") ? name.slice(2) : name`. The lookup side matches: a `var(--x)`
|
|
63
|
+
* reference compiles to `[{}, "var", ident.slice(2)]`, so `varResolver` looks up the
|
|
64
|
+
* bare name. `buildScopeVars` returns keys WITH the `--` prefix, so we strip it before
|
|
65
|
+
* writing each entry.
|
|
66
|
+
*
|
|
67
|
+
* Value shape
|
|
68
|
+
* -----------
|
|
69
|
+
* Each entry is a `VariableValue[]` — an array of `[value, mediaCondition?]` tuples.
|
|
70
|
+
* Bloom's preset vars are unconditional, so each is a single-element `[[value]]`, e.g.
|
|
71
|
+
* `rootVariables('primary').set([['205 87% 53%']])`. This is the same shape the compiler
|
|
72
|
+
* emits for unconditional `:root` vars.
|
|
73
|
+
*
|
|
74
|
+
* This is native-only and additive: the `VariableContextProvider` wrapper stays (it is
|
|
75
|
+
* the correct, scoped mechanism for `BloomColorScope` subtree overrides and harmlessly
|
|
76
|
+
* covers direct descendants). The web fork (`native-root-vars.web.ts`) no-ops — web
|
|
77
|
+
* writes the same vars to `document.documentElement` via `applyColorPresetVars`.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Write the preset's CSS vars to react-native-css's global `rootVariables` family
|
|
82
|
+
* so the whole native tree (navigator screens + portals/modals/bottom-sheets)
|
|
83
|
+
* resolves the active palette.
|
|
84
|
+
*
|
|
85
|
+
* Each `.set` notifies its own observers synchronously (react-native-css only
|
|
86
|
+
* batches notifications inside its own `StyleCollection.inject`; outside it,
|
|
87
|
+
* `observableBatch.current` is unset so every `.set` runs observers immediately),
|
|
88
|
+
* so sequential writes correctly trigger a re-render when the preset/mode changes.
|
|
89
|
+
*
|
|
90
|
+
* Defensive guard: if a host ships a react-native-css build that doesn't expose
|
|
91
|
+
* `rootVariables` as a callable (it always does on @3), we bail rather than throw.
|
|
92
|
+
*/
|
|
93
|
+
export function applyNativeRootVars(colorPreset: AppColorName, mode: 'light' | 'dark'): void {
|
|
94
|
+
if (typeof rootVariables !== 'function') return;
|
|
95
|
+
|
|
96
|
+
const vars = buildScopeVars(colorPreset, mode);
|
|
97
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
98
|
+
// The family is keyed by the bare name; `buildScopeVars` keys include `--`.
|
|
99
|
+
const name = key.startsWith('--') ? key.slice(2) : key;
|
|
100
|
+
rootVariables(name).set([[value]]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AppColorName } from './color-presets';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web fork of `applyNativeRootVars` — a no-op.
|
|
5
|
+
*
|
|
6
|
+
* On web, `BloomThemeProvider` already writes the active preset's CSS vars to
|
|
7
|
+
* `document.documentElement` via `applyColorPresetVars`, which the browser /
|
|
8
|
+
* react-native-web resolve natively. The native/default variant — the plain
|
|
9
|
+
* sibling `native-root-vars.ts` — instead publishes those vars into
|
|
10
|
+
* react-native-css's GLOBAL `rootVariables` family.
|
|
11
|
+
*
|
|
12
|
+
* Keeping the native variant's `react-native-css/native-internal` import out of
|
|
13
|
+
* the web bundle is the whole reason this is a platform-split module: web (and
|
|
14
|
+
* any non-NativeWind host) picks this `.web` fork over the plain file and so
|
|
15
|
+
* never statically pulls react-native-css internals.
|
|
16
|
+
*
|
|
17
|
+
* The signature is intentionally identical to the plain variant so the import
|
|
18
|
+
* site in `BloomThemeProvider` is platform-agnostic.
|
|
19
|
+
*/
|
|
20
|
+
export function applyNativeRootVars(_colorPreset: AppColorName, _mode: 'light' | 'dark'): void {
|
|
21
|
+
// Intentionally empty — web applies preset vars to `document.documentElement`.
|
|
22
|
+
}
|
package/src/theme/preset-vars.ts
CHANGED
|
@@ -67,7 +67,10 @@ export function getPresetVars(
|
|
|
67
67
|
|
|
68
68
|
const extended: PresetTokens = {
|
|
69
69
|
...base,
|
|
70
|
-
|
|
70
|
+
// Light cards carry the same faint preset tint as `--popover` (H 12% 99%)
|
|
71
|
+
// so they read as part of the preset family rather than a pure-white slab —
|
|
72
|
+
// mirroring how dark cards (H 30% 10%) carry the accent hue into near-black.
|
|
73
|
+
'--card': isDark ? `${hue} 30% 10%` : `${hue} 12% 99%`,
|
|
71
74
|
'--card-foreground': foreground,
|
|
72
75
|
'--chart-1': `${hue} ${sat}% 85%`,
|
|
73
76
|
'--chart-2': `${hue} ${sat}% 75%`,
|