@oxyhq/bloom 0.7.1 → 0.7.2
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/apply-dark-class.js +6 -3
- package/lib/commonjs/theme/apply-dark-class.js.map +1 -1
- package/lib/commonjs/theme/native-root-vars.js +6 -1
- package/lib/commonjs/theme/native-root-vars.js.map +1 -1
- package/lib/commonjs/theme/preset-vars.js +67 -1
- package/lib/commonjs/theme/preset-vars.js.map +1 -1
- package/lib/module/theme/apply-dark-class.js +6 -3
- package/lib/module/theme/apply-dark-class.js.map +1 -1
- package/lib/module/theme/native-root-vars.js +6 -1
- package/lib/module/theme/native-root-vars.js.map +1 -1
- package/lib/module/theme/preset-vars.js +66 -1
- package/lib/module/theme/preset-vars.js.map +1 -1
- package/lib/typescript/commonjs/theme/apply-dark-class.d.ts +6 -3
- package/lib/typescript/commonjs/theme/apply-dark-class.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/native-root-vars.d.ts +6 -1
- package/lib/typescript/commonjs/theme/native-root-vars.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/preset-vars.d.ts +35 -2
- package/lib/typescript/commonjs/theme/preset-vars.d.ts.map +1 -1
- package/lib/typescript/module/theme/apply-dark-class.d.ts +6 -3
- package/lib/typescript/module/theme/apply-dark-class.d.ts.map +1 -1
- package/lib/typescript/module/theme/native-root-vars.d.ts +6 -1
- package/lib/typescript/module/theme/native-root-vars.d.ts.map +1 -1
- package/lib/typescript/module/theme/preset-vars.d.ts +35 -2
- 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 +4 -2
- package/src/__tests__/preset-vars.test.ts +45 -4
- package/src/react-native-css.d.ts +3 -2
- package/src/theme/apply-dark-class.ts +6 -3
- package/src/theme/native-root-vars.ts +6 -1
- package/src/theme/preset-vars.ts +84 -3
|
@@ -19,10 +19,13 @@ function applyDarkClass(resolved) {
|
|
|
19
19
|
* No-op on native — only affects web.
|
|
20
20
|
*
|
|
21
21
|
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
22
|
-
* resolved `--color-*` vars (`--color-primary:
|
|
22
|
+
* resolved `--color-*` vars (`--color-primary: rgb(0 94 102)`) so both
|
|
23
23
|
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
24
|
-
* utilities resolve consistently.
|
|
25
|
-
*
|
|
24
|
+
* utilities resolve consistently. The resolved vars are emitted as `rgb(...)`
|
|
25
|
+
* (not `hsl(...)`) so the alpha utilities (`bg-primary/10`) resolve on native —
|
|
26
|
+
* see `getPresetVars` / `hslTripletToRgb`. Includes extended tokens (card,
|
|
27
|
+
* chart-*, content-area, sidebar-*) so consumer apps don't need to synthesize
|
|
28
|
+
* them.
|
|
26
29
|
*/
|
|
27
30
|
function applyColorPresetVars(preset, resolved) {
|
|
28
31
|
if (_reactNative.Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_colorPresets","_presetVars","applyDarkClass","resolved","Platform","OS","document","documentElement","classList","toggle","applyColorPresetVars","preset","APP_COLOR_PRESETS","vars","getPresetVars","includeResolvedColorVars","root","style","key","value","Object","entries","setProperty"],"sourceRoot":"../../../src","sources":["theme/apply-dark-class.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAEO,SAASG,cAAcA,CAACC,QAA0B,EAAE;EACzD,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IAC5DA,QAAQ,CAACC,eAAe,CAACC,SAAS,CAACC,MAAM,CAAC,MAAM,EAAEN,QAAQ,KAAK,MAAM,CAAC;EACxE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,oBAAoBA,CAACC,MAAoB,EAAER,QAA0B,EAAE;EACrF,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EAC9D,IAAI,CAACM,+BAAiB,CAACD,MAAM,CAAC,EAAE;EAEhC,MAAME,IAAI,GAAG,IAAAC,yBAAa,EAACH,MAAM,EAAER,QAAQ,EAAE;IAAEY,wBAAwB,EAAE;EAAK,CAAC,CAAC;EAChF,MAAMC,IAAI,GAAGV,QAAQ,CAACC,eAAe,CAACU,KAAK;EAE3C,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACR,IAAI,CAAC,EAAE;IAC/CG,IAAI,CAACM,WAAW,CAACJ,GAAG,EAAEC,KAAK,CAAC;EAC9B;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_colorPresets","_presetVars","applyDarkClass","resolved","Platform","OS","document","documentElement","classList","toggle","applyColorPresetVars","preset","APP_COLOR_PRESETS","vars","getPresetVars","includeResolvedColorVars","root","style","key","value","Object","entries","setProperty"],"sourceRoot":"../../../src","sources":["theme/apply-dark-class.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAEO,SAASG,cAAcA,CAACC,QAA0B,EAAE;EACzD,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IAC5DA,QAAQ,CAACC,eAAe,CAACC,SAAS,CAACC,MAAM,CAAC,MAAM,EAAEN,QAAQ,KAAK,MAAM,CAAC;EACxE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,oBAAoBA,CAACC,MAAoB,EAAER,QAA0B,EAAE;EACrF,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EAC9D,IAAI,CAACM,+BAAiB,CAACD,MAAM,CAAC,EAAE;EAEhC,MAAME,IAAI,GAAG,IAAAC,yBAAa,EAACH,MAAM,EAAER,QAAQ,EAAE;IAAEY,wBAAwB,EAAE;EAAK,CAAC,CAAC;EAChF,MAAMC,IAAI,GAAGV,QAAQ,CAACC,eAAe,CAACU,KAAK;EAE3C,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACR,IAAI,CAAC,EAAE;IAC/CG,IAAI,CAACM,WAAW,CAACJ,GAAG,EAAEC,KAAK,CAAC;EAC9B;AACF","ignoreList":[]}
|
|
@@ -31,11 +31,16 @@ var _styleBuilder = require("./color-scope/style-builder.js");
|
|
|
31
31
|
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
32
32
|
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
33
33
|
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
34
|
-
* navigator renders monochrome. Writing the
|
|
34
|
+
* navigator renders monochrome. Writing the vars into `rootVariables` here is the
|
|
35
35
|
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
36
36
|
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
37
37
|
* content resolves the palette identically regardless of React-tree position.
|
|
38
38
|
*
|
|
39
|
+
* The raw tokens are written as HSL triples (`primary: '205 87% 53%'`) and the
|
|
40
|
+
* resolved Tailwind v4 `--color-*` vars as sRGB `rgb(...)` (`color-primary:
|
|
41
|
+
* 'rgb(31 153 239)'`) — the latter so `color-mix`-based alpha utilities resolve
|
|
42
|
+
* on native (see `getPresetVars` / `hslTripletToRgb`).
|
|
43
|
+
*
|
|
39
44
|
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
40
45
|
* ---------------------------------------------------------
|
|
41
46
|
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_nativeInternal","require","_styleBuilder","applyNativeRootVars","colorPreset","mode","rootVariables","vars","buildScopeVars","key","value","Object","entries","name","startsWith","slice","set"],"sourceRoot":"../../../src","sources":["theme/native-root-vars.ts"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,mBAAmBA,CAACC,WAAyB,EAAEC,IAAsB,EAAQ;EAC3F,IAAI,OAAOC,6BAAa,KAAK,UAAU,EAAE;EAEzC,MAAMC,IAAI,GAAG,IAAAC,4BAAc,EAACJ,WAAW,EAAEC,IAAI,CAAC;EAC9C,KAAK,MAAM,CAACI,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,IAAI,CAAC,EAAE;IAC/C;IACA,MAAMM,IAAI,GAAGJ,GAAG,CAACK,UAAU,CAAC,IAAI,CAAC,GAAGL,GAAG,CAACM,KAAK,CAAC,CAAC,CAAC,GAAGN,GAAG;IACtD,IAAAH,6BAAa,EAACO,IAAI,CAAC,CAACG,GAAG,CAAC,CAAC,CAACN,KAAK,CAAC,CAAC,CAAC;EACpC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_nativeInternal","require","_styleBuilder","applyNativeRootVars","colorPreset","mode","rootVariables","vars","buildScopeVars","key","value","Object","entries","name","startsWith","slice","set"],"sourceRoot":"../../../src","sources":["theme/native-root-vars.ts"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,mBAAmBA,CAACC,WAAyB,EAAEC,IAAsB,EAAQ;EAC3F,IAAI,OAAOC,6BAAa,KAAK,UAAU,EAAE;EAEzC,MAAMC,IAAI,GAAG,IAAAC,4BAAc,EAACJ,WAAW,EAAEC,IAAI,CAAC;EAC9C,KAAK,MAAM,CAACI,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,IAAI,CAAC,EAAE;IAC/C;IACA,MAAMM,IAAI,GAAGJ,GAAG,CAACK,UAAU,CAAC,IAAI,CAAC,GAAGL,GAAG,CAACM,KAAK,CAAC,CAAC,CAAC,GAAGN,GAAG;IACtD,IAAAH,6BAAa,EAACO,IAAI,CAAC,CAACG,GAAG,CAAC,CAAC,CAACN,KAAK,CAAC,CAAC,CAAC;EACpC;AACF","ignoreList":[]}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.applyPresetVarsToDocument = applyPresetVarsToDocument;
|
|
7
7
|
exports.getPresetVars = getPresetVars;
|
|
8
|
+
exports.hslTripletToRgb = hslTripletToRgb;
|
|
8
9
|
var _reactNative = require("react-native");
|
|
9
10
|
var _colorPresets = require("./color-presets.js");
|
|
10
11
|
function extractHue(hslVar) {
|
|
@@ -13,6 +14,71 @@ function extractHue(hslVar) {
|
|
|
13
14
|
function extractSat(hslVar) {
|
|
14
15
|
return parseInt(hslVar.split(' ')[1] ?? '0', 10);
|
|
15
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Convert a shadcn-style HSL triple (`'H S% L%'`, optionally with an alpha tail
|
|
20
|
+
* `'H S% L% / A'`) into an sRGB `rgb(...)` string.
|
|
21
|
+
*
|
|
22
|
+
* Why rgb and not hsl (the native alpha-utility bug this fixes)
|
|
23
|
+
* -------------------------------------------------------------
|
|
24
|
+
* Tailwind v4 compiles an alpha-on-theme-color utility (`bg-primary/10`) into a
|
|
25
|
+
* `color-mix(... var(--color-primary) 10%, transparent)` declaration. On native,
|
|
26
|
+
* react-native-css resolves that `color-mix` at runtime via `colorjs.io/fn`, but
|
|
27
|
+
* its `color-mix` implementation registers ONLY the `sRGB`, `P3`, and `OKLab`
|
|
28
|
+
* color spaces — never `HSL`. So if `--color-primary` resolves to an `hsl(...)`
|
|
29
|
+
* string, `parse('hsl(...)')` throws, the mix is swallowed, and the utility
|
|
30
|
+
* silently produces no color. Emitting the resolved var as `rgb(...)` (a space
|
|
31
|
+
* colorjs.io always has registered) makes the alpha utilities resolve on native,
|
|
32
|
+
* matching web. Full (non-alpha) utilities already worked because React Native's
|
|
33
|
+
* native color parser handles `hsl()` directly; only `color-mix` was affected.
|
|
34
|
+
*
|
|
35
|
+
* Output is space-separated channels (`rgb(31 153 239)`), the modern CSS syntax
|
|
36
|
+
* parsed by both `colorjs.io/fn` (with only sRGB/P3/OKLab registered) and
|
|
37
|
+
* react-native-web / browsers. An alpha tail emits `rgb(r g b / a)`, likewise
|
|
38
|
+
* parsed by both.
|
|
39
|
+
*
|
|
40
|
+
* Pure function — standard HSL→sRGB conversion, channels rounded to integers.
|
|
41
|
+
* Tolerates a `deg` suffix on the hue and `%` suffixes on saturation/lightness.
|
|
42
|
+
*/
|
|
43
|
+
function hslTripletToRgb(triplet) {
|
|
44
|
+
const [colorPart, alphaPart] = triplet.split('/').map(part => part.trim());
|
|
45
|
+
const channels = (colorPart ?? '').split(/\s+/).filter(Boolean);
|
|
46
|
+
const hue = parseFloat((channels[0] ?? '0').replace(/deg$/i, ''));
|
|
47
|
+
const sat = parseFloat((channels[1] ?? '0').replace('%', '')) / 100;
|
|
48
|
+
const light = parseFloat((channels[2] ?? '0').replace('%', '')) / 100;
|
|
49
|
+
const h = Number.isFinite(hue) ? hue : 0;
|
|
50
|
+
const s = Number.isFinite(sat) ? sat : 0;
|
|
51
|
+
const l = Number.isFinite(light) ? light : 0;
|
|
52
|
+
const chroma = (1 - Math.abs(2 * l - 1)) * s;
|
|
53
|
+
const huePrime = (h % 360 + 360) % 360 / 60;
|
|
54
|
+
const second = chroma * (1 - Math.abs(huePrime % 2 - 1));
|
|
55
|
+
let r = 0;
|
|
56
|
+
let g = 0;
|
|
57
|
+
let b = 0;
|
|
58
|
+
if (huePrime < 1) {
|
|
59
|
+
[r, g, b] = [chroma, second, 0];
|
|
60
|
+
} else if (huePrime < 2) {
|
|
61
|
+
[r, g, b] = [second, chroma, 0];
|
|
62
|
+
} else if (huePrime < 3) {
|
|
63
|
+
[r, g, b] = [0, chroma, second];
|
|
64
|
+
} else if (huePrime < 4) {
|
|
65
|
+
[r, g, b] = [0, second, chroma];
|
|
66
|
+
} else if (huePrime < 5) {
|
|
67
|
+
[r, g, b] = [second, 0, chroma];
|
|
68
|
+
} else {
|
|
69
|
+
[r, g, b] = [chroma, 0, second];
|
|
70
|
+
}
|
|
71
|
+
const match = l - chroma / 2;
|
|
72
|
+
const red = Math.round((r + match) * 255);
|
|
73
|
+
const green = Math.round((g + match) * 255);
|
|
74
|
+
const blue = Math.round((b + match) * 255);
|
|
75
|
+
if (alphaPart !== undefined && alphaPart !== '') {
|
|
76
|
+
const alpha = alphaPart.endsWith('%') ? parseFloat(alphaPart) / 100 : parseFloat(alphaPart);
|
|
77
|
+
const safeAlpha = Number.isFinite(alpha) ? alpha : 1;
|
|
78
|
+
return `rgb(${red} ${green} ${blue} / ${safeAlpha})`;
|
|
79
|
+
}
|
|
80
|
+
return `rgb(${red} ${green} ${blue})`;
|
|
81
|
+
}
|
|
16
82
|
const RESOLVED_COLOR_MAP = {
|
|
17
83
|
'--background': '--color-background',
|
|
18
84
|
'--foreground': '--color-foreground',
|
|
@@ -79,7 +145,7 @@ function getPresetVars(colorName, mode, options = {}) {
|
|
|
79
145
|
};
|
|
80
146
|
for (const [rawKey, colorKey] of Object.entries(RESOLVED_COLOR_MAP)) {
|
|
81
147
|
const value = extended[rawKey];
|
|
82
|
-
if (value) resolved[colorKey] =
|
|
148
|
+
if (value) resolved[colorKey] = hslTripletToRgb(value);
|
|
83
149
|
}
|
|
84
150
|
return resolved;
|
|
85
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_colorPresets","extractHue","hslVar","parseInt","split","extractSat","RESOLVED_COLOR_MAP","getPresetVars","colorName","mode","options","preset","APP_COLOR_PRESETS","base","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_colorPresets","extractHue","hslVar","parseInt","split","extractSat","hslTripletToRgb","triplet","colorPart","alphaPart","map","part","trim","channels","filter","Boolean","hue","parseFloat","replace","sat","light","h","Number","isFinite","s","l","chroma","Math","abs","huePrime","second","r","g","b","match","red","round","green","blue","undefined","alpha","endsWith","safeAlpha","RESOLVED_COLOR_MAP","getPresetVars","colorName","mode","options","preset","APP_COLOR_PRESETS","base","dark","get","key","primary","foreground","min","isDark","extended","includeResolvedColorVars","resolved","rawKey","colorKey","Object","entries","value","applyPresetVarsToDocument","Platform","OS","document","vars","root","documentElement","style","setProperty"],"sourceRoot":"../../../src","sources":["theme/preset-vars.ts"],"mappings":";;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA,SAASE,UAAUA,CAACC,MAAc,EAAU;EAC1C,OAAOC,QAAQ,CAACD,MAAM,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;AAClD;AAEA,SAASC,UAAUA,CAACH,MAAc,EAAU;EAC1C,OAAOC,QAAQ,CAACD,MAAM,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACC,OAAe,EAAU;EACvD,MAAM,CAACC,SAAS,EAAEC,SAAS,CAAC,GAAGF,OAAO,CAACH,KAAK,CAAC,GAAG,CAAC,CAACM,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACC,IAAI,CAAC,CAAC,CAAC;EAC5E,MAAMC,QAAQ,GAAG,CAACL,SAAS,IAAI,EAAE,EAAEJ,KAAK,CAAC,KAAK,CAAC,CAACU,MAAM,CAACC,OAAO,CAAC;EAE/D,MAAMC,GAAG,GAAGC,UAAU,CAAC,CAACJ,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAEK,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;EACjE,MAAMC,GAAG,GAAGF,UAAU,CAAC,CAACJ,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAEK,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG;EACnE,MAAME,KAAK,GAAGH,UAAU,CAAC,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IAAII,KAAK,EAAEL,QAAQ,CAACE,QAAQ,CAAC,GAAGxD,eAAe,CAAC2D,KAAK,CAAC;EACxD;EACA,OAAOL,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASM,yBAAyBA,CACvCrB,SAAuB,EACvBC,IAAsB,EACtBC,OAA2B,EACrB;EACN,IAAIoB,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EAE9D,MAAMC,IAAI,GAAG1B,aAAa,CAACC,SAAS,EAAEC,IAAI,EAAEC,OAAO,CAAC;EACpD,MAAMwB,IAAI,GAAGF,QAAQ,CAACG,eAAe,CAACC,KAAK;EAC3C,KAAK,MAAM,CAACpB,GAAG,EAAEY,KAAK,CAAC,IAAIF,MAAM,CAACC,OAAO,CAACM,IAAI,CAAC,EAAE;IAC/CC,IAAI,CAACG,WAAW,CAACrB,GAAG,EAAEY,KAAK,CAAC;EAC9B;AACF","ignoreList":[]}
|
|
@@ -14,10 +14,13 @@ export function applyDarkClass(resolved) {
|
|
|
14
14
|
* No-op on native — only affects web.
|
|
15
15
|
*
|
|
16
16
|
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
17
|
-
* resolved `--color-*` vars (`--color-primary:
|
|
17
|
+
* resolved `--color-*` vars (`--color-primary: rgb(0 94 102)`) so both
|
|
18
18
|
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
19
|
-
* utilities resolve consistently.
|
|
20
|
-
*
|
|
19
|
+
* utilities resolve consistently. The resolved vars are emitted as `rgb(...)`
|
|
20
|
+
* (not `hsl(...)`) so the alpha utilities (`bg-primary/10`) resolve on native —
|
|
21
|
+
* see `getPresetVars` / `hslTripletToRgb`. Includes extended tokens (card,
|
|
22
|
+
* chart-*, content-area, sidebar-*) so consumer apps don't need to synthesize
|
|
23
|
+
* them.
|
|
21
24
|
*/
|
|
22
25
|
export function applyColorPresetVars(preset, resolved) {
|
|
23
26
|
if (Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","APP_COLOR_PRESETS","getPresetVars","applyDarkClass","resolved","OS","document","documentElement","classList","toggle","applyColorPresetVars","preset","vars","includeResolvedColorVars","root","style","key","value","Object","entries","setProperty"],"sourceRoot":"../../../src","sources":["theme/apply-dark-class.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,iBAAiB,QAA2B,oBAAiB;AACtE,SAASC,aAAa,QAAQ,kBAAe;AAE7C,OAAO,SAASC,cAAcA,CAACC,QAA0B,EAAE;EACzD,IAAIJ,QAAQ,CAACK,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IAC5DA,QAAQ,CAACC,eAAe,CAACC,SAAS,CAACC,MAAM,CAAC,MAAM,EAAEL,QAAQ,KAAK,MAAM,CAAC;EACxE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,oBAAoBA,CAACC,MAAoB,EAAEP,QAA0B,EAAE;EACrF,IAAIJ,QAAQ,CAACK,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EAC9D,IAAI,CAACL,iBAAiB,CAACU,MAAM,CAAC,EAAE;EAEhC,MAAMC,IAAI,GAAGV,aAAa,CAACS,MAAM,EAAEP,QAAQ,EAAE;IAAES,wBAAwB,EAAE;EAAK,CAAC,CAAC;EAChF,MAAMC,IAAI,GAAGR,QAAQ,CAACC,eAAe,CAACQ,KAAK;EAE3C,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACP,IAAI,CAAC,EAAE;IAC/CE,IAAI,CAACM,WAAW,CAACJ,GAAG,EAAEC,KAAK,CAAC;EAC9B;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["Platform","APP_COLOR_PRESETS","getPresetVars","applyDarkClass","resolved","OS","document","documentElement","classList","toggle","applyColorPresetVars","preset","vars","includeResolvedColorVars","root","style","key","value","Object","entries","setProperty"],"sourceRoot":"../../../src","sources":["theme/apply-dark-class.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,iBAAiB,QAA2B,oBAAiB;AACtE,SAASC,aAAa,QAAQ,kBAAe;AAE7C,OAAO,SAASC,cAAcA,CAACC,QAA0B,EAAE;EACzD,IAAIJ,QAAQ,CAACK,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IAC5DA,QAAQ,CAACC,eAAe,CAACC,SAAS,CAACC,MAAM,CAAC,MAAM,EAAEL,QAAQ,KAAK,MAAM,CAAC;EACxE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,oBAAoBA,CAACC,MAAoB,EAAEP,QAA0B,EAAE;EACrF,IAAIJ,QAAQ,CAACK,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EAC9D,IAAI,CAACL,iBAAiB,CAACU,MAAM,CAAC,EAAE;EAEhC,MAAMC,IAAI,GAAGV,aAAa,CAACS,MAAM,EAAEP,QAAQ,EAAE;IAAES,wBAAwB,EAAE;EAAK,CAAC,CAAC;EAChF,MAAMC,IAAI,GAAGR,QAAQ,CAACC,eAAe,CAACQ,KAAK;EAE3C,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACP,IAAI,CAAC,EAAE;IAC/CE,IAAI,CAACM,WAAW,CAACJ,GAAG,EAAEC,KAAK,CAAC;EAC9B;AACF","ignoreList":[]}
|
|
@@ -27,11 +27,16 @@ import { buildScopeVars } from "./color-scope/style-builder.js";
|
|
|
27
27
|
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
28
28
|
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
29
29
|
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
30
|
-
* navigator renders monochrome. Writing the
|
|
30
|
+
* navigator renders monochrome. Writing the vars into `rootVariables` here is the
|
|
31
31
|
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
32
32
|
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
33
33
|
* content resolves the palette identically regardless of React-tree position.
|
|
34
34
|
*
|
|
35
|
+
* The raw tokens are written as HSL triples (`primary: '205 87% 53%'`) and the
|
|
36
|
+
* resolved Tailwind v4 `--color-*` vars as sRGB `rgb(...)` (`color-primary:
|
|
37
|
+
* 'rgb(31 153 239)'`) — the latter so `color-mix`-based alpha utilities resolve
|
|
38
|
+
* on native (see `getPresetVars` / `hslTripletToRgb`).
|
|
39
|
+
*
|
|
35
40
|
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
36
41
|
* ---------------------------------------------------------
|
|
37
42
|
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["rootVariables","buildScopeVars","applyNativeRootVars","colorPreset","mode","vars","key","value","Object","entries","name","startsWith","slice","set"],"sourceRoot":"../../../src","sources":["theme/native-root-vars.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,kCAAkC;AAEhE,SAASC,cAAc,QAAQ,gCAA6B;AAG5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAACC,WAAyB,EAAEC,IAAsB,EAAQ;EAC3F,IAAI,OAAOJ,aAAa,KAAK,UAAU,EAAE;EAEzC,MAAMK,IAAI,GAAGJ,cAAc,CAACE,WAAW,EAAEC,IAAI,CAAC;EAC9C,KAAK,MAAM,CAACE,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,IAAI,CAAC,EAAE;IAC/C;IACA,MAAMK,IAAI,GAAGJ,GAAG,CAACK,UAAU,CAAC,IAAI,CAAC,GAAGL,GAAG,CAACM,KAAK,CAAC,CAAC,CAAC,GAAGN,GAAG;IACtDN,aAAa,CAACU,IAAI,CAAC,CAACG,GAAG,CAAC,CAAC,CAACN,KAAK,CAAC,CAAC,CAAC;EACpC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["rootVariables","buildScopeVars","applyNativeRootVars","colorPreset","mode","vars","key","value","Object","entries","name","startsWith","slice","set"],"sourceRoot":"../../../src","sources":["theme/native-root-vars.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,kCAAkC;AAEhE,SAASC,cAAc,QAAQ,gCAA6B;AAG5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAACC,WAAyB,EAAEC,IAAsB,EAAQ;EAC3F,IAAI,OAAOJ,aAAa,KAAK,UAAU,EAAE;EAEzC,MAAMK,IAAI,GAAGJ,cAAc,CAACE,WAAW,EAAEC,IAAI,CAAC;EAC9C,KAAK,MAAM,CAACE,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,IAAI,CAAC,EAAE;IAC/C;IACA,MAAMK,IAAI,GAAGJ,GAAG,CAACK,UAAU,CAAC,IAAI,CAAC,GAAGL,GAAG,CAACM,KAAK,CAAC,CAAC,CAAC,GAAGN,GAAG;IACtDN,aAAa,CAACU,IAAI,CAAC,CAACG,GAAG,CAAC,CAAC,CAACN,KAAK,CAAC,CAAC,CAAC;EACpC;AACF","ignoreList":[]}
|
|
@@ -8,6 +8,71 @@ function extractHue(hslVar) {
|
|
|
8
8
|
function extractSat(hslVar) {
|
|
9
9
|
return parseInt(hslVar.split(' ')[1] ?? '0', 10);
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Convert a shadcn-style HSL triple (`'H S% L%'`, optionally with an alpha tail
|
|
14
|
+
* `'H S% L% / A'`) into an sRGB `rgb(...)` string.
|
|
15
|
+
*
|
|
16
|
+
* Why rgb and not hsl (the native alpha-utility bug this fixes)
|
|
17
|
+
* -------------------------------------------------------------
|
|
18
|
+
* Tailwind v4 compiles an alpha-on-theme-color utility (`bg-primary/10`) into a
|
|
19
|
+
* `color-mix(... var(--color-primary) 10%, transparent)` declaration. On native,
|
|
20
|
+
* react-native-css resolves that `color-mix` at runtime via `colorjs.io/fn`, but
|
|
21
|
+
* its `color-mix` implementation registers ONLY the `sRGB`, `P3`, and `OKLab`
|
|
22
|
+
* color spaces — never `HSL`. So if `--color-primary` resolves to an `hsl(...)`
|
|
23
|
+
* string, `parse('hsl(...)')` throws, the mix is swallowed, and the utility
|
|
24
|
+
* silently produces no color. Emitting the resolved var as `rgb(...)` (a space
|
|
25
|
+
* colorjs.io always has registered) makes the alpha utilities resolve on native,
|
|
26
|
+
* matching web. Full (non-alpha) utilities already worked because React Native's
|
|
27
|
+
* native color parser handles `hsl()` directly; only `color-mix` was affected.
|
|
28
|
+
*
|
|
29
|
+
* Output is space-separated channels (`rgb(31 153 239)`), the modern CSS syntax
|
|
30
|
+
* parsed by both `colorjs.io/fn` (with only sRGB/P3/OKLab registered) and
|
|
31
|
+
* react-native-web / browsers. An alpha tail emits `rgb(r g b / a)`, likewise
|
|
32
|
+
* parsed by both.
|
|
33
|
+
*
|
|
34
|
+
* Pure function — standard HSL→sRGB conversion, channels rounded to integers.
|
|
35
|
+
* Tolerates a `deg` suffix on the hue and `%` suffixes on saturation/lightness.
|
|
36
|
+
*/
|
|
37
|
+
export function hslTripletToRgb(triplet) {
|
|
38
|
+
const [colorPart, alphaPart] = triplet.split('/').map(part => part.trim());
|
|
39
|
+
const channels = (colorPart ?? '').split(/\s+/).filter(Boolean);
|
|
40
|
+
const hue = parseFloat((channels[0] ?? '0').replace(/deg$/i, ''));
|
|
41
|
+
const sat = parseFloat((channels[1] ?? '0').replace('%', '')) / 100;
|
|
42
|
+
const light = parseFloat((channels[2] ?? '0').replace('%', '')) / 100;
|
|
43
|
+
const h = Number.isFinite(hue) ? hue : 0;
|
|
44
|
+
const s = Number.isFinite(sat) ? sat : 0;
|
|
45
|
+
const l = Number.isFinite(light) ? light : 0;
|
|
46
|
+
const chroma = (1 - Math.abs(2 * l - 1)) * s;
|
|
47
|
+
const huePrime = (h % 360 + 360) % 360 / 60;
|
|
48
|
+
const second = chroma * (1 - Math.abs(huePrime % 2 - 1));
|
|
49
|
+
let r = 0;
|
|
50
|
+
let g = 0;
|
|
51
|
+
let b = 0;
|
|
52
|
+
if (huePrime < 1) {
|
|
53
|
+
[r, g, b] = [chroma, second, 0];
|
|
54
|
+
} else if (huePrime < 2) {
|
|
55
|
+
[r, g, b] = [second, chroma, 0];
|
|
56
|
+
} else if (huePrime < 3) {
|
|
57
|
+
[r, g, b] = [0, chroma, second];
|
|
58
|
+
} else if (huePrime < 4) {
|
|
59
|
+
[r, g, b] = [0, second, chroma];
|
|
60
|
+
} else if (huePrime < 5) {
|
|
61
|
+
[r, g, b] = [second, 0, chroma];
|
|
62
|
+
} else {
|
|
63
|
+
[r, g, b] = [chroma, 0, second];
|
|
64
|
+
}
|
|
65
|
+
const match = l - chroma / 2;
|
|
66
|
+
const red = Math.round((r + match) * 255);
|
|
67
|
+
const green = Math.round((g + match) * 255);
|
|
68
|
+
const blue = Math.round((b + match) * 255);
|
|
69
|
+
if (alphaPart !== undefined && alphaPart !== '') {
|
|
70
|
+
const alpha = alphaPart.endsWith('%') ? parseFloat(alphaPart) / 100 : parseFloat(alphaPart);
|
|
71
|
+
const safeAlpha = Number.isFinite(alpha) ? alpha : 1;
|
|
72
|
+
return `rgb(${red} ${green} ${blue} / ${safeAlpha})`;
|
|
73
|
+
}
|
|
74
|
+
return `rgb(${red} ${green} ${blue})`;
|
|
75
|
+
}
|
|
11
76
|
const RESOLVED_COLOR_MAP = {
|
|
12
77
|
'--background': '--color-background',
|
|
13
78
|
'--foreground': '--color-foreground',
|
|
@@ -74,7 +139,7 @@ export function getPresetVars(colorName, mode, options = {}) {
|
|
|
74
139
|
};
|
|
75
140
|
for (const [rawKey, colorKey] of Object.entries(RESOLVED_COLOR_MAP)) {
|
|
76
141
|
const value = extended[rawKey];
|
|
77
|
-
if (value) resolved[colorKey] =
|
|
142
|
+
if (value) resolved[colorKey] = hslTripletToRgb(value);
|
|
78
143
|
}
|
|
79
144
|
return resolved;
|
|
80
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","APP_COLOR_PRESETS","extractHue","hslVar","parseInt","split","extractSat","
|
|
1
|
+
{"version":3,"names":["Platform","APP_COLOR_PRESETS","extractHue","hslVar","parseInt","split","extractSat","hslTripletToRgb","triplet","colorPart","alphaPart","map","part","trim","channels","filter","Boolean","hue","parseFloat","replace","sat","light","h","Number","isFinite","s","l","chroma","Math","abs","huePrime","second","r","g","b","match","red","round","green","blue","undefined","alpha","endsWith","safeAlpha","RESOLVED_COLOR_MAP","getPresetVars","colorName","mode","options","preset","base","dark","get","key","primary","foreground","min","isDark","extended","includeResolvedColorVars","resolved","rawKey","colorKey","Object","entries","value","applyPresetVarsToDocument","OS","document","vars","root","documentElement","style","setProperty"],"sourceRoot":"../../../src","sources":["theme/preset-vars.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,iBAAiB,QAA8C,oBAAiB;AAEzF,SAASC,UAAUA,CAACC,MAAc,EAAU;EAC1C,OAAOC,QAAQ,CAACD,MAAM,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;AAClD;AAEA,SAASC,UAAUA,CAACH,MAAc,EAAU;EAC1C,OAAOC,QAAQ,CAACD,MAAM,CAACE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,eAAeA,CAACC,OAAe,EAAU;EACvD,MAAM,CAACC,SAAS,EAAEC,SAAS,CAAC,GAAGF,OAAO,CAACH,KAAK,CAAC,GAAG,CAAC,CAACM,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACC,IAAI,CAAC,CAAC,CAAC;EAC5E,MAAMC,QAAQ,GAAG,CAACL,SAAS,IAAI,EAAE,EAAEJ,KAAK,CAAC,KAAK,CAAC,CAACU,MAAM,CAACC,OAAO,CAAC;EAE/D,MAAMC,GAAG,GAAGC,UAAU,CAAC,CAACJ,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAEK,OAA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AOD,QAAQ;EAEtD,MAAME,QAAsB,GAAG;IAAE,GAAGF;EAAS,CAAC;EAC9C,KAAK,MAAM,CAACG,MAAM,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACpB,kBAAkB,CAAC,EAAE;IACnE,MAAMqB,KAAK,GAAGP,QAAQ,CAACG,MAAM,CAAC;IAC9B,IAAII,KAAK,EAAEL,QAAQ,CAACE,QAAQ,CAAC,GAAGvD,eAAe,CAAC0D,KAAK,CAAC;EACxD;EACA,OAAOL,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,yBAAyBA,CACvCpB,SAAuB,EACvBC,IAAsB,EACtBC,OAA2B,EACrB;EACN,IAAIhD,QAAQ,CAACmE,EAAE,KAAK,KAAK,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EAE9D,MAAMC,IAAI,GAAGxB,aAAa,CAACC,SAAS,EAAEC,IAAI,EAAEC,OAAO,CAAC;EACpD,MAAMsB,IAAI,GAAGF,QAAQ,CAACG,eAAe,CAACC,KAAK;EAC3C,KAAK,MAAM,CAACnB,GAAG,EAAEY,KAAK,CAAC,IAAIF,MAAM,CAACC,OAAO,CAACK,IAAI,CAAC,EAAE;IAC/CC,IAAI,CAACG,WAAW,CAACpB,GAAG,EAAEY,KAAK,CAAC;EAC9B;AACF","ignoreList":[]}
|
|
@@ -5,10 +5,13 @@ export declare function applyDarkClass(resolved: 'light' | 'dark'): void;
|
|
|
5
5
|
* No-op on native — only affects web.
|
|
6
6
|
*
|
|
7
7
|
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
8
|
-
* resolved `--color-*` vars (`--color-primary:
|
|
8
|
+
* resolved `--color-*` vars (`--color-primary: rgb(0 94 102)`) so both
|
|
9
9
|
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
10
|
-
* utilities resolve consistently.
|
|
11
|
-
*
|
|
10
|
+
* utilities resolve consistently. The resolved vars are emitted as `rgb(...)`
|
|
11
|
+
* (not `hsl(...)`) so the alpha utilities (`bg-primary/10`) resolve on native —
|
|
12
|
+
* see `getPresetVars` / `hslTripletToRgb`. Includes extended tokens (card,
|
|
13
|
+
* chart-*, content-area, sidebar-*) so consumer apps don't need to synthesize
|
|
14
|
+
* them.
|
|
12
15
|
*/
|
|
13
16
|
export declare function applyColorPresetVars(preset: AppColorName, resolved: 'light' | 'dark'): void;
|
|
14
17
|
//# sourceMappingURL=apply-dark-class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGvE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,QAIxD;AAED
|
|
1
|
+
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGvE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,QAIxD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,QAUpF"}
|
|
@@ -24,11 +24,16 @@ import { type AppColorName } from './color-presets';
|
|
|
24
24
|
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
25
25
|
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
26
26
|
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
27
|
-
* navigator renders monochrome. Writing the
|
|
27
|
+
* navigator renders monochrome. Writing the vars into `rootVariables` here is the
|
|
28
28
|
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
29
29
|
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
30
30
|
* content resolves the palette identically regardless of React-tree position.
|
|
31
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
|
+
*
|
|
32
37
|
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
33
38
|
* ---------------------------------------------------------
|
|
34
39
|
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"AAGA,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,11 +1,44 @@
|
|
|
1
1
|
import { type AppColorName, type PresetTokens } from './color-presets';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a shadcn-style HSL triple (`'H S% L%'`, optionally with an alpha tail
|
|
4
|
+
* `'H S% L% / A'`) into an sRGB `rgb(...)` string.
|
|
5
|
+
*
|
|
6
|
+
* Why rgb and not hsl (the native alpha-utility bug this fixes)
|
|
7
|
+
* -------------------------------------------------------------
|
|
8
|
+
* Tailwind v4 compiles an alpha-on-theme-color utility (`bg-primary/10`) into a
|
|
9
|
+
* `color-mix(... var(--color-primary) 10%, transparent)` declaration. On native,
|
|
10
|
+
* react-native-css resolves that `color-mix` at runtime via `colorjs.io/fn`, but
|
|
11
|
+
* its `color-mix` implementation registers ONLY the `sRGB`, `P3`, and `OKLab`
|
|
12
|
+
* color spaces — never `HSL`. So if `--color-primary` resolves to an `hsl(...)`
|
|
13
|
+
* string, `parse('hsl(...)')` throws, the mix is swallowed, and the utility
|
|
14
|
+
* silently produces no color. Emitting the resolved var as `rgb(...)` (a space
|
|
15
|
+
* colorjs.io always has registered) makes the alpha utilities resolve on native,
|
|
16
|
+
* matching web. Full (non-alpha) utilities already worked because React Native's
|
|
17
|
+
* native color parser handles `hsl()` directly; only `color-mix` was affected.
|
|
18
|
+
*
|
|
19
|
+
* Output is space-separated channels (`rgb(31 153 239)`), the modern CSS syntax
|
|
20
|
+
* parsed by both `colorjs.io/fn` (with only sRGB/P3/OKLab registered) and
|
|
21
|
+
* react-native-web / browsers. An alpha tail emits `rgb(r g b / a)`, likewise
|
|
22
|
+
* parsed by both.
|
|
23
|
+
*
|
|
24
|
+
* Pure function — standard HSL→sRGB conversion, channels rounded to integers.
|
|
25
|
+
* Tolerates a `deg` suffix on the hue and `%` suffixes on saturation/lightness.
|
|
26
|
+
*/
|
|
27
|
+
export declare function hslTripletToRgb(triplet: string): string;
|
|
2
28
|
export interface PresetVarsOptions {
|
|
3
29
|
/**
|
|
4
|
-
* Also emit Tailwind v4 resolved `--color-*` vars (
|
|
30
|
+
* Also emit Tailwind v4 resolved `--color-*` vars (as sRGB `rgb(...)` strings)
|
|
5
31
|
* alongside the raw HSL triples. Needed when scoping a subtree where
|
|
6
32
|
* Tailwind's `@theme` block has already precomputed `--color-*` at `:root`,
|
|
7
33
|
* so overriding `--background` alone wouldn't cascade to `bg-background`.
|
|
8
|
-
*
|
|
34
|
+
*
|
|
35
|
+
* The resolved vars are emitted as `rgb(...)` rather than `hsl(...)` so the
|
|
36
|
+
* alpha-on-theme-color utilities (`bg-primary/10`, `text-foreground/50`)
|
|
37
|
+
* resolve on native: Tailwind compiles those to a runtime `color-mix(...)` that
|
|
38
|
+
* react-native-css evaluates via `colorjs.io/fn`, which only registers the
|
|
39
|
+
* sRGB/P3/OKLab spaces (not HSL) — so an `hsl(...)` var would throw and the
|
|
40
|
+
* utility would silently render no color. See `hslTripletToRgb`. Default
|
|
41
|
+
* `false`.
|
|
9
42
|
*/
|
|
10
43
|
includeResolvedColorVars?: boolean;
|
|
11
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/preset-vars.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"preset-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/preset-vars.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU1F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA+CvD;AAyBD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;OAaG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,OAAO,GAAG,MAAM,EACtB,OAAO,GAAE,iBAAsB,GAC9B,YAAY,CAwCd;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,OAAO,GAAG,MAAM,EACtB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,IAAI,CAQN"}
|
|
@@ -5,10 +5,13 @@ export declare function applyDarkClass(resolved: 'light' | 'dark'): void;
|
|
|
5
5
|
* No-op on native — only affects web.
|
|
6
6
|
*
|
|
7
7
|
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
8
|
-
* resolved `--color-*` vars (`--color-primary:
|
|
8
|
+
* resolved `--color-*` vars (`--color-primary: rgb(0 94 102)`) so both
|
|
9
9
|
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
10
|
-
* utilities resolve consistently.
|
|
11
|
-
*
|
|
10
|
+
* utilities resolve consistently. The resolved vars are emitted as `rgb(...)`
|
|
11
|
+
* (not `hsl(...)`) so the alpha utilities (`bg-primary/10`) resolve on native —
|
|
12
|
+
* see `getPresetVars` / `hslTripletToRgb`. Includes extended tokens (card,
|
|
13
|
+
* chart-*, content-area, sidebar-*) so consumer apps don't need to synthesize
|
|
14
|
+
* them.
|
|
12
15
|
*/
|
|
13
16
|
export declare function applyColorPresetVars(preset: AppColorName, resolved: 'light' | 'dark'): void;
|
|
14
17
|
//# sourceMappingURL=apply-dark-class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGvE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,QAIxD;AAED
|
|
1
|
+
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGvE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,QAIxD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,QAUpF"}
|
|
@@ -24,11 +24,16 @@ import { type AppColorName } from './color-presets';
|
|
|
24
24
|
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
25
25
|
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
26
26
|
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
27
|
-
* navigator renders monochrome. Writing the
|
|
27
|
+
* navigator renders monochrome. Writing the vars into `rootVariables` here is the
|
|
28
28
|
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
29
29
|
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
30
30
|
* content resolves the palette identically regardless of React-tree position.
|
|
31
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
|
+
*
|
|
32
37
|
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
33
38
|
* ---------------------------------------------------------
|
|
34
39
|
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"native-root-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/native-root-vars.ts"],"names":[],"mappings":"AAGA,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,11 +1,44 @@
|
|
|
1
1
|
import { type AppColorName, type PresetTokens } from './color-presets';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a shadcn-style HSL triple (`'H S% L%'`, optionally with an alpha tail
|
|
4
|
+
* `'H S% L% / A'`) into an sRGB `rgb(...)` string.
|
|
5
|
+
*
|
|
6
|
+
* Why rgb and not hsl (the native alpha-utility bug this fixes)
|
|
7
|
+
* -------------------------------------------------------------
|
|
8
|
+
* Tailwind v4 compiles an alpha-on-theme-color utility (`bg-primary/10`) into a
|
|
9
|
+
* `color-mix(... var(--color-primary) 10%, transparent)` declaration. On native,
|
|
10
|
+
* react-native-css resolves that `color-mix` at runtime via `colorjs.io/fn`, but
|
|
11
|
+
* its `color-mix` implementation registers ONLY the `sRGB`, `P3`, and `OKLab`
|
|
12
|
+
* color spaces — never `HSL`. So if `--color-primary` resolves to an `hsl(...)`
|
|
13
|
+
* string, `parse('hsl(...)')` throws, the mix is swallowed, and the utility
|
|
14
|
+
* silently produces no color. Emitting the resolved var as `rgb(...)` (a space
|
|
15
|
+
* colorjs.io always has registered) makes the alpha utilities resolve on native,
|
|
16
|
+
* matching web. Full (non-alpha) utilities already worked because React Native's
|
|
17
|
+
* native color parser handles `hsl()` directly; only `color-mix` was affected.
|
|
18
|
+
*
|
|
19
|
+
* Output is space-separated channels (`rgb(31 153 239)`), the modern CSS syntax
|
|
20
|
+
* parsed by both `colorjs.io/fn` (with only sRGB/P3/OKLab registered) and
|
|
21
|
+
* react-native-web / browsers. An alpha tail emits `rgb(r g b / a)`, likewise
|
|
22
|
+
* parsed by both.
|
|
23
|
+
*
|
|
24
|
+
* Pure function — standard HSL→sRGB conversion, channels rounded to integers.
|
|
25
|
+
* Tolerates a `deg` suffix on the hue and `%` suffixes on saturation/lightness.
|
|
26
|
+
*/
|
|
27
|
+
export declare function hslTripletToRgb(triplet: string): string;
|
|
2
28
|
export interface PresetVarsOptions {
|
|
3
29
|
/**
|
|
4
|
-
* Also emit Tailwind v4 resolved `--color-*` vars (
|
|
30
|
+
* Also emit Tailwind v4 resolved `--color-*` vars (as sRGB `rgb(...)` strings)
|
|
5
31
|
* alongside the raw HSL triples. Needed when scoping a subtree where
|
|
6
32
|
* Tailwind's `@theme` block has already precomputed `--color-*` at `:root`,
|
|
7
33
|
* so overriding `--background` alone wouldn't cascade to `bg-background`.
|
|
8
|
-
*
|
|
34
|
+
*
|
|
35
|
+
* The resolved vars are emitted as `rgb(...)` rather than `hsl(...)` so the
|
|
36
|
+
* alpha-on-theme-color utilities (`bg-primary/10`, `text-foreground/50`)
|
|
37
|
+
* resolve on native: Tailwind compiles those to a runtime `color-mix(...)` that
|
|
38
|
+
* react-native-css evaluates via `colorjs.io/fn`, which only registers the
|
|
39
|
+
* sRGB/P3/OKLab spaces (not HSL) — so an `hsl(...)` var would throw and the
|
|
40
|
+
* utility would silently render no color. See `hslTripletToRgb`. Default
|
|
41
|
+
* `false`.
|
|
9
42
|
*/
|
|
10
43
|
includeResolvedColorVars?: boolean;
|
|
11
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/preset-vars.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"preset-vars.d.ts","sourceRoot":"","sources":["../../../../src/theme/preset-vars.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU1F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA+CvD;AAyBD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;OAaG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,OAAO,GAAG,MAAM,EACtB,OAAO,GAAE,iBAAsB,GAC9B,YAAY,CAwCd;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,OAAO,GAAG,MAAM,EACtB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,IAAI,CAQN"}
|
package/package.json
CHANGED
|
@@ -51,9 +51,11 @@ describe('applyNativeRootVars (native variant)', () => {
|
|
|
51
51
|
expect(sets).not.toHaveProperty('--primary');
|
|
52
52
|
expect(sets.primary).toEqual([['205 87% 53%']]);
|
|
53
53
|
|
|
54
|
-
// Resolved Tailwind v4 `--color-*` vars are written too, also bare-keyed
|
|
54
|
+
// Resolved Tailwind v4 `--color-*` vars are written too, also bare-keyed,
|
|
55
|
+
// and as sRGB `rgb(...)` (not `hsl(...)`) so native `color-mix` alpha
|
|
56
|
+
// utilities resolve — `205 87% 53%` → `rgb(31 153 239)`.
|
|
55
57
|
expect(sets).toHaveProperty('color-primary');
|
|
56
|
-
expect(sets['color-primary']).toEqual([['
|
|
58
|
+
expect(sets['color-primary']).toEqual([['rgb(31 153 239)']]);
|
|
57
59
|
|
|
58
60
|
// Every value is a single-element value-array `[[value]]` of strings.
|
|
59
61
|
for (const value of Object.values(sets)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APP_COLOR_NAMES, APP_COLOR_PRESETS } from '../theme/color-presets';
|
|
2
|
-
import { getPresetVars } from '../theme/preset-vars';
|
|
2
|
+
import { getPresetVars, hslTripletToRgb } from '../theme/preset-vars';
|
|
3
3
|
|
|
4
4
|
const EXTENDED_KEYS = [
|
|
5
5
|
'--card',
|
|
@@ -50,9 +50,50 @@ describe('getPresetVars', () => {
|
|
|
50
50
|
expect(vars['--color-primary']).toBeUndefined();
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
it('emits resolved --color-* vars
|
|
53
|
+
it('emits resolved --color-* vars as rgb() when requested', () => {
|
|
54
54
|
const vars = getPresetVars('green', 'dark', { includeResolvedColorVars: true });
|
|
55
|
-
|
|
56
|
-
expect(vars['--color-
|
|
55
|
+
const primaryTriple = APP_COLOR_PRESETS.green.dark['--primary'] ?? '';
|
|
56
|
+
expect(vars['--color-primary']).toBe(hslTripletToRgb(primaryTriple));
|
|
57
|
+
expect(vars['--color-primary']).toMatch(/^rgb\(\d+ \d+ \d+\)$/);
|
|
58
|
+
expect(vars['--color-card']).toBe(hslTripletToRgb(vars['--card'] ?? ''));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('resolves --color-primary to rgb for the blue preset (matches web reference)', () => {
|
|
62
|
+
// `blue` preset light `--primary` is `205 87% 53%` → rgb(31 153 239).
|
|
63
|
+
const vars = getPresetVars('blue', 'light', { includeResolvedColorVars: true });
|
|
64
|
+
expect(vars['--color-primary']).toBe('rgb(31 153 239)');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('hslTripletToRgb', () => {
|
|
69
|
+
it('converts a plain HSL triple to a space-separated rgb() string', () => {
|
|
70
|
+
expect(hslTripletToRgb('205 87% 53%')).toBe('rgb(31 153 239)');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('converts the achromatic extremes', () => {
|
|
74
|
+
expect(hslTripletToRgb('0 0% 0%')).toBe('rgb(0 0 0)');
|
|
75
|
+
expect(hslTripletToRgb('0 0% 100%')).toBe('rgb(255 255 255)');
|
|
76
|
+
expect(hslTripletToRgb('0 0% 12%')).toBe('rgb(31 31 31)');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('converts a saturated triple within ±1 per channel of the reference', () => {
|
|
80
|
+
// teal `185 100% 20%` ≈ rgb(0 94 102).
|
|
81
|
+
const match = /^rgb\((\d+) (\d+) (\d+)\)$/.exec(hslTripletToRgb('185 100% 20%'));
|
|
82
|
+
expect(match).not.toBeNull();
|
|
83
|
+
const r = Number(match?.[1] ?? NaN);
|
|
84
|
+
const g = Number(match?.[2] ?? NaN);
|
|
85
|
+
const b = Number(match?.[3] ?? NaN);
|
|
86
|
+
expect(Math.abs(r - 0)).toBeLessThanOrEqual(1);
|
|
87
|
+
expect(Math.abs(g - 94)).toBeLessThanOrEqual(1);
|
|
88
|
+
expect(Math.abs(b - 102)).toBeLessThanOrEqual(1);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('tolerates a deg suffix on the hue', () => {
|
|
92
|
+
expect(hslTripletToRgb('205deg 87% 53%')).toBe('rgb(31 153 239)');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('emits rgb(r g b / a) for an alpha tail (decimal or percentage)', () => {
|
|
96
|
+
expect(hslTripletToRgb('205 87% 53% / 0.5')).toBe('rgb(31 153 239 / 0.5)');
|
|
97
|
+
expect(hslTripletToRgb('205 87% 53% / 50%')).toBe('rgb(31 153 239 / 0.5)');
|
|
57
98
|
});
|
|
58
99
|
});
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
declare module 'react-native-css/native-internal' {
|
|
21
21
|
/**
|
|
22
22
|
* A leaf style value. Mirrors react-native-css's `compiler.types`
|
|
23
|
-
* `StyleDescriptor`. Bloom only ever writes string
|
|
24
|
-
*
|
|
23
|
+
* `StyleDescriptor`. Bloom only ever writes string color values (raw HSL
|
|
24
|
+
* triples for the `--*` vars, sRGB `rgb(...)` for the resolved `--color-*`
|
|
25
|
+
* vars), but the family is typed against the full descriptor union.
|
|
25
26
|
*/
|
|
26
27
|
type StyleDescriptor =
|
|
27
28
|
| string
|
|
@@ -13,10 +13,13 @@ export function applyDarkClass(resolved: 'light' | 'dark') {
|
|
|
13
13
|
* No-op on native — only affects web.
|
|
14
14
|
*
|
|
15
15
|
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
16
|
-
* resolved `--color-*` vars (`--color-primary:
|
|
16
|
+
* resolved `--color-*` vars (`--color-primary: rgb(0 94 102)`) so both
|
|
17
17
|
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
18
|
-
* utilities resolve consistently.
|
|
19
|
-
*
|
|
18
|
+
* utilities resolve consistently. The resolved vars are emitted as `rgb(...)`
|
|
19
|
+
* (not `hsl(...)`) so the alpha utilities (`bg-primary/10`) resolve on native —
|
|
20
|
+
* see `getPresetVars` / `hslTripletToRgb`. Includes extended tokens (card,
|
|
21
|
+
* chart-*, content-area, sidebar-*) so consumer apps don't need to synthesize
|
|
22
|
+
* them.
|
|
20
23
|
*/
|
|
21
24
|
export function applyColorPresetVars(preset: AppColorName, resolved: 'light' | 'dark') {
|
|
22
25
|
if (Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
@@ -28,11 +28,16 @@ import { type AppColorName } from './color-presets';
|
|
|
28
28
|
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
29
29
|
* (Bloom's `global.css` defines the `hsl(var(--primary))` indirection but not the HSL
|
|
30
30
|
* triples themselves — those are injected at runtime), so the whole tree below the
|
|
31
|
-
* navigator renders monochrome. Writing the
|
|
31
|
+
* navigator renders monochrome. Writing the vars into `rootVariables` here is the
|
|
32
32
|
* exact same mechanism react-native-css uses for compiled `:root {}` / `@theme` vars
|
|
33
33
|
* (`StyleCollection.inject` does `rootVariables(name).set(valueArray)`), so portaled
|
|
34
34
|
* content resolves the palette identically regardless of React-tree position.
|
|
35
35
|
*
|
|
36
|
+
* The raw tokens are written as HSL triples (`primary: '205 87% 53%'`) and the
|
|
37
|
+
* resolved Tailwind v4 `--color-*` vars as sRGB `rgb(...)` (`color-primary:
|
|
38
|
+
* 'rgb(31 153 239)'`) — the latter so `color-mix`-based alpha utilities resolve
|
|
39
|
+
* on native (see `getPresetVars` / `hslTripletToRgb`).
|
|
40
|
+
*
|
|
36
41
|
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
37
42
|
* ---------------------------------------------------------
|
|
38
43
|
* react-native-css@3.0.7 ships both a `dist/commonjs` and a `dist/module` build, and
|
package/src/theme/preset-vars.ts
CHANGED
|
@@ -9,6 +9,80 @@ function extractSat(hslVar: string): number {
|
|
|
9
9
|
return parseInt(hslVar.split(' ')[1] ?? '0', 10);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Convert a shadcn-style HSL triple (`'H S% L%'`, optionally with an alpha tail
|
|
14
|
+
* `'H S% L% / A'`) into an sRGB `rgb(...)` string.
|
|
15
|
+
*
|
|
16
|
+
* Why rgb and not hsl (the native alpha-utility bug this fixes)
|
|
17
|
+
* -------------------------------------------------------------
|
|
18
|
+
* Tailwind v4 compiles an alpha-on-theme-color utility (`bg-primary/10`) into a
|
|
19
|
+
* `color-mix(... var(--color-primary) 10%, transparent)` declaration. On native,
|
|
20
|
+
* react-native-css resolves that `color-mix` at runtime via `colorjs.io/fn`, but
|
|
21
|
+
* its `color-mix` implementation registers ONLY the `sRGB`, `P3`, and `OKLab`
|
|
22
|
+
* color spaces — never `HSL`. So if `--color-primary` resolves to an `hsl(...)`
|
|
23
|
+
* string, `parse('hsl(...)')` throws, the mix is swallowed, and the utility
|
|
24
|
+
* silently produces no color. Emitting the resolved var as `rgb(...)` (a space
|
|
25
|
+
* colorjs.io always has registered) makes the alpha utilities resolve on native,
|
|
26
|
+
* matching web. Full (non-alpha) utilities already worked because React Native's
|
|
27
|
+
* native color parser handles `hsl()` directly; only `color-mix` was affected.
|
|
28
|
+
*
|
|
29
|
+
* Output is space-separated channels (`rgb(31 153 239)`), the modern CSS syntax
|
|
30
|
+
* parsed by both `colorjs.io/fn` (with only sRGB/P3/OKLab registered) and
|
|
31
|
+
* react-native-web / browsers. An alpha tail emits `rgb(r g b / a)`, likewise
|
|
32
|
+
* parsed by both.
|
|
33
|
+
*
|
|
34
|
+
* Pure function — standard HSL→sRGB conversion, channels rounded to integers.
|
|
35
|
+
* Tolerates a `deg` suffix on the hue and `%` suffixes on saturation/lightness.
|
|
36
|
+
*/
|
|
37
|
+
export function hslTripletToRgb(triplet: string): string {
|
|
38
|
+
const [colorPart, alphaPart] = triplet.split('/').map((part) => part.trim());
|
|
39
|
+
const channels = (colorPart ?? '').split(/\s+/).filter(Boolean);
|
|
40
|
+
|
|
41
|
+
const hue = parseFloat((channels[0] ?? '0').replace(/deg$/i, ''));
|
|
42
|
+
const sat = parseFloat((channels[1] ?? '0').replace('%', '')) / 100;
|
|
43
|
+
const light = parseFloat((channels[2] ?? '0').replace('%', '')) / 100;
|
|
44
|
+
|
|
45
|
+
const h = Number.isFinite(hue) ? hue : 0;
|
|
46
|
+
const s = Number.isFinite(sat) ? sat : 0;
|
|
47
|
+
const l = Number.isFinite(light) ? light : 0;
|
|
48
|
+
|
|
49
|
+
const chroma = (1 - Math.abs(2 * l - 1)) * s;
|
|
50
|
+
const huePrime = ((((h % 360) + 360) % 360) / 60);
|
|
51
|
+
const second = chroma * (1 - Math.abs((huePrime % 2) - 1));
|
|
52
|
+
|
|
53
|
+
let r = 0;
|
|
54
|
+
let g = 0;
|
|
55
|
+
let b = 0;
|
|
56
|
+
if (huePrime < 1) {
|
|
57
|
+
[r, g, b] = [chroma, second, 0];
|
|
58
|
+
} else if (huePrime < 2) {
|
|
59
|
+
[r, g, b] = [second, chroma, 0];
|
|
60
|
+
} else if (huePrime < 3) {
|
|
61
|
+
[r, g, b] = [0, chroma, second];
|
|
62
|
+
} else if (huePrime < 4) {
|
|
63
|
+
[r, g, b] = [0, second, chroma];
|
|
64
|
+
} else if (huePrime < 5) {
|
|
65
|
+
[r, g, b] = [second, 0, chroma];
|
|
66
|
+
} else {
|
|
67
|
+
[r, g, b] = [chroma, 0, second];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const match = l - chroma / 2;
|
|
71
|
+
const red = Math.round((r + match) * 255);
|
|
72
|
+
const green = Math.round((g + match) * 255);
|
|
73
|
+
const blue = Math.round((b + match) * 255);
|
|
74
|
+
|
|
75
|
+
if (alphaPart !== undefined && alphaPart !== '') {
|
|
76
|
+
const alpha = alphaPart.endsWith('%')
|
|
77
|
+
? parseFloat(alphaPart) / 100
|
|
78
|
+
: parseFloat(alphaPart);
|
|
79
|
+
const safeAlpha = Number.isFinite(alpha) ? alpha : 1;
|
|
80
|
+
return `rgb(${red} ${green} ${blue} / ${safeAlpha})`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return `rgb(${red} ${green} ${blue})`;
|
|
84
|
+
}
|
|
85
|
+
|
|
12
86
|
const RESOLVED_COLOR_MAP: Record<string, string> = {
|
|
13
87
|
'--background': '--color-background',
|
|
14
88
|
'--foreground': '--color-foreground',
|
|
@@ -34,11 +108,18 @@ const RESOLVED_COLOR_MAP: Record<string, string> = {
|
|
|
34
108
|
|
|
35
109
|
export interface PresetVarsOptions {
|
|
36
110
|
/**
|
|
37
|
-
* Also emit Tailwind v4 resolved `--color-*` vars (
|
|
111
|
+
* Also emit Tailwind v4 resolved `--color-*` vars (as sRGB `rgb(...)` strings)
|
|
38
112
|
* alongside the raw HSL triples. Needed when scoping a subtree where
|
|
39
113
|
* Tailwind's `@theme` block has already precomputed `--color-*` at `:root`,
|
|
40
114
|
* so overriding `--background` alone wouldn't cascade to `bg-background`.
|
|
41
|
-
*
|
|
115
|
+
*
|
|
116
|
+
* The resolved vars are emitted as `rgb(...)` rather than `hsl(...)` so the
|
|
117
|
+
* alpha-on-theme-color utilities (`bg-primary/10`, `text-foreground/50`)
|
|
118
|
+
* resolve on native: Tailwind compiles those to a runtime `color-mix(...)` that
|
|
119
|
+
* react-native-css evaluates via `colorjs.io/fn`, which only registers the
|
|
120
|
+
* sRGB/P3/OKLab spaces (not HSL) — so an `hsl(...)` var would throw and the
|
|
121
|
+
* utility would silently render no color. See `hslTripletToRgb`. Default
|
|
122
|
+
* `false`.
|
|
42
123
|
*/
|
|
43
124
|
includeResolvedColorVars?: boolean;
|
|
44
125
|
}
|
|
@@ -92,7 +173,7 @@ export function getPresetVars(
|
|
|
92
173
|
const resolved: PresetTokens = { ...extended };
|
|
93
174
|
for (const [rawKey, colorKey] of Object.entries(RESOLVED_COLOR_MAP)) {
|
|
94
175
|
const value = extended[rawKey];
|
|
95
|
-
if (value) resolved[colorKey] =
|
|
176
|
+
if (value) resolved[colorKey] = hslTripletToRgb(value);
|
|
96
177
|
}
|
|
97
178
|
return resolved;
|
|
98
179
|
}
|