@oxyhq/bloom 0.7.4 → 0.7.6
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/theme/native-root-vars.js +32 -100
- package/lib/commonjs/theme/native-root-vars.js.map +1 -1
- package/lib/commonjs/theme/native-root-vars.native.js +127 -0
- package/lib/commonjs/theme/native-root-vars.native.js.map +1 -0
- package/lib/module/theme/native-root-vars.js +32 -100
- package/lib/module/theme/native-root-vars.js.map +1 -1
- package/lib/module/theme/native-root-vars.native.js +122 -0
- package/lib/module/theme/native-root-vars.native.js.map +1 -0
- package/lib/typescript/commonjs/theme/native-root-vars.d.ts +30 -90
- package/lib/typescript/commonjs/theme/native-root-vars.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/native-root-vars.native.d.ts +94 -0
- package/lib/typescript/commonjs/theme/native-root-vars.native.d.ts.map +1 -0
- package/lib/typescript/module/theme/native-root-vars.d.ts +30 -90
- package/lib/typescript/module/theme/native-root-vars.d.ts.map +1 -1
- package/lib/typescript/module/theme/native-root-vars.native.d.ts +94 -0
- package/lib/typescript/module/theme/native-root-vars.native.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/native-root-vars.test.ts +30 -4
- package/src/theme/native-root-vars.native.ts +123 -0
- package/src/theme/native-root-vars.ts +32 -102
|
@@ -1,94 +1,34 @@
|
|
|
1
1
|
import { type AppColorName } from './color-presets';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* The raw tokens are written as HSL triples (`primary: '205 87% 53%'`) and the
|
|
33
|
-
* resolved Tailwind v4 `--color-*` vars as sRGB `rgb(...)` (`color-primary:
|
|
34
|
-
* 'rgb(31 153 239)'`) — the latter so `color-mix`-based alpha utilities resolve
|
|
35
|
-
* on native (see `getPresetVars` / `hslTripletToRgb`).
|
|
36
|
-
*
|
|
37
|
-
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
38
|
-
* ---------------------------------------------------------
|
|
39
|
-
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
40
|
-
* Metro bundles BOTH. In `native-internal/root.js` the variable families are plain
|
|
41
|
-
* module-local consts — NOT `globalThis`-guarded the way `StyleCollection` is — so the
|
|
42
|
-
* commonjs `root.js` and the module `root.js` each instantiate their OWN separate
|
|
43
|
-
* `rootVariables` family. The react-native-css renderer (`react-native-css/src/components/View.tsx`
|
|
44
|
-
* → `varResolver`) imports its `root.js` via ESM `import`, i.e. the MODULE build. A
|
|
45
|
-
* runtime `require('react-native-css/native-internal')` resolves the package's `require`
|
|
46
|
-
* export condition → the COMMONJS build → a DIFFERENT family the renderer never
|
|
47
|
-
* subscribes to, so the writes are a silent no-op on device. A static top-level
|
|
48
|
-
* `import` resolves the `import` condition → the MODULE build → the renderer's instance.
|
|
49
|
-
*
|
|
50
|
-
* This plain file is the NATIVE/default variant (Metro selects it on iOS/Android,
|
|
51
|
-
* which have no `.native` override here); the web variant lives in the sibling
|
|
52
|
-
* `native-root-vars.web.ts` no-op, which web bundlers pick over this one. So the
|
|
53
|
-
* static `react-native-css/native-internal` import below is never pulled into a web
|
|
54
|
-
* bundle — only into native. This mirrors Bloom's existing platform-split convention
|
|
55
|
-
* (`color-scope/index.tsx` + `color-scope/index.web.tsx`, `FontLoader.native.tsx`).
|
|
56
|
-
*
|
|
57
|
-
* Keying contract (verified against react-native-css@3.0.7)
|
|
58
|
-
* ---------------------------------------------------------
|
|
59
|
-
* The `rootVariables` family is keyed by the BARE variable name, WITHOUT the leading
|
|
60
|
-
* `--`. The compiler strips it uniformly: a `:root { --primary: ... }` declaration is
|
|
61
|
-
* stored via `rule.v.push([property.slice(2), value])` then routed into
|
|
62
|
-
* `shared.rootVariables[name]`, and `@property --x` goes through
|
|
63
|
-
* `name.startsWith("--") ? name.slice(2) : name`. The lookup side matches: a `var(--x)`
|
|
64
|
-
* reference compiles to `[{}, "var", ident.slice(2)]`, so `varResolver` looks up the
|
|
65
|
-
* bare name. `buildScopeVars` returns keys WITH the `--` prefix, so we strip it before
|
|
66
|
-
* writing each entry.
|
|
67
|
-
*
|
|
68
|
-
* Value shape
|
|
69
|
-
* -----------
|
|
70
|
-
* Each entry is a `VariableValue[]` — an array of `[value, mediaCondition?]` tuples.
|
|
71
|
-
* Bloom's preset vars are unconditional, so each is a single-element `[[value]]`, e.g.
|
|
72
|
-
* `rootVariables('primary').set([['205 87% 53%']])`. This is the same shape the compiler
|
|
73
|
-
* emits for unconditional `:root` vars.
|
|
74
|
-
*
|
|
75
|
-
* This is native-only and additive: the `VariableContextProvider` wrapper stays (it is
|
|
76
|
-
* the correct, scoped mechanism for `BloomColorScope` subtree overrides and harmlessly
|
|
77
|
-
* covers direct descendants). The web fork (`native-root-vars.web.ts`) no-ops — web
|
|
78
|
-
* writes the same vars to `document.documentElement` via `applyColorPresetVars`.
|
|
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.
|
|
3
|
+
* Platform-neutral DEFAULT variant of `applyNativeRootVars` — a no-op.
|
|
4
|
+
*
|
|
5
|
+
* This is the file resolved by every bundler / type-checker that does NOT do
|
|
6
|
+
* React Native's platform-extension resolution:
|
|
7
|
+
* - a consumer's `tsc` (resolving Bloom's `"react-native"` -> `./src/...` source
|
|
8
|
+
* export condition: `theme/index.ts` -> `BloomThemeProvider` -> this import);
|
|
9
|
+
* - non-Metro web bundlers (Vite/Rolldown, webpack) resolving the package
|
|
10
|
+
* `exports` `import`/`require` conditions to `lib/.../native-root-vars.js`.
|
|
11
|
+
*
|
|
12
|
+
* It deliberately does NOT import `react-native-css/native-internal`. That subpath
|
|
13
|
+
* is native-only: it has no web build, and react-native-css is not even a Bloom
|
|
14
|
+
* dependency. Statically importing it from a file a web bundler resolves breaks
|
|
15
|
+
* module resolution outright (the original report: `Rolldown failed to resolve
|
|
16
|
+
* import "react-native-css/native-internal" from .../native-root-vars.js`).
|
|
17
|
+
* Importing it from a file a consumer's `tsc` resolves breaks type-check (TS2307).
|
|
18
|
+
*
|
|
19
|
+
* Confining the real implementation (and that import) to the `.native` sibling —
|
|
20
|
+
* `native-root-vars.native.ts`, which ONLY Metro selects — keeps both web bundling
|
|
21
|
+
* AND downstream `tsc` green, while native still publishes the preset vars into
|
|
22
|
+
* react-native-css's GLOBAL `rootVariables` family so the whole native tree
|
|
23
|
+
* (navigator screens + portals/modals) resolves the palette.
|
|
24
|
+
*
|
|
25
|
+
* The other variants:
|
|
26
|
+
* - `native-root-vars.native.ts` — iOS/Android (Metro), the real implementation;
|
|
27
|
+
* - `native-root-vars.web.ts` — web, also a no-op (web writes the same vars to
|
|
28
|
+
* `document.documentElement` via `applyColorPresetVars` instead).
|
|
29
|
+
*
|
|
30
|
+
* The signature is intentionally identical to those variants so the import site in
|
|
31
|
+
* `BloomThemeProvider` is platform-agnostic.
|
|
92
32
|
*/
|
|
93
|
-
export declare function applyNativeRootVars(
|
|
33
|
+
export declare function applyNativeRootVars(_colorPreset: AppColorName, _mode: 'light' | 'dark'): void;
|
|
94
34
|
//# sourceMappingURL=native-root-vars.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG7F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type AppColorName } from './color-presets';
|
|
2
|
+
/**
|
|
3
|
+
* Publish the active color preset's CSS custom properties into react-native-css's
|
|
4
|
+
* GLOBAL root-variable family so they reach the ENTIRE native app tree — including
|
|
5
|
+
* content rendered outside the React subtree of `BloomThemeProvider`: expo-router
|
|
6
|
+
* navigator screens, `Portal`s, `Dialog`/`BottomSheet` overlays, and any other host
|
|
7
|
+
* that paints through a separate React root.
|
|
8
|
+
*
|
|
9
|
+
* Why a global write is required (native only)
|
|
10
|
+
* --------------------------------------------
|
|
11
|
+
* react-native-css resolves a `var(--x)` reference (its `varResolver`) in this order:
|
|
12
|
+
* 1. `name in inheritedVariables` — the React-context-inherited vars. This is what
|
|
13
|
+
* `VariableContextProvider` populates, but it is React-context-scoped, so it only
|
|
14
|
+
* reaches *direct descendants* of the provider in the React tree.
|
|
15
|
+
* 2. `inlineVariables[name]` — same-component inline vars.
|
|
16
|
+
* 3. `variables[name]` — resolved inherited vars.
|
|
17
|
+
* 4. `universalVariables(name)` — a GLOBAL observable family.
|
|
18
|
+
* 5. `rootVariables(name)` — a GLOBAL observable family.
|
|
19
|
+
* 6. the declared fallback.
|
|
20
|
+
*
|
|
21
|
+
* `BloomThemeProvider`'s `VariableContextProvider` only feeds path #1, so the navigator
|
|
22
|
+
* host and every portal/modal — which render outside that subtree — never see the
|
|
23
|
+
* preset vars and fall through to `rootVariables`/`universalVariables`. By default those
|
|
24
|
+
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
25
|
+
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
26
|
+
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
27
|
+
* navigator renders monochrome. Writing the vars into `rootVariables` here is the
|
|
28
|
+
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
29
|
+
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
30
|
+
* content resolves the palette identically regardless of React-tree position.
|
|
31
|
+
*
|
|
32
|
+
* The raw tokens are written as HSL triples (`primary: '205 87% 53%'`) and the
|
|
33
|
+
* resolved Tailwind v4 `--color-*` vars as sRGB `rgb(...)` (`color-primary:
|
|
34
|
+
* 'rgb(31 153 239)'`) — the latter so `color-mix`-based alpha utilities resolve
|
|
35
|
+
* on native (see `getPresetVars` / `hslTripletToRgb`).
|
|
36
|
+
*
|
|
37
|
+
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
38
|
+
* ---------------------------------------------------------
|
|
39
|
+
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
40
|
+
* Metro bundles BOTH. In `native-internal/root.js` the variable families are plain
|
|
41
|
+
* module-local consts — NOT `globalThis`-guarded the way `StyleCollection` is — so the
|
|
42
|
+
* commonjs `root.js` and the module `root.js` each instantiate their OWN separate
|
|
43
|
+
* `rootVariables` family. The react-native-css renderer (`react-native-css/src/components/View.tsx`
|
|
44
|
+
* → `varResolver`) imports its `root.js` via ESM `import`, i.e. the MODULE build. A
|
|
45
|
+
* runtime `require('react-native-css/native-internal')` resolves the package's `require`
|
|
46
|
+
* export condition → the COMMONJS build → a DIFFERENT family the renderer never
|
|
47
|
+
* subscribes to, so the writes are a silent no-op on device. A static top-level
|
|
48
|
+
* `import` resolves the `import` condition → the MODULE build → the renderer's instance.
|
|
49
|
+
*
|
|
50
|
+
* This plain file is the NATIVE/default variant (Metro selects it on iOS/Android,
|
|
51
|
+
* which have no `.native` override here); the web variant lives in the sibling
|
|
52
|
+
* `native-root-vars.web.ts` no-op, which web bundlers pick over this one. So the
|
|
53
|
+
* static `react-native-css/native-internal` import below is never pulled into a web
|
|
54
|
+
* bundle — only into native. This mirrors Bloom's existing platform-split convention
|
|
55
|
+
* (`color-scope/index.tsx` + `color-scope/index.web.tsx`, `FontLoader.native.tsx`).
|
|
56
|
+
*
|
|
57
|
+
* Keying contract (verified against react-native-css@3.0.7)
|
|
58
|
+
* ---------------------------------------------------------
|
|
59
|
+
* The `rootVariables` family is keyed by the BARE variable name, WITHOUT the leading
|
|
60
|
+
* `--`. The compiler strips it uniformly: a `:root { --primary: ... }` declaration is
|
|
61
|
+
* stored via `rule.v.push([property.slice(2), value])` then routed into
|
|
62
|
+
* `shared.rootVariables[name]`, and `@property --x` goes through
|
|
63
|
+
* `name.startsWith("--") ? name.slice(2) : name`. The lookup side matches: a `var(--x)`
|
|
64
|
+
* reference compiles to `[{}, "var", ident.slice(2)]`, so `varResolver` looks up the
|
|
65
|
+
* bare name. `buildScopeVars` returns keys WITH the `--` prefix, so we strip it before
|
|
66
|
+
* writing each entry.
|
|
67
|
+
*
|
|
68
|
+
* Value shape
|
|
69
|
+
* -----------
|
|
70
|
+
* Each entry is a `VariableValue[]` — an array of `[value, mediaCondition?]` tuples.
|
|
71
|
+
* Bloom's preset vars are unconditional, so each is a single-element `[[value]]`, e.g.
|
|
72
|
+
* `rootVariables('primary').set([['205 87% 53%']])`. This is the same shape the compiler
|
|
73
|
+
* emits for unconditional `:root` vars.
|
|
74
|
+
*
|
|
75
|
+
* This is native-only and additive: the `VariableContextProvider` wrapper stays (it is
|
|
76
|
+
* the correct, scoped mechanism for `BloomColorScope` subtree overrides and harmlessly
|
|
77
|
+
* covers direct descendants). The web fork (`native-root-vars.web.ts`) no-ops — web
|
|
78
|
+
* writes the same vars to `document.documentElement` via `applyColorPresetVars`.
|
|
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 declare function applyNativeRootVars(colorPreset: AppColorName, mode: 'light' | 'dark'): void;
|
|
94
|
+
//# sourceMappingURL=native-root-vars.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-root-vars.native.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.native.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAS3F"}
|
|
@@ -1,94 +1,34 @@
|
|
|
1
1
|
import { type AppColorName } from './color-presets';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* The raw tokens are written as HSL triples (`primary: '205 87% 53%'`) and the
|
|
33
|
-
* resolved Tailwind v4 `--color-*` vars as sRGB `rgb(...)` (`color-primary:
|
|
34
|
-
* 'rgb(31 153 239)'`) — the latter so `color-mix`-based alpha utilities resolve
|
|
35
|
-
* on native (see `getPresetVars` / `hslTripletToRgb`).
|
|
36
|
-
*
|
|
37
|
-
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
38
|
-
* ---------------------------------------------------------
|
|
39
|
-
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
40
|
-
* Metro bundles BOTH. In `native-internal/root.js` the variable families are plain
|
|
41
|
-
* module-local consts — NOT `globalThis`-guarded the way `StyleCollection` is — so the
|
|
42
|
-
* commonjs `root.js` and the module `root.js` each instantiate their OWN separate
|
|
43
|
-
* `rootVariables` family. The react-native-css renderer (`react-native-css/src/components/View.tsx`
|
|
44
|
-
* → `varResolver`) imports its `root.js` via ESM `import`, i.e. the MODULE build. A
|
|
45
|
-
* runtime `require('react-native-css/native-internal')` resolves the package's `require`
|
|
46
|
-
* export condition → the COMMONJS build → a DIFFERENT family the renderer never
|
|
47
|
-
* subscribes to, so the writes are a silent no-op on device. A static top-level
|
|
48
|
-
* `import` resolves the `import` condition → the MODULE build → the renderer's instance.
|
|
49
|
-
*
|
|
50
|
-
* This plain file is the NATIVE/default variant (Metro selects it on iOS/Android,
|
|
51
|
-
* which have no `.native` override here); the web variant lives in the sibling
|
|
52
|
-
* `native-root-vars.web.ts` no-op, which web bundlers pick over this one. So the
|
|
53
|
-
* static `react-native-css/native-internal` import below is never pulled into a web
|
|
54
|
-
* bundle — only into native. This mirrors Bloom's existing platform-split convention
|
|
55
|
-
* (`color-scope/index.tsx` + `color-scope/index.web.tsx`, `FontLoader.native.tsx`).
|
|
56
|
-
*
|
|
57
|
-
* Keying contract (verified against react-native-css@3.0.7)
|
|
58
|
-
* ---------------------------------------------------------
|
|
59
|
-
* The `rootVariables` family is keyed by the BARE variable name, WITHOUT the leading
|
|
60
|
-
* `--`. The compiler strips it uniformly: a `:root { --primary: ... }` declaration is
|
|
61
|
-
* stored via `rule.v.push([property.slice(2), value])` then routed into
|
|
62
|
-
* `shared.rootVariables[name]`, and `@property --x` goes through
|
|
63
|
-
* `name.startsWith("--") ? name.slice(2) : name`. The lookup side matches: a `var(--x)`
|
|
64
|
-
* reference compiles to `[{}, "var", ident.slice(2)]`, so `varResolver` looks up the
|
|
65
|
-
* bare name. `buildScopeVars` returns keys WITH the `--` prefix, so we strip it before
|
|
66
|
-
* writing each entry.
|
|
67
|
-
*
|
|
68
|
-
* Value shape
|
|
69
|
-
* -----------
|
|
70
|
-
* Each entry is a `VariableValue[]` — an array of `[value, mediaCondition?]` tuples.
|
|
71
|
-
* Bloom's preset vars are unconditional, so each is a single-element `[[value]]`, e.g.
|
|
72
|
-
* `rootVariables('primary').set([['205 87% 53%']])`. This is the same shape the compiler
|
|
73
|
-
* emits for unconditional `:root` vars.
|
|
74
|
-
*
|
|
75
|
-
* This is native-only and additive: the `VariableContextProvider` wrapper stays (it is
|
|
76
|
-
* the correct, scoped mechanism for `BloomColorScope` subtree overrides and harmlessly
|
|
77
|
-
* covers direct descendants). The web fork (`native-root-vars.web.ts`) no-ops — web
|
|
78
|
-
* writes the same vars to `document.documentElement` via `applyColorPresetVars`.
|
|
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.
|
|
3
|
+
* Platform-neutral DEFAULT variant of `applyNativeRootVars` — a no-op.
|
|
4
|
+
*
|
|
5
|
+
* This is the file resolved by every bundler / type-checker that does NOT do
|
|
6
|
+
* React Native's platform-extension resolution:
|
|
7
|
+
* - a consumer's `tsc` (resolving Bloom's `"react-native"` -> `./src/...` source
|
|
8
|
+
* export condition: `theme/index.ts` -> `BloomThemeProvider` -> this import);
|
|
9
|
+
* - non-Metro web bundlers (Vite/Rolldown, webpack) resolving the package
|
|
10
|
+
* `exports` `import`/`require` conditions to `lib/.../native-root-vars.js`.
|
|
11
|
+
*
|
|
12
|
+
* It deliberately does NOT import `react-native-css/native-internal`. That subpath
|
|
13
|
+
* is native-only: it has no web build, and react-native-css is not even a Bloom
|
|
14
|
+
* dependency. Statically importing it from a file a web bundler resolves breaks
|
|
15
|
+
* module resolution outright (the original report: `Rolldown failed to resolve
|
|
16
|
+
* import "react-native-css/native-internal" from .../native-root-vars.js`).
|
|
17
|
+
* Importing it from a file a consumer's `tsc` resolves breaks type-check (TS2307).
|
|
18
|
+
*
|
|
19
|
+
* Confining the real implementation (and that import) to the `.native` sibling —
|
|
20
|
+
* `native-root-vars.native.ts`, which ONLY Metro selects — keeps both web bundling
|
|
21
|
+
* AND downstream `tsc` green, while native still publishes the preset vars into
|
|
22
|
+
* react-native-css's GLOBAL `rootVariables` family so the whole native tree
|
|
23
|
+
* (navigator screens + portals/modals) resolves the palette.
|
|
24
|
+
*
|
|
25
|
+
* The other variants:
|
|
26
|
+
* - `native-root-vars.native.ts` — iOS/Android (Metro), the real implementation;
|
|
27
|
+
* - `native-root-vars.web.ts` — web, also a no-op (web writes the same vars to
|
|
28
|
+
* `document.documentElement` via `applyColorPresetVars` instead).
|
|
29
|
+
*
|
|
30
|
+
* The signature is intentionally identical to those variants so the import site in
|
|
31
|
+
* `BloomThemeProvider` is platform-agnostic.
|
|
92
32
|
*/
|
|
93
|
-
export declare function applyNativeRootVars(
|
|
33
|
+
export declare function applyNativeRootVars(_colorPreset: AppColorName, _mode: 'light' | 'dark'): void;
|
|
94
34
|
//# sourceMappingURL=native-root-vars.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG7F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type AppColorName } from './color-presets';
|
|
2
|
+
/**
|
|
3
|
+
* Publish the active color preset's CSS custom properties into react-native-css's
|
|
4
|
+
* GLOBAL root-variable family so they reach the ENTIRE native app tree — including
|
|
5
|
+
* content rendered outside the React subtree of `BloomThemeProvider`: expo-router
|
|
6
|
+
* navigator screens, `Portal`s, `Dialog`/`BottomSheet` overlays, and any other host
|
|
7
|
+
* that paints through a separate React root.
|
|
8
|
+
*
|
|
9
|
+
* Why a global write is required (native only)
|
|
10
|
+
* --------------------------------------------
|
|
11
|
+
* react-native-css resolves a `var(--x)` reference (its `varResolver`) in this order:
|
|
12
|
+
* 1. `name in inheritedVariables` — the React-context-inherited vars. This is what
|
|
13
|
+
* `VariableContextProvider` populates, but it is React-context-scoped, so it only
|
|
14
|
+
* reaches *direct descendants* of the provider in the React tree.
|
|
15
|
+
* 2. `inlineVariables[name]` — same-component inline vars.
|
|
16
|
+
* 3. `variables[name]` — resolved inherited vars.
|
|
17
|
+
* 4. `universalVariables(name)` — a GLOBAL observable family.
|
|
18
|
+
* 5. `rootVariables(name)` — a GLOBAL observable family.
|
|
19
|
+
* 6. the declared fallback.
|
|
20
|
+
*
|
|
21
|
+
* `BloomThemeProvider`'s `VariableContextProvider` only feeds path #1, so the navigator
|
|
22
|
+
* host and every portal/modal — which render outside that subtree — never see the
|
|
23
|
+
* preset vars and fall through to `rootVariables`/`universalVariables`. By default those
|
|
24
|
+
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
25
|
+
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
26
|
+
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
27
|
+
* navigator renders monochrome. Writing the vars into `rootVariables` here is the
|
|
28
|
+
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
29
|
+
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
30
|
+
* content resolves the palette identically regardless of React-tree position.
|
|
31
|
+
*
|
|
32
|
+
* The raw tokens are written as HSL triples (`primary: '205 87% 53%'`) and the
|
|
33
|
+
* resolved Tailwind v4 `--color-*` vars as sRGB `rgb(...)` (`color-primary:
|
|
34
|
+
* 'rgb(31 153 239)'`) — the latter so `color-mix`-based alpha utilities resolve
|
|
35
|
+
* on native (see `getPresetVars` / `hslTripletToRgb`).
|
|
36
|
+
*
|
|
37
|
+
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
38
|
+
* ---------------------------------------------------------
|
|
39
|
+
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
40
|
+
* Metro bundles BOTH. In `native-internal/root.js` the variable families are plain
|
|
41
|
+
* module-local consts — NOT `globalThis`-guarded the way `StyleCollection` is — so the
|
|
42
|
+
* commonjs `root.js` and the module `root.js` each instantiate their OWN separate
|
|
43
|
+
* `rootVariables` family. The react-native-css renderer (`react-native-css/src/components/View.tsx`
|
|
44
|
+
* → `varResolver`) imports its `root.js` via ESM `import`, i.e. the MODULE build. A
|
|
45
|
+
* runtime `require('react-native-css/native-internal')` resolves the package's `require`
|
|
46
|
+
* export condition → the COMMONJS build → a DIFFERENT family the renderer never
|
|
47
|
+
* subscribes to, so the writes are a silent no-op on device. A static top-level
|
|
48
|
+
* `import` resolves the `import` condition → the MODULE build → the renderer's instance.
|
|
49
|
+
*
|
|
50
|
+
* This plain file is the NATIVE/default variant (Metro selects it on iOS/Android,
|
|
51
|
+
* which have no `.native` override here); the web variant lives in the sibling
|
|
52
|
+
* `native-root-vars.web.ts` no-op, which web bundlers pick over this one. So the
|
|
53
|
+
* static `react-native-css/native-internal` import below is never pulled into a web
|
|
54
|
+
* bundle — only into native. This mirrors Bloom's existing platform-split convention
|
|
55
|
+
* (`color-scope/index.tsx` + `color-scope/index.web.tsx`, `FontLoader.native.tsx`).
|
|
56
|
+
*
|
|
57
|
+
* Keying contract (verified against react-native-css@3.0.7)
|
|
58
|
+
* ---------------------------------------------------------
|
|
59
|
+
* The `rootVariables` family is keyed by the BARE variable name, WITHOUT the leading
|
|
60
|
+
* `--`. The compiler strips it uniformly: a `:root { --primary: ... }` declaration is
|
|
61
|
+
* stored via `rule.v.push([property.slice(2), value])` then routed into
|
|
62
|
+
* `shared.rootVariables[name]`, and `@property --x` goes through
|
|
63
|
+
* `name.startsWith("--") ? name.slice(2) : name`. The lookup side matches: a `var(--x)`
|
|
64
|
+
* reference compiles to `[{}, "var", ident.slice(2)]`, so `varResolver` looks up the
|
|
65
|
+
* bare name. `buildScopeVars` returns keys WITH the `--` prefix, so we strip it before
|
|
66
|
+
* writing each entry.
|
|
67
|
+
*
|
|
68
|
+
* Value shape
|
|
69
|
+
* -----------
|
|
70
|
+
* Each entry is a `VariableValue[]` — an array of `[value, mediaCondition?]` tuples.
|
|
71
|
+
* Bloom's preset vars are unconditional, so each is a single-element `[[value]]`, e.g.
|
|
72
|
+
* `rootVariables('primary').set([['205 87% 53%']])`. This is the same shape the compiler
|
|
73
|
+
* emits for unconditional `:root` vars.
|
|
74
|
+
*
|
|
75
|
+
* This is native-only and additive: the `VariableContextProvider` wrapper stays (it is
|
|
76
|
+
* the correct, scoped mechanism for `BloomColorScope` subtree overrides and harmlessly
|
|
77
|
+
* covers direct descendants). The web fork (`native-root-vars.web.ts`) no-ops — web
|
|
78
|
+
* writes the same vars to `document.documentElement` via `applyColorPresetVars`.
|
|
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 declare function applyNativeRootVars(colorPreset: AppColorName, mode: 'light' | 'dark'): void;
|
|
94
|
+
//# sourceMappingURL=native-root-vars.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-root-vars.native.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.native.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAS3F"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
type SetCall = ReadonlyArray<readonly [string]>;
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Verifies the native
|
|
4
|
+
* Verifies the native variant `theme/native-root-vars.native.ts` publishes the
|
|
5
5
|
* active preset into react-native-css's GLOBAL `rootVariables` family with the
|
|
6
6
|
* exact keying and value shape react-native-css itself uses for compiled `:root`
|
|
7
|
-
* vars, and that the
|
|
7
|
+
* vars, and that BOTH the platform-neutral default (`theme/native-root-vars.ts`)
|
|
8
|
+
* and the web fork (`theme/native-root-vars.web.ts`) are inert no-ops.
|
|
8
9
|
*
|
|
9
10
|
* - keys are written WITHOUT the leading `--` (the family is keyed by the bare
|
|
10
11
|
* name — confirmed against react-native-css@3.0.7's compiler, which stores
|
|
@@ -12,6 +13,11 @@ type SetCall = ReadonlyArray<readonly [string]>;
|
|
|
12
13
|
* - each value is a single-element value-array `[[value]]` (`VariableValue[]`);
|
|
13
14
|
* - the native variant reaches react-native-css via a STATIC ESM import (so
|
|
14
15
|
* Metro resolves the `module` build — the SAME family the renderer reads);
|
|
16
|
+
* - the default variant never imports react-native-css and writes nothing — it
|
|
17
|
+
* is what `tsc` and non-Metro web bundlers (Vite/Rolldown) resolve, so
|
|
18
|
+
* confining the `react-native-css/native-internal` import to the `.native`
|
|
19
|
+
* variant keeps web bundling resolvable AND a NativeWind-4 consumer's `tsc`
|
|
20
|
+
* from failing with TS2307;
|
|
15
21
|
* - the web variant never imports react-native-css and writes nothing.
|
|
16
22
|
*
|
|
17
23
|
* react-native-css is NOT a Bloom dependency (it arrives transitively via the
|
|
@@ -40,7 +46,7 @@ describe('applyNativeRootVars (native variant)', () => {
|
|
|
40
46
|
{ virtual: true },
|
|
41
47
|
);
|
|
42
48
|
|
|
43
|
-
const { applyNativeRootVars } = require('../theme/native-root-vars') as {
|
|
49
|
+
const { applyNativeRootVars } = require('../theme/native-root-vars.native') as {
|
|
44
50
|
applyNativeRootVars: (preset: string, mode: 'light' | 'dark') => void;
|
|
45
51
|
};
|
|
46
52
|
applyNativeRootVars('blue', 'light');
|
|
@@ -81,7 +87,7 @@ describe('applyNativeRootVars (native variant)', () => {
|
|
|
81
87
|
}),
|
|
82
88
|
{ virtual: true },
|
|
83
89
|
);
|
|
84
|
-
const { applyNativeRootVars } = require('../theme/native-root-vars') as {
|
|
90
|
+
const { applyNativeRootVars } = require('../theme/native-root-vars.native') as {
|
|
85
91
|
applyNativeRootVars: (preset: string, mode: 'light' | 'dark') => void;
|
|
86
92
|
};
|
|
87
93
|
applyNativeRootVars('teal', mode);
|
|
@@ -99,10 +105,30 @@ describe('applyNativeRootVars (native variant)', () => {
|
|
|
99
105
|
() => ({ rootVariables: undefined }),
|
|
100
106
|
{ virtual: true },
|
|
101
107
|
);
|
|
108
|
+
const { applyNativeRootVars } = require('../theme/native-root-vars.native') as {
|
|
109
|
+
applyNativeRootVars: (preset: string, mode: 'light' | 'dark') => void;
|
|
110
|
+
};
|
|
111
|
+
expect(() => applyNativeRootVars('blue', 'light')).not.toThrow();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('applyNativeRootVars (default variant - tsc / web-bundler resolution)', () => {
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
jest.resetModules();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('no-ops without importing react-native-css (keeps web bundling + tsc green)', () => {
|
|
122
|
+
// The platform-neutral default is what a consumer's `tsc` and non-Metro web
|
|
123
|
+
// bundlers (Vite/Rolldown) resolve. It must never touch react-native-css.
|
|
124
|
+
// Confining the `react-native-css/native-internal` import to the `.native`
|
|
125
|
+
// sibling fixes both the downstream TS2307 AND the Vite/Rolldown resolve fail.
|
|
126
|
+
jest.isolateModules(() => {
|
|
102
127
|
const { applyNativeRootVars } = require('../theme/native-root-vars') as {
|
|
103
128
|
applyNativeRootVars: (preset: string, mode: 'light' | 'dark') => void;
|
|
104
129
|
};
|
|
105
130
|
expect(() => applyNativeRootVars('blue', 'light')).not.toThrow();
|
|
131
|
+
expect(applyNativeRootVars('blue', 'light')).toBeUndefined();
|
|
106
132
|
});
|
|
107
133
|
});
|
|
108
134
|
});
|