@oxyhq/bloom 0.7.7 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/normalize-colors.d.js +2 -0
- package/lib/commonjs/normalize-colors.d.js.map +1 -0
- package/lib/commonjs/theme/apply-dark-class.js +8 -24
- package/lib/commonjs/theme/apply-dark-class.js.map +1 -1
- package/lib/commonjs/theme/build-theme.js +61 -57
- package/lib/commonjs/theme/build-theme.js.map +1 -1
- package/lib/commonjs/theme/color-presets.js +9 -9
- package/lib/commonjs/theme/color-scope/index.web.js +7 -14
- package/lib/commonjs/theme/color-scope/index.web.js.map +1 -1
- package/lib/commonjs/theme/color-scope/style-builder.js +7 -6
- package/lib/commonjs/theme/color-scope/style-builder.js.map +1 -1
- package/lib/commonjs/theme/color-space.js +76 -0
- package/lib/commonjs/theme/color-space.js.map +1 -0
- package/lib/commonjs/theme/index.js +0 -6
- package/lib/commonjs/theme/index.js.map +1 -1
- package/lib/commonjs/theme/native-root-vars.native.js +28 -18
- package/lib/commonjs/theme/native-root-vars.native.js.map +1 -1
- package/lib/commonjs/theme/preset-vars.js +20 -152
- package/lib/commonjs/theme/preset-vars.js.map +1 -1
- package/lib/commonjs/theme/token-registry.js +123 -0
- package/lib/commonjs/theme/token-registry.js.map +1 -0
- package/lib/module/normalize-colors.d.js +2 -0
- package/lib/module/normalize-colors.d.js.map +1 -0
- package/lib/module/theme/apply-dark-class.js +8 -19
- package/lib/module/theme/apply-dark-class.js.map +1 -1
- package/lib/module/theme/build-theme.js +61 -57
- package/lib/module/theme/build-theme.js.map +1 -1
- package/lib/module/theme/color-presets.js +9 -9
- package/lib/module/theme/color-scope/index.web.js +7 -14
- package/lib/module/theme/color-scope/index.web.js.map +1 -1
- package/lib/module/theme/color-scope/style-builder.js +7 -6
- package/lib/module/theme/color-scope/style-builder.js.map +1 -1
- package/lib/module/theme/color-space.js +69 -0
- package/lib/module/theme/color-space.js.map +1 -0
- package/lib/module/theme/index.js +1 -1
- package/lib/module/theme/index.js.map +1 -1
- package/lib/module/theme/native-root-vars.native.js +29 -18
- package/lib/module/theme/native-root-vars.native.js.map +1 -1
- package/lib/module/theme/preset-vars.js +19 -150
- package/lib/module/theme/preset-vars.js.map +1 -1
- package/lib/module/theme/token-registry.js +113 -0
- package/lib/module/theme/token-registry.js.map +1 -0
- package/lib/typescript/commonjs/theme/apply-dark-class.d.ts +5 -10
- package/lib/typescript/commonjs/theme/apply-dark-class.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/build-theme.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-presets.d.ts +9 -9
- package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/style-builder.d.ts +5 -2
- package/lib/typescript/commonjs/theme/color-scope/style-builder.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-space.d.ts +28 -0
- package/lib/typescript/commonjs/theme/color-space.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/index.d.ts +1 -2
- package/lib/typescript/commonjs/theme/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/native-root-vars.native.d.ts +25 -15
- package/lib/typescript/commonjs/theme/native-root-vars.native.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/preset-vars.d.ts +11 -74
- package/lib/typescript/commonjs/theme/preset-vars.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/token-registry.d.ts +53 -0
- package/lib/typescript/commonjs/theme/token-registry.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/types.d.ts +3 -0
- package/lib/typescript/commonjs/theme/types.d.ts.map +1 -1
- package/lib/typescript/module/theme/apply-dark-class.d.ts +5 -10
- package/lib/typescript/module/theme/apply-dark-class.d.ts.map +1 -1
- package/lib/typescript/module/theme/build-theme.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-presets.d.ts +9 -9
- package/lib/typescript/module/theme/color-scope/index.web.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/style-builder.d.ts +5 -2
- package/lib/typescript/module/theme/color-scope/style-builder.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-space.d.ts +28 -0
- package/lib/typescript/module/theme/color-space.d.ts.map +1 -0
- package/lib/typescript/module/theme/index.d.ts +1 -2
- package/lib/typescript/module/theme/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/native-root-vars.native.d.ts +25 -15
- package/lib/typescript/module/theme/native-root-vars.native.d.ts.map +1 -1
- package/lib/typescript/module/theme/preset-vars.d.ts +11 -74
- package/lib/typescript/module/theme/preset-vars.d.ts.map +1 -1
- package/lib/typescript/module/theme/token-registry.d.ts +53 -0
- package/lib/typescript/module/theme/token-registry.d.ts.map +1 -0
- package/lib/typescript/module/theme/types.d.ts +3 -0
- package/lib/typescript/module/theme/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/BloomColorScope.test.tsx +5 -5
- package/src/__tests__/BloomThemeProvider.test.tsx +4 -3
- package/src/__tests__/apply-dark-class.test.ts +26 -21
- package/src/__tests__/native-root-vars.test.ts +8 -7
- package/src/__tests__/preset-vars.test.ts +31 -77
- package/src/__tests__/theme.test.ts +6 -6
- package/src/normalize-colors.d.ts +22 -0
- package/src/react-native-css.d.ts +3 -3
- package/src/theme/__tests__/__fixtures__/golden-resolved-tokens.json +574 -0
- package/src/theme/__tests__/__snapshots__/visual-gallery.test.tsx.snap +838 -0
- package/src/theme/__tests__/color-space.test.ts +28 -0
- package/src/theme/__tests__/golden-tokens.test.ts +33 -0
- package/src/theme/__tests__/runtime-contract.test.ts +63 -0
- package/src/theme/__tests__/theme-colors-parity.test.ts +115 -0
- package/src/theme/__tests__/token-registry.test.ts +30 -0
- package/src/theme/__tests__/visual-gallery.test.tsx +10 -0
- package/src/theme/apply-dark-class.ts +8 -17
- package/src/theme/build-theme.ts +59 -62
- package/src/theme/color-presets.ts +9 -9
- package/src/theme/color-scope/index.web.tsx +7 -14
- package/src/theme/color-scope/style-builder.ts +7 -4
- package/src/theme/color-space.ts +56 -0
- package/src/theme/index.ts +1 -6
- package/src/theme/native-root-vars.native.ts +28 -18
- package/src/theme/preset-vars.ts +17 -178
- package/src/theme/token-registry.ts +159 -0
- package/src/theme/types.ts +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["normalize-colors.d.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -5,19 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.applyColorPresetVars = applyColorPresetVars;
|
|
7
7
|
exports.applyDarkClass = applyDarkClass;
|
|
8
|
-
Object.defineProperty(exports, "toWebColorValue", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return _presetVars.toWebColorValue;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
8
|
var _reactNative = require("react-native");
|
|
15
9
|
var _colorPresets = require("./color-presets.js");
|
|
16
|
-
var
|
|
17
|
-
// Re-exported so the web var-contract helper is reachable from this file (the
|
|
18
|
-
// home of the web write path). Defined in `preset-vars.ts` next to the related
|
|
19
|
-
// HSL parsing so native (which never imports this module) doesn't pull it in.
|
|
20
|
-
|
|
10
|
+
var _tokenRegistry = require("./token-registry.js");
|
|
21
11
|
function applyDarkClass(resolved) {
|
|
22
12
|
if (_reactNative.Platform.OS === 'web' && typeof document !== 'undefined') {
|
|
23
13
|
document.documentElement.classList.toggle('dark', resolved === 'dark');
|
|
@@ -32,28 +22,22 @@ function applyDarkClass(resolved) {
|
|
|
32
22
|
* -------------------------------------------------------------------
|
|
33
23
|
* The shadcn/Tailwind-v4 web apps compile their color utilities to reference the
|
|
34
24
|
* BASE token directly (`.bg-background { background-color: var(--background) }`),
|
|
35
|
-
* so on web the base `--x` tokens MUST be FULL CSS colors.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* unchanged. See `toWebColorValue`.
|
|
25
|
+
* so on web the base `--x` tokens MUST be FULL CSS colors. `getResolvedTokens`
|
|
26
|
+
* returns every canonical token already resolved to an sRGB `rgb(...)` string,
|
|
27
|
+
* so `var(--x)` resolves to a valid color directly — no per-value wrapping. The
|
|
28
|
+
* same rgb values feed native (`color-mix` alpha utilities resolve on sRGB), so
|
|
29
|
+
* web and native share one canonical token pipeline.
|
|
41
30
|
*
|
|
42
|
-
* NATIVE writes the SAME tokens as RAW HSL triples (no `hsl()` wrapper) via
|
|
43
|
-
* `rootVariables` (`native-root-vars.native.ts`), consumed through bloom's
|
|
44
|
-
* native `global.css` `hsl(var(--x))` indirection — that path is untouched here.
|
|
45
31
|
* Includes extended tokens (card, chart-*, content-area, sidebar-*) so consumer
|
|
46
32
|
* apps don't need to synthesize them.
|
|
47
33
|
*/
|
|
48
34
|
function applyColorPresetVars(preset, resolved) {
|
|
49
35
|
if (_reactNative.Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
50
36
|
if (!_colorPresets.APP_COLOR_PRESETS[preset]) return;
|
|
51
|
-
const vars = (0,
|
|
52
|
-
includeResolvedColorVars: true
|
|
53
|
-
});
|
|
37
|
+
const vars = (0, _tokenRegistry.getResolvedTokens)(preset, resolved);
|
|
54
38
|
const root = document.documentElement.style;
|
|
55
39
|
for (const [key, value] of Object.entries(vars)) {
|
|
56
|
-
root.setProperty(key,
|
|
40
|
+
root.setProperty(key, value);
|
|
57
41
|
}
|
|
58
42
|
}
|
|
59
43
|
//# sourceMappingURL=apply-dark-class.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_colorPresets","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_colorPresets","_tokenRegistry","applyDarkClass","resolved","Platform","OS","document","documentElement","classList","toggle","applyColorPresetVars","preset","APP_COLOR_PRESETS","vars","getResolvedTokens","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,cAAA,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;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,gCAAiB,EAACH,MAAM,EAAER,QAAQ,CAAC;EAChD,MAAMY,IAAI,GAAGT,QAAQ,CAACC,eAAe,CAACS,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":[]}
|
|
@@ -8,6 +8,7 @@ exports.buildTheme = buildTheme;
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _colorPresets = require("./color-presets.js");
|
|
10
10
|
var _adaptiveColors = require("./adaptive-colors.js");
|
|
11
|
+
var _tokenRegistry = require("./token-registry.js");
|
|
11
12
|
/**
|
|
12
13
|
* Status colors used across the design system. Independent of the accent
|
|
13
14
|
* preset so semantic intent stays stable across themes.
|
|
@@ -20,72 +21,75 @@ const STATUS_COLORS = exports.STATUS_COLORS = {
|
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* Extract the integer hue from a shadcn-style raw HSL triple (`'H S% L%'`,
|
|
25
|
+
* optionally with an alpha tail). Used to seed the computed brand tints below
|
|
26
|
+
* from the preset's primary/destructive hue, exactly as pre-0.8.0.
|
|
26
27
|
*/
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
const triple = parts[0] ?? '0 0% 0%';
|
|
30
|
-
const components = triple.replace(/\s+/g, ', ');
|
|
31
|
-
if (parts.length === 2) {
|
|
32
|
-
const alpha = parseFloat(parts[1] ?? '100') / 100;
|
|
33
|
-
return `hsla(${components}, ${alpha})`;
|
|
34
|
-
}
|
|
35
|
-
return `hsl(${components})`;
|
|
36
|
-
}
|
|
37
|
-
function extractHue(hslVar) {
|
|
38
|
-
const first = hslVar.split(/\s+/)[0] ?? '0';
|
|
28
|
+
function extractHue(triple) {
|
|
29
|
+
const first = (triple.split(/\s+/)[0] ?? '0').replace(/deg$/i, '');
|
|
39
30
|
const hue = parseInt(first, 10);
|
|
40
31
|
return Number.isFinite(hue) ? hue : 0;
|
|
41
32
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Build the JS `theme.colors` object from the SAME canonical rgb token source
|
|
36
|
+
* the web/native CSS-var writes use (`getResolvedTokens`). JS styles and the
|
|
37
|
+
* `var(--x)` document tokens therefore share one rgb pipeline — no second,
|
|
38
|
+
* drift-prone HSL conversion lives here.
|
|
39
|
+
*
|
|
40
|
+
* Token-backed values read straight from the resolved rgb map via `g(...)`.
|
|
41
|
+
* The brand tints (primarySubtle/negative/contrast50/...) reproduce the EXACT
|
|
42
|
+
* pre-0.8.0 colors — computed from the preset's primary/destructive HUE with
|
|
43
|
+
* the historical `hsl(h, s%, l%)` math — but are emitted as `rgb(...)` by
|
|
44
|
+
* routing the triple through the registry's `hslToSrgb`, so the single-format
|
|
45
|
+
* pipeline is preserved. (`hsl(h,s%,l%)` and the `rgb(...)` of the same color
|
|
46
|
+
* are byte-identical under the RN/RNW/browser parser.)
|
|
47
|
+
*/
|
|
48
48
|
function buildColorsFromPreset(preset, resolved) {
|
|
49
|
-
const
|
|
50
|
-
const tokens = resolved === 'dark' ? config.dark : config.light;
|
|
49
|
+
const t = (0, _tokenRegistry.getResolvedTokens)(preset, resolved);
|
|
51
50
|
const isDark = resolved === 'dark';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
51
|
+
|
|
52
|
+
// Read a resolved `rgb(...)` token by its bare name (no leading `--`).
|
|
53
|
+
const g = k => t[`--${k}`] ?? 'rgb(0 0 0)';
|
|
54
|
+
|
|
55
|
+
// Convert a computed `H S% L%` triple to the canonical `rgb(...)` via the
|
|
56
|
+
// registry's single HSL→sRGB conversion (matches the old `hsl(h,s%,l%)`).
|
|
57
|
+
const hslRgb = (h, s, l) => (0, _tokenRegistry.hslToSrgb)(`${h} ${s}% ${l}%`);
|
|
58
|
+
|
|
59
|
+
// Brand hues seed the computed tints from the preset's raw HSL triples,
|
|
60
|
+
// exactly as the pre-0.8.0 logic did.
|
|
61
|
+
const presetTokens = isDark ? _colorPresets.APP_COLOR_PRESETS[preset].dark : _colorPresets.APP_COLOR_PRESETS[preset].light;
|
|
62
|
+
const pHue = extractHue(presetTokens['--primary'] ?? '0 0% 50%');
|
|
63
|
+
const dHue = extractHue(presetTokens['--destructive'] ?? '0 0% 0%');
|
|
59
64
|
return {
|
|
60
|
-
background,
|
|
61
|
-
backgroundSecondary: surface,
|
|
62
|
-
backgroundTertiary:
|
|
63
|
-
text:
|
|
64
|
-
textSecondary:
|
|
65
|
-
textTertiary:
|
|
66
|
-
border:
|
|
67
|
-
borderLight:
|
|
68
|
-
primary:
|
|
69
|
-
primaryForeground,
|
|
70
|
-
// Legacy aliases
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
iconActive: primaryColor,
|
|
65
|
+
background: g('background'),
|
|
66
|
+
backgroundSecondary: g('surface'),
|
|
67
|
+
backgroundTertiary: g('muted'),
|
|
68
|
+
text: g('foreground'),
|
|
69
|
+
textSecondary: g('muted-foreground'),
|
|
70
|
+
textTertiary: g('muted-foreground'),
|
|
71
|
+
border: g('border'),
|
|
72
|
+
borderLight: g('input'),
|
|
73
|
+
primary: g('primary'),
|
|
74
|
+
primaryForeground: g('primary-foreground'),
|
|
75
|
+
// Legacy aliases (see types.ts): `primaryLight` is the page surface tint,
|
|
76
|
+
// `primaryDark` is the page background — retained for downstream consumers.
|
|
77
|
+
primaryLight: g('surface'),
|
|
78
|
+
primaryDark: g('background'),
|
|
79
|
+
// `secondary` historically mirrors `primary`. Retained for compatibility.
|
|
80
|
+
secondary: g('primary'),
|
|
81
|
+
tint: g('primary'),
|
|
82
|
+
icon: g('muted-foreground'),
|
|
83
|
+
iconActive: g('primary'),
|
|
80
84
|
...STATUS_COLORS,
|
|
81
|
-
primarySubtle: isDark ?
|
|
82
|
-
primarySubtleForeground: isDark ?
|
|
83
|
-
negative:
|
|
85
|
+
primarySubtle: isDark ? hslRgb(pHue, 50, 10) : hslRgb(pHue, 70, 93),
|
|
86
|
+
primarySubtleForeground: isDark ? hslRgb(pHue, 70, 65) : hslRgb(pHue, 90, 25),
|
|
87
|
+
negative: hslRgb(dHue, 84, 45),
|
|
84
88
|
negativeForeground: '#FFFFFF',
|
|
85
|
-
negativeSubtle: isDark ?
|
|
86
|
-
negativeSubtleForeground: isDark ?
|
|
87
|
-
contrast50: isDark ?
|
|
88
|
-
card: surface,
|
|
89
|
+
negativeSubtle: isDark ? hslRgb(dHue, 50, 10) : hslRgb(dHue, 90, 95),
|
|
90
|
+
negativeSubtleForeground: isDark ? hslRgb(dHue, 70, 65) : hslRgb(dHue, 80, 40),
|
|
91
|
+
contrast50: isDark ? hslRgb(pHue, 15, 12) : hslRgb(pHue, 10, 93),
|
|
92
|
+
card: g('surface'),
|
|
89
93
|
shadow: isDark ? 'rgba(0, 0, 0, 0.3)' : 'rgba(0, 0, 0, 0.1)',
|
|
90
94
|
overlay: 'rgba(0, 0, 0, 0.5)'
|
|
91
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_colorPresets","_adaptiveColors","STATUS_COLORS","exports","success","error","warning","info","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_colorPresets","_adaptiveColors","_tokenRegistry","STATUS_COLORS","exports","success","error","warning","info","extractHue","triple","first","split","replace","hue","parseInt","Number","isFinite","buildColorsFromPreset","preset","resolved","t","getResolvedTokens","isDark","g","k","hslRgb","h","s","l","hslToSrgb","presetTokens","APP_COLOR_PRESETS","dark","light","pHue","dHue","background","backgroundSecondary","backgroundTertiary","text","textSecondary","textTertiary","border","borderLight","primary","primaryForeground","primaryLight","primaryDark","secondary","tint","icon","iconActive","primarySubtle","primarySubtleForeground","negative","negativeForeground","negativeSubtle","negativeSubtleForeground","contrast50","card","shadow","overlay","buildTheme","isAdaptive","adaptive","Platform","OS","getAdaptiveColors","undefined","colors","mode","isLight"],"sourceRoot":"../../../src","sources":["theme/build-theme.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AAGA;AACA;AACA;AACA;AACO,MAAMI,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG;EAC3BE,OAAO,EAAE,SAAS;EAClBC,KAAK,EAAE,SAAS;EAChBC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE;AACR,CAAU;;AAEV;AACA;AACA;AACA;AACA;AAC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ACpEsB,wBAAwB,EAAEnC,MAAM,GAAGG,MAAM,CAACU,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,GAAGV,MAAM,CAACU,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC;IAC9EuB,UAAU,EAAEpC,MAAM,GAAGG,MAAM,CAACS,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,GAAGT,MAAM,CAACS,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC;IAEhEyB,IAAI,EAAEpC,CAAC,CAAC,SAAS,CAAC;IAClBqC,MAAM,EAAEtC,MAAM,GAAG,oBAAoB,GAAG,oBAAoB;IAC5DuC,OAAO,EAAE;EACX,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CACxB5C,MAAoB,EACpBC,QAA0B,EAC1B4C,UAAmB,GAAG,KAAK,EACpB;EACP,MAAMC,QAAQ,GAAGD,UAAU,IAAIE,qBAAQ,CAACC,EAAE,KAAK,KAAK,GAAG,IAAAC,iCAAiB,EAAC,CAAC,GAAGC,SAAS;EACtF,MAAMC,MAAM,GAAGL,QAAQ,IAAI/C,qBAAqB,CAACC,MAAM,EAAEC,QAAQ,CAAC;EAElE,OAAO;IACLmD,IAAI,EAAEnD,QAAQ;IACdkD,MAAM;IACN/C,MAAM,EAAEH,QAAQ,KAAK,MAAM;IAC3BoD,OAAO,EAAEpD,QAAQ,KAAK;EACxB,CAAC;AACH","ignoreList":[]}
|
|
@@ -11,17 +11,17 @@ exports.hexToAppColorName = hexToAppColorName;
|
|
|
11
11
|
* Keys carry a leading `--` for historical reasons (shadcn-style CSS variable
|
|
12
12
|
* names) — keep in mind the values are platform-agnostic **raw HSL triples**
|
|
13
13
|
* (e.g. `'185 100% 20%'` or `'185 100% 20% / 0.5'`), not CSS-resolved colors.
|
|
14
|
-
* The
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
14
|
+
* The single canonical resolver `getResolvedTokens` (in `token-registry.ts`)
|
|
15
|
+
* converts this raw map to sRGB `rgb(...)` for every runtime write — the same
|
|
16
|
+
* values drive BOTH layers:
|
|
17
|
+
* - the web layer: `getResolvedTokens`'s `rgb(...)` strings are written to
|
|
18
|
+
* `document.documentElement` / a `BloomColorScope` element, so `var(--x)` —
|
|
19
|
+
* the form Tailwind v4 `@theme inline` compiles its color utilities to —
|
|
20
|
+
* resolves to a valid color directly, and
|
|
21
21
|
* - the native layer (`buildTheme` resolves the raw triples into `hsl(...)`
|
|
22
22
|
* strings consumable by React Native styles; `native-root-vars.native.ts`
|
|
23
|
-
* writes the
|
|
24
|
-
*
|
|
23
|
+
* writes the same canonical `rgb(...)` values into react-native-css's
|
|
24
|
+
* `rootVariables` family).
|
|
25
25
|
*
|
|
26
26
|
* The `--` prefix is an implementation detail we will drop in a future major.
|
|
27
27
|
*/
|
|
@@ -8,24 +8,17 @@ exports.useColorScopeStyle = useColorScopeStyle;
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _BloomThemeProvider = require("../BloomThemeProvider.js");
|
|
10
10
|
var _buildTheme = require("../build-theme.js");
|
|
11
|
-
var
|
|
12
|
-
var _styleBuilder = require("./style-builder.js");
|
|
11
|
+
var _tokenRegistry = require("../token-registry.js");
|
|
13
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
13
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
14
|
/**
|
|
16
|
-
* `
|
|
17
|
-
*
|
|
18
|
-
* element's inline `style`,
|
|
19
|
-
* `var(--x)` directly
|
|
20
|
-
*
|
|
21
|
-
* non-color tokens pass through. See `toWebColorValue` in `../preset-vars`.
|
|
15
|
+
* `getResolvedTokens` returns every canonical token already resolved to an sRGB
|
|
16
|
+
* `rgb(...)` string — the SAME pipeline the document-root web writer and the
|
|
17
|
+
* native writer use. Scoped onto an element's inline `style`, Tailwind v4's
|
|
18
|
+
* compiled utilities read these as `var(--x)` directly, so each base token is a
|
|
19
|
+
* full CSS color with no per-value wrapping needed.
|
|
22
20
|
*/function buildWebScopeVars(colorPreset, mode) {
|
|
23
|
-
|
|
24
|
-
const out = {};
|
|
25
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
26
|
-
out[key] = (0, _presetVars.toWebColorValue)(key, value);
|
|
27
|
-
}
|
|
28
|
-
return out;
|
|
21
|
+
return (0, _tokenRegistry.getResolvedTokens)(colorPreset, mode);
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_BloomThemeProvider","_buildTheme","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_BloomThemeProvider","_buildTheme","_tokenRegistry","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","buildWebScopeVars","colorPreset","mode","getResolvedTokens","BloomColorScope","asChild","style","children","parent","useContext","BloomThemeContext","Error","jsx","Fragment","resolvedMode","theme","contextValue","useMemo","buildTheme","varsStyle","content","child","Children","only","isValidElement","childStyle","props","mergedStyle","cloneElement","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.web.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OA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AC5DL,OAAO,gBAAG,IAAAQ,mBAAY,EAACP,KAAK,EAAE;MAAEf,KAAK,EAAEqB;IAAY,CAAC,CAAC;EACvD,CAAC,MAAM;IACL;IACA;IACA,MAAMA,WAAgC,GAAG;MAAE,GAAGR,SAAS;MAAE,GAAGb;IAAM,CAAC;IACnEc,OAAO,gBAAG,IAAAxC,WAAA,CAAAgC,GAAA;MAAKN,KAAK,EAAEqB,WAAY;MAAApB,QAAA,EAAEA;IAAQ,CAAM,CAAC;EACrD;EAEA,oBAAO,IAAA3B,WAAA,CAAAgC,GAAA,EAACnC,mBAAA,CAAAiC,iBAAiB,CAACmB,QAAQ;IAACC,KAAK,EAAEd,YAAa;IAAAT,QAAA,EAAEa;EAAO,CAA6B,CAAC;AAChG;;AAEA;AACA;AACA;AACA;AACO,SAASW,kBAAkBA,CAAC9B,WAAyB,EAAuB;EACjF,MAAMO,MAAM,GAAG,IAAAC,iBAAU,EAACC,qCAAiB,CAAC;EAC5C,IAAI,CAACF,MAAM,EAAE;IACX,MAAM,IAAIG,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,MAAMG,YAAY,GAAGN,MAAM,CAACO,KAAK,CAACb,IAAI;EACtC,OAAO,IAAAe,cAAO,EACZ,MAAMjB,iBAAiB,CAACC,WAAW,EAAEa,YAAY,CAAC,EAClD,CAACb,WAAW,EAAEa,YAAY,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -7,7 +7,7 @@ exports.buildNativePresetStyle = buildNativePresetStyle;
|
|
|
7
7
|
exports.buildScopeVars = buildScopeVars;
|
|
8
8
|
exports.getVariableContextProvider = getVariableContextProvider;
|
|
9
9
|
var _reactNative = require("react-native");
|
|
10
|
-
var
|
|
10
|
+
var _tokenRegistry = require("../token-registry.js");
|
|
11
11
|
var _lazyRequire = require("../../utils/lazy-require.js");
|
|
12
12
|
/**
|
|
13
13
|
* Component that provides inline CSS variables to a subtree via NativeWind's
|
|
@@ -20,13 +20,14 @@ const getNativeWindVars = (0, _lazyRequire.lazyRequire)('nativewind');
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Build the CSS custom-property map for a preset, ready to be applied to a
|
|
23
|
-
* subtree.
|
|
24
|
-
*
|
|
23
|
+
* subtree. Every token is resolved to an sRGB `rgb(...)` string via
|
|
24
|
+
* `getResolvedTokens` — the single canonical token pipeline shared by web and
|
|
25
|
+
* native — so Tailwind v4 `@theme` utilities (e.g. `bg-background`) and
|
|
26
|
+
* `color-mix`-based alpha utilities (`bg-primary/10`) both resolve against the
|
|
27
|
+
* same color values. Keys retain the leading `--`.
|
|
25
28
|
*/
|
|
26
29
|
function buildScopeVars(colorPreset, mode) {
|
|
27
|
-
return (0,
|
|
28
|
-
includeResolvedColorVars: true
|
|
29
|
-
});
|
|
30
|
+
return (0, _tokenRegistry.getResolvedTokens)(colorPreset, mode);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_tokenRegistry","_lazyRequire","getNativeWindVars","lazyRequire","buildScopeVars","colorPreset","mode","getResolvedTokens","getVariableContextProvider","Platform","OS","module","VariableContextProvider","buildNativePresetStyle","undefined","vars"],"sourceRoot":"../../../../src","sources":["theme/color-scope/style-builder.ts"],"mappings":";;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;;AAWA,MAAMG,iBAAiB,GAAG,IAAAC,wBAAW,EAAuB,YAAY,CAAC;;AAEzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAC5BC,WAAyB,EACzBC,IAAsB,EACE;EACxB,OAAO,IAAAC,gCAAiB,EAACF,WAAW,EAAEC,IAAI,CAAC;AAC7C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,0BAA0BA,CAAA,EAA4C;EACpF,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE,OAAO,IAAI;EACtC,MAAMC,MAAM,GAAGT,iBAAiB,CAAC,CAAC;EAClC,IAAI,CAACS,MAAM,IAAI,OAAOA,MAAM,CAACC,uBAAuB,KAAK,UAAU,EAAE,OAAO,IAAI;EAChF,OAAOD,MAAM,CAACC,uBAAuB;AACvC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,sBAAsBA,CACpCR,WAAyB,EACzBC,IAAsB,EACA;EACtB,IAAIG,qBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE,OAAOI,SAAS;EAC3C,MAAMH,MAAM,GAAGT,iBAAiB,CAAC,CAAC;EAClC,IAAI,CAACS,MAAM,IAAI,OAAOA,MAAM,CAACI,IAAI,KAAK,UAAU,EAAE,OAAOD,SAAS;EAClE,OAAOH,MAAM,CAACI,IAAI,CAACX,cAAc,CAACC,WAAW,EAAEC,IAAI,CAAC,CAAC;AACvD","ignoreList":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deltaE = deltaE;
|
|
7
|
+
exports.oklchToSrgb = oklchToSrgb;
|
|
8
|
+
exports.parseRgbString = parseRgbString;
|
|
9
|
+
exports.srgbToRgbString = srgbToRgbString;
|
|
10
|
+
// l 0..1, c 0..~0.4, h deg
|
|
11
|
+
// 0..255 integers
|
|
12
|
+
|
|
13
|
+
const clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));
|
|
14
|
+
const srgbGamma = x => x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055;
|
|
15
|
+
|
|
16
|
+
/** OKLCH → linear OKLab → linear sRGB → gamma sRGB → 0..255. Pure. */
|
|
17
|
+
function oklchToSrgb({
|
|
18
|
+
l,
|
|
19
|
+
c,
|
|
20
|
+
h
|
|
21
|
+
}) {
|
|
22
|
+
const hr = h * Math.PI / 180;
|
|
23
|
+
const a = c * Math.cos(hr);
|
|
24
|
+
const b2 = c * Math.sin(hr);
|
|
25
|
+
const l_ = l + 0.3963377774 * a + 0.2158037573 * b2;
|
|
26
|
+
const m_ = l - 0.1055613458 * a - 0.0638541728 * b2;
|
|
27
|
+
const s_ = l - 0.0894841775 * a - 1.291485548 * b2;
|
|
28
|
+
const lc = l_ ** 3,
|
|
29
|
+
mc = m_ ** 3,
|
|
30
|
+
sc = s_ ** 3;
|
|
31
|
+
const lr = +4.0767416621 * lc - 3.3077115913 * mc + 0.2309699292 * sc;
|
|
32
|
+
const lg = -1.2684380046 * lc + 2.6097574011 * mc - 0.3413193965 * sc;
|
|
33
|
+
const lb = -0.0041960863 * lc - 0.7034186147 * mc + 1.707614701 * sc;
|
|
34
|
+
return {
|
|
35
|
+
r: Math.round(clamp(srgbGamma(lr), 0, 1) * 255),
|
|
36
|
+
g: Math.round(clamp(srgbGamma(lg), 0, 1) * 255),
|
|
37
|
+
b: Math.round(clamp(srgbGamma(lb), 0, 1) * 255)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function srgbToRgbString({
|
|
41
|
+
r,
|
|
42
|
+
g,
|
|
43
|
+
b
|
|
44
|
+
}, alpha) {
|
|
45
|
+
return alpha === undefined || alpha >= 1 ? `rgb(${r} ${g} ${b})` : `rgb(${r} ${g} ${b} / ${alpha})`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parse an `rgb(...)` / `rgba(...)` string into an {@link Rgb}.
|
|
50
|
+
*
|
|
51
|
+
* Contract: input MUST be an `rgb(...)` / `rgba(...)` string (e.g. a resolved
|
|
52
|
+
* token from `getResolvedTokens`). Both modern (`rgb(r g b)`) and legacy
|
|
53
|
+
* (`rgb(r, g, b)`) syntaxes are accepted. Anything else throws — this is a
|
|
54
|
+
* canonical-pipeline primitive and a non-rgb input signals a real bug at the
|
|
55
|
+
* call site, never a value to silently coerce to black.
|
|
56
|
+
*
|
|
57
|
+
* @throws {Error} if `s` is not an `rgb()` / `rgba()` string.
|
|
58
|
+
*/
|
|
59
|
+
function parseRgbString(s) {
|
|
60
|
+
const inner = s.match(/rgba?\(([^)]+)\)/i)?.[1];
|
|
61
|
+
if (inner === undefined) {
|
|
62
|
+
throw new Error(`parseRgbString: expected an rgb() string, got: ${s}`);
|
|
63
|
+
}
|
|
64
|
+
const [r, g, b] = inner.split(/[ ,/]+/).map(n => parseInt(n, 10));
|
|
65
|
+
return {
|
|
66
|
+
r: r ?? 0,
|
|
67
|
+
g: g ?? 0,
|
|
68
|
+
b: b ?? 0
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Cheap perceptual-ish distance in sRGB (sufficient for a ≤1 rounding gate). */
|
|
73
|
+
function deltaE(a, b) {
|
|
74
|
+
return Math.sqrt((a.r - b.r) ** 2 + (a.g - b.g) ** 2 + (a.b - b.b) ** 2) / Math.sqrt(3);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=color-space.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["clamp","n","lo","hi","Math","min","max","srgbGamma","x","pow","oklchToSrgb","l","c","h","hr","PI","a","cos","b2","sin","l_","m_","s_","lc","mc","sc","lr","lg","lb","r","round","g","b","srgbToRgbString","alpha","undefined","parseRgbString","s","inner","match","Error","split","map","parseInt","deltaE","sqrt"],"sourceRoot":"../../../src","sources":["theme/color-space.ts"],"mappings":";;;;;;;;;AAA2D;AACA;;AAE3D,MAAMA,KAAK,GAAGA,CAACC,CAAS,EAAEC,EAAU,EAAEC,EAAU,KAAKC,IAAI,CAACC,GAAG,CAACF,EAAE,EAAEC,IAAI,CAACE,GAAG,CAACJ,EAAE,EAAED,C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AE,CAAC;AAC5C;;AAEA;AACO,SAASY,MAAMA,CAAC5B,CAAM,EAAEgB,CAAM,EAAU;EAC7C,OAAO5B,IAAI,CAACyC,IAAI,CAAC,CAAC7B,CAAC,CAACa,CAAC,GAAGG,CAAC,CAACH,CAAC,KAAK,CAAC,GAAG,CAACb,CAAC,CAACe,CAAC,GAAGC,CAAC,CAACD,CAAC,KAAK,CAAC,GAAG,CAACf,CAAC,CAACgB,CAAC,GAAGA,CAAC,CAACA,CAAC,KAAK,CAAC,CAAC,GAAG5B,IAAI,CAACyC,IAAI,CAAC,CAAC,CAAC;AACzF","ignoreList":[]}
|
|
@@ -87,12 +87,6 @@ Object.defineProperty(exports, "setColorSchemeSafe", {
|
|
|
87
87
|
return _setColorSchemeSafe.setColorSchemeSafe;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
-
Object.defineProperty(exports, "toWebColorValue", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return _presetVars.toWebColorValue;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
90
|
Object.defineProperty(exports, "useBloomTheme", {
|
|
97
91
|
enumerable: true,
|
|
98
92
|
get: function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_BloomThemeProvider","require","_colorScope","_buildTheme","_useTheme","_colorPresets","_presetVars","_applyDarkClass","_setColorSchemeSafe","_initCssInterop","_persistence"],"sourceRoot":"../../../src","sources":["theme/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_BloomThemeProvider","require","_colorScope","_buildTheme","_useTheme","_colorPresets","_presetVars","_applyDarkClass","_setColorSchemeSafe","_initCssInterop","_persistence"],"sourceRoot":"../../../src","sources":["theme/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAGA,IAAAI,aAAA,GAAAJ,OAAA;AAOA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,mBAAA,GAAAP,OAAA;AACA,IAAAQ,eAAA,GAAAR,OAAA;AAEA,IAAAS,YAAA,GAAAT,OAAA","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.applyNativeRootVars = applyNativeRootVars;
|
|
7
7
|
var _nativeInternal = require("react-native-css/native-internal");
|
|
8
|
-
var
|
|
8
|
+
var _tokenRegistry = require("./token-registry.js");
|
|
9
9
|
/// <reference path="../react-native-css.d.ts" />
|
|
10
10
|
// The triple-slash reference above pins Bloom's ambient declaration for
|
|
11
11
|
// `react-native-css/native-internal` (`src/react-native-css.d.ts`) into the
|
|
@@ -45,18 +45,28 @@ var _styleBuilder = require("./color-scope/style-builder.js");
|
|
|
45
45
|
* `BloomThemeProvider`'s `VariableContextProvider` only feeds path #1, so the navigator
|
|
46
46
|
* host and every portal/modal — which render outside that subtree — never see the
|
|
47
47
|
* preset vars and fall through to `rootVariables`/`universalVariables`. By default those
|
|
48
|
-
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* content resolves the palette identically regardless of React-tree position.
|
|
48
|
+
* families hold only react-native-css's own `__rn-css-rem`/`__rn-css-color` entries, so
|
|
49
|
+
* the whole tree below the navigator renders monochrome until the palette is injected at
|
|
50
|
+
* runtime. Writing the vars into `rootVariables` here is the exact same mechanism
|
|
51
|
+
* react-native-css uses for compiled `:root {}` / `@theme` vars (`StyleCollection.inject`
|
|
52
|
+
* does `rootVariables(name).set(valueArray)`), so portaled content resolves the palette
|
|
53
|
+
* identically regardless of React-tree position.
|
|
55
54
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
55
|
+
* Consumer contract (CRITICAL — single canonical color pipeline)
|
|
56
|
+
* -------------------------------------------------------------
|
|
57
|
+
* Each base `--x` token is now written as a FULL `rgb(...)` color (not a raw HSL
|
|
58
|
+
* triple). A consuming app's Tailwind `@theme` must therefore reference these
|
|
59
|
+
* base tokens DIRECTLY (its Tailwind color var equals `var(--x)`) and must NOT
|
|
60
|
+
* wrap them in `hsl(...)`. The legacy `hsl(var(--x))` indirection (which assumed
|
|
61
|
+
* a raw triple) would produce the invalid `hsl(rgb(...))` and must be removed in
|
|
62
|
+
* every consumer. Web and native now share this one contract.
|
|
63
|
+
*
|
|
64
|
+
* Every token is written as an sRGB `rgb(...)` string from the single canonical
|
|
65
|
+
* token pipeline (`getResolvedTokens`) — `primary: 'rgb(31 153 239)'` — the SAME
|
|
66
|
+
* values web writes to `document.documentElement`. sRGB is the space
|
|
67
|
+
* react-native-css's `color-mix` resolver registers, so `color-mix`-based alpha
|
|
68
|
+
* utilities (`bg-primary/10`) resolve on native; full (non-alpha) utilities
|
|
69
|
+
* resolve directly through bloom's `global.css` `var(--x)` indirection.
|
|
60
70
|
*
|
|
61
71
|
* Why a STATIC `import`, not a runtime `require` (critical)
|
|
62
72
|
* ---------------------------------------------------------
|
|
@@ -86,15 +96,15 @@ var _styleBuilder = require("./color-scope/style-builder.js");
|
|
|
86
96
|
* `shared.rootVariables[name]`, and `@property --x` goes through
|
|
87
97
|
* `name.startsWith("--") ? name.slice(2) : name`. The lookup side matches: a `var(--x)`
|
|
88
98
|
* reference compiles to `[{}, "var", ident.slice(2)]`, so `varResolver` looks up the
|
|
89
|
-
* bare name. `
|
|
90
|
-
* writing each entry.
|
|
99
|
+
* bare name. `getResolvedTokens` returns keys WITH the `--` prefix, so we strip it
|
|
100
|
+
* before writing each entry.
|
|
91
101
|
*
|
|
92
102
|
* Value shape
|
|
93
103
|
* -----------
|
|
94
104
|
* Each entry is a `VariableValue[]` — an array of `[value, mediaCondition?]` tuples.
|
|
95
105
|
* Bloom's preset vars are unconditional, so each is a single-element `[[value]]`, e.g.
|
|
96
|
-
* `rootVariables('primary').set([['
|
|
97
|
-
* emits for unconditional `:root` vars.
|
|
106
|
+
* `rootVariables('primary').set([['rgb(31 153 239)']])`. This is the same shape the
|
|
107
|
+
* compiler emits for unconditional `:root` vars.
|
|
98
108
|
*
|
|
99
109
|
* This is native-only and additive: the `VariableContextProvider` wrapper stays (it is
|
|
100
110
|
* the correct, scoped mechanism for `BloomColorScope` subtree overrides and harmlessly
|
|
@@ -117,9 +127,9 @@ var _styleBuilder = require("./color-scope/style-builder.js");
|
|
|
117
127
|
*/
|
|
118
128
|
function applyNativeRootVars(colorPreset, mode) {
|
|
119
129
|
if (typeof _nativeInternal.rootVariables !== 'function') return;
|
|
120
|
-
const vars = (0,
|
|
130
|
+
const vars = (0, _tokenRegistry.getResolvedTokens)(colorPreset, mode);
|
|
121
131
|
for (const [key, value] of Object.entries(vars)) {
|
|
122
|
-
// The family is keyed by the bare name; `
|
|
132
|
+
// The family is keyed by the bare name; `getResolvedTokens` keys include `--`.
|
|
123
133
|
const name = key.startsWith('--') ? key.slice(2) : key;
|
|
124
134
|
(0, _nativeInternal.rootVariables)(name).set([[value]]);
|
|
125
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_nativeInternal","require","
|
|
1
|
+
{"version":3,"names":["_nativeInternal","require","_tokenRegistry","applyNativeRootVars","colorPreset","mode","rootVariables","vars","getResolvedTokens","key","value","Object","entries","name","startsWith","slice","set"],"sourceRoot":"../../../src","sources":["theme/native-root-vars.native.ts"],"mappings":";;;;;;AAgBA,IAAAA,eAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;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;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,gCAAiB,EAACJ,WAAW,EAAEC,IAAI,CAAC;EACjD,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":[]}
|