@oxyhq/bloom 0.39.0 → 0.40.0
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/build-theme-from-seed.js +90 -0
- package/lib/commonjs/theme/build-theme-from-seed.js.map +1 -0
- package/lib/commonjs/theme/index.js +94 -0
- package/lib/commonjs/theme/index.js.map +1 -1
- package/lib/commonjs/theme/seed-scope/index.js +87 -0
- package/lib/commonjs/theme/seed-scope/index.js.map +1 -0
- package/lib/commonjs/theme/seed-scope/index.web.js +86 -0
- package/lib/commonjs/theme/seed-scope/index.web.js.map +1 -0
- package/lib/module/theme/build-theme-from-seed.js +85 -0
- package/lib/module/theme/build-theme-from-seed.js.map +1 -0
- package/lib/module/theme/index.js +7 -0
- package/lib/module/theme/index.js.map +1 -1
- package/lib/module/theme/seed-scope/index.js +82 -0
- package/lib/module/theme/seed-scope/index.js.map +1 -0
- package/lib/module/theme/seed-scope/index.web.js +81 -0
- package/lib/module/theme/seed-scope/index.web.js.map +1 -0
- package/lib/typescript/commonjs/theme/build-theme-from-seed.d.ts +23 -0
- package/lib/typescript/commonjs/theme/build-theme-from-seed.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/index.d.ts +7 -0
- package/lib/typescript/commonjs/theme/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/seed-scope/index.d.ts +37 -0
- package/lib/typescript/commonjs/theme/seed-scope/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/seed-scope/index.web.d.ts +35 -0
- package/lib/typescript/commonjs/theme/seed-scope/index.web.d.ts.map +1 -0
- package/lib/typescript/module/theme/build-theme-from-seed.d.ts +23 -0
- package/lib/typescript/module/theme/build-theme-from-seed.d.ts.map +1 -0
- package/lib/typescript/module/theme/index.d.ts +7 -0
- package/lib/typescript/module/theme/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/seed-scope/index.d.ts +37 -0
- package/lib/typescript/module/theme/seed-scope/index.d.ts.map +1 -0
- package/lib/typescript/module/theme/seed-scope/index.web.d.ts +35 -0
- package/lib/typescript/module/theme/seed-scope/index.web.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/theme/__tests__/build-theme-from-seed-parity.test.ts +33 -0
- package/src/theme/build-theme-from-seed.ts +99 -0
- package/src/theme/index.ts +21 -0
- package/src/theme/seed-scope/index.tsx +100 -0
- package/src/theme/seed-scope/index.web.tsx +110 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { Children, cloneElement, isValidElement, useContext, useMemo } from 'react';
|
|
4
|
+
import { BloomThemeContext } from "../BloomThemeProvider.js";
|
|
5
|
+
import { buildSeedScopeVars } from "../color-scope/seed-scope.js";
|
|
6
|
+
import { buildThemeFromSeed } from "../build-theme-from-seed.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* On web the single `asChild` child is frequently a react-native-web component
|
|
10
|
+
* whose `style` prop is a style ARRAY (or a numeric registered-style id), not a
|
|
11
|
+
* plain object. Spreading such an array into an object literal would copy its
|
|
12
|
+
* numeric indices as keys and crash RNW; merge as an array instead.
|
|
13
|
+
*/
|
|
14
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
/**
|
|
16
|
+
* Web `<BloomSeedScope>`: scopes a subtree to an ARBITRARY seed colour's palette
|
|
17
|
+
* (the dynamic counterpart of `<BloomColorScope>`). It (1) writes every canonical
|
|
18
|
+
* `--x` token plus the Tailwind v4 `--color-x` aliases (already resolved to
|
|
19
|
+
* `rgb(...)`) onto the wrapping element's inline `style`, so NativeWind classes
|
|
20
|
+
* inside resolve against the seed palette instead of the document root, and
|
|
21
|
+
* (2) publishes a matching JS `theme` on `BloomThemeContext` so
|
|
22
|
+
* `useTheme()`/`useBloomTheme()` consumers inside the subtree re-theme too. The
|
|
23
|
+
* `colorPreset` field is left as the parent's (a seed is not a named preset).
|
|
24
|
+
*/
|
|
25
|
+
export function BloomSeedScope({
|
|
26
|
+
seed,
|
|
27
|
+
variant,
|
|
28
|
+
contrastLevel,
|
|
29
|
+
asChild = false,
|
|
30
|
+
style,
|
|
31
|
+
children
|
|
32
|
+
}) {
|
|
33
|
+
const parent = useContext(BloomThemeContext);
|
|
34
|
+
const resolvedMode = parent?.theme.mode ?? 'light';
|
|
35
|
+
const varsStyle = useMemo(() => seed ? buildSeedScopeVars({
|
|
36
|
+
seed,
|
|
37
|
+
mode: resolvedMode,
|
|
38
|
+
variant,
|
|
39
|
+
contrastLevel
|
|
40
|
+
}) : null, [seed, resolvedMode, variant, contrastLevel]);
|
|
41
|
+
const contextValue = useMemo(() => {
|
|
42
|
+
if (!parent || !seed) return null;
|
|
43
|
+
const theme = buildThemeFromSeed(seed, resolvedMode, variant, contrastLevel);
|
|
44
|
+
return {
|
|
45
|
+
...parent,
|
|
46
|
+
theme
|
|
47
|
+
};
|
|
48
|
+
}, [parent, seed, resolvedMode, variant, contrastLevel]);
|
|
49
|
+
if (!parent) {
|
|
50
|
+
throw new Error('BloomSeedScope must be used within a <BloomThemeProvider>');
|
|
51
|
+
}
|
|
52
|
+
if (!varsStyle || !contextValue) return /*#__PURE__*/_jsx(_Fragment, {
|
|
53
|
+
children: children
|
|
54
|
+
});
|
|
55
|
+
let content;
|
|
56
|
+
if (asChild) {
|
|
57
|
+
const child = Children.only(children);
|
|
58
|
+
if (! /*#__PURE__*/isValidElement(child)) {
|
|
59
|
+
throw new Error('BloomSeedScope with `asChild` requires a single React element child that accepts a `style` prop.');
|
|
60
|
+
}
|
|
61
|
+
const childStyle = child.props.style;
|
|
62
|
+
const mergedStyle = [varsStyle, style, childStyle];
|
|
63
|
+
content = /*#__PURE__*/cloneElement(child, {
|
|
64
|
+
style: mergedStyle
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
const mergedStyle = {
|
|
68
|
+
...varsStyle,
|
|
69
|
+
...style
|
|
70
|
+
};
|
|
71
|
+
content = /*#__PURE__*/_jsx("div", {
|
|
72
|
+
style: mergedStyle,
|
|
73
|
+
children: children
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return /*#__PURE__*/_jsx(BloomThemeContext.Provider, {
|
|
77
|
+
value: contextValue,
|
|
78
|
+
children: content
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=index.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","Children","cloneElement","isValidElement","useContext","useMemo","BloomThemeContext","buildSeedScopeVars","buildThemeFromSeed","Fragment","_Fragment","jsx","_jsx","BloomSeedScope","seed","variant","contrastLevel","asChild","style","children","parent","resolvedMode","theme","mode","varsStyle","contextValue","Error","content","child","only","childStyle","props","mergedStyle","Provider","value"],"sourceRoot":"../../../../src","sources":["theme/seed-scope/index.web.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAE1F,SAASC,iBAAiB,QAAqC,0BAAuB;AACtF,SAASC,kBAAkB,QAAQ,8BAA2B;AAC9D,SAASC,kBAAkB,QAAQ,6BAA0B;;AAyB7D;AACA;AACA;AACA;AACA;AACA;AALA,SAAAC,QAAA,IAAAC,SAAA,EAAAC,GAAA,IAAAC,IAAA;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAC;EAC7BC,IAAI;EACJC,OAAO;EACPC,aAAa;EACbC,OAAO,GAAG,KAAK;EACfC,KAAK;EACLC;AACmB,CAAC,EAAE;EACtB,MAAMC,MAAM,GAAGhB,UAAU,CAACE,iBAAiB,CAAC;EAC5C,MAAMe,YAAY,GAAGD,MAAM,EAAEE,KAAK,CAACC,IAAI,IAAI,OAAO;EAElD,MAAMC,SAAS,GAAGnB,OAAO,CACvB,MACES,IAAI,GACCP,kBAAkB,CAAC;IAClBO,IAAI;IACJS,IAAI,EAAE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Ec,WAAY;MAAAb,QAAA,EAAEA;IAAQ,CAAM,CAAC;EACrD;EAEA,oBAAOP,IAAA,CAACN,iBAAiB,CAAC2B,QAAQ;IAACC,KAAK,EAAET,YAAa;IAAAN,QAAA,EAAEQ;EAAO,CAA6B,CAAC;AAChG","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SchemeVariant } from './color-engine';
|
|
2
|
+
import type { Theme, ThemeColors } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Build the JS `theme.colors` object from an ARBITRARY seed colour — the dynamic
|
|
5
|
+
* counterpart of `buildTheme(preset, …)`.
|
|
6
|
+
*
|
|
7
|
+
* This mirrors `buildColorsFromPreset` (`build-theme.ts`) field-for-field, but
|
|
8
|
+
* sources its tokens from `buildSeedScopeVars({ seed })` instead of a named
|
|
9
|
+
* preset, so a preset's seed reproduces that preset's JS theme exactly. Keeping
|
|
10
|
+
* the two in lockstep is enforced by `__tests__/build-theme-from-seed-parity.test.ts`.
|
|
11
|
+
*
|
|
12
|
+
* Token-backed fields read the resolved `rgb(...)` token map; the brand-tint
|
|
13
|
+
* family (primarySubtle / negative / …) reads the engine's container/error roles
|
|
14
|
+
* directly — identical to the preset path.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildColorsFromSeed(seed: string, resolved: 'light' | 'dark', variant?: SchemeVariant, contrastLevel?: number): ThemeColors;
|
|
17
|
+
/**
|
|
18
|
+
* Build a full `Theme` from a seed colour and a resolved light/dark mode. Unlike
|
|
19
|
+
* `buildTheme`, there is no adaptive (Material You / iOS dynamic) override — a
|
|
20
|
+
* seed IS the dynamic source here.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildThemeFromSeed(seed: string, resolved: 'light' | 'dark', variant?: SchemeVariant, contrastLevel?: number): Theme;
|
|
23
|
+
//# sourceMappingURL=build-theme-from-seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-theme-from-seed.d.ts","sourceRoot":"","sources":["../../../../src/theme/build-theme-from-seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIzF,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,OAAO,CAAC,EAAE,aAAa,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,WAAW,CAsDb;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,OAAO,CAAC,EAAE,aAAa,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,KAAK,CAQP"}
|
|
@@ -2,7 +2,14 @@ export { BloomThemeProvider } from './BloomThemeProvider';
|
|
|
2
2
|
export type { BloomThemeProviderProps, BloomThemeContextValue, } from './BloomThemeProvider';
|
|
3
3
|
export { BloomColorScope, useColorScopeStyle } from './color-scope';
|
|
4
4
|
export type { BloomColorScopeProps } from './color-scope';
|
|
5
|
+
export { BloomSeedScope } from './seed-scope';
|
|
6
|
+
export type { BloomSeedScopeProps } from './seed-scope';
|
|
7
|
+
export { buildSeedScopeVars, roleColorsToPresetTokens } from './color-scope/seed-scope';
|
|
8
|
+
export type { SeedScopeOptions } from './color-scope/seed-scope';
|
|
9
|
+
export { generateRoleColors, seedHexFromImagePixels, seedsFromImagePixels, quantizeImage, argbFromHex, hexFromArgb, argbFromRgb, redFromArgb, greenFromArgb, blueFromArgb, } from './color-engine';
|
|
10
|
+
export type { RoleColors, GenerateOptions, RoleName, SchemeVariant } from './color-engine';
|
|
5
11
|
export { buildTheme, STATUS_COLORS } from './build-theme';
|
|
12
|
+
export { buildThemeFromSeed, buildColorsFromSeed } from './build-theme-from-seed';
|
|
6
13
|
export { THEME_GRADIENTS } from './gradients';
|
|
7
14
|
export { useTheme, useThemeColor, useBloomTheme } from './use-theme';
|
|
8
15
|
export { useNavigationTheme } from './use-navigation-theme';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EACV,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACnF,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAo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AAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACnF,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import type { SchemeVariant } from '../color-engine';
|
|
4
|
+
export interface BloomSeedScopeProps {
|
|
5
|
+
/**
|
|
6
|
+
* The seed colour (`#rrggbb`) to derive this subtree's palette from. When
|
|
7
|
+
* `undefined`, the scope is a no-op and children inherit the parent scope
|
|
8
|
+
* unchanged — pass `undefined` to fall back to the app preset (e.g. on
|
|
9
|
+
* mouse-leave/blur when restoring the default theme).
|
|
10
|
+
*/
|
|
11
|
+
seed: string | undefined;
|
|
12
|
+
/** Tonal scheme variant. Defaults to `'vibrant'` (matches Bloom presets). */
|
|
13
|
+
variant?: SchemeVariant;
|
|
14
|
+
/** −1 (low) … 0 (normal) … 1 (high). Defaults to 0. */
|
|
15
|
+
contrastLevel?: number;
|
|
16
|
+
/**
|
|
17
|
+
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
18
|
+
* with the caller's `style` merged into its `style` prop (Radix-style).
|
|
19
|
+
*/
|
|
20
|
+
asChild?: boolean;
|
|
21
|
+
/** Additional style applied to the wrapping `<View>` (or merged into the cloned child with `asChild`). */
|
|
22
|
+
style?: StyleProp<ViewStyle>;
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Native `<BloomSeedScope>`: scopes a subtree to an ARBITRARY seed colour's
|
|
27
|
+
* palette (the dynamic counterpart of `<BloomColorScope>`, which takes a named
|
|
28
|
+
* preset). Feeds the seed through the colour engine and (1) provides the
|
|
29
|
+
* resulting canonical CSS vars to descendants via react-native-css's
|
|
30
|
+
* `VariableContext` — so `bg-background` / `bg-card` / `var(--primary)` resolve
|
|
31
|
+
* against the seed inside this subtree — and (2) publishes a matching JS `theme`
|
|
32
|
+
* on `BloomThemeContext`, so `useTheme()`/`useBloomTheme()` consumers inside the
|
|
33
|
+
* subtree also re-theme. The `colorPreset` field is left as the parent's (a seed
|
|
34
|
+
* is not a named preset).
|
|
35
|
+
*/
|
|
36
|
+
export declare function BloomSeedScope({ seed, variant, contrastLevel, asChild, style, children, }: BloomSeedScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/seed-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAMpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,mBAAmB,2CA8CrB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SchemeVariant } from '../color-engine';
|
|
3
|
+
export interface BloomSeedScopeProps {
|
|
4
|
+
/**
|
|
5
|
+
* The seed colour (`#rrggbb`) to derive this subtree's palette from. When
|
|
6
|
+
* `undefined`, the scope is a no-op and children inherit the parent scope
|
|
7
|
+
* unchanged — pass `undefined` to fall back to the app preset (e.g. on
|
|
8
|
+
* mouse-leave/blur when restoring the default theme).
|
|
9
|
+
*/
|
|
10
|
+
seed: string | undefined;
|
|
11
|
+
/** Tonal scheme variant. Defaults to `'vibrant'` (matches Bloom presets). */
|
|
12
|
+
variant?: SchemeVariant;
|
|
13
|
+
/** −1 (low) … 0 (normal) … 1 (high). Defaults to 0. */
|
|
14
|
+
contrastLevel?: number;
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
17
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
18
|
+
*/
|
|
19
|
+
asChild?: boolean;
|
|
20
|
+
/** Additional style applied to the wrapping `<div>` (or merged into the cloned child with `asChild`). */
|
|
21
|
+
style?: React.CSSProperties;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Web `<BloomSeedScope>`: scopes a subtree to an ARBITRARY seed colour's palette
|
|
26
|
+
* (the dynamic counterpart of `<BloomColorScope>`). It (1) writes every canonical
|
|
27
|
+
* `--x` token plus the Tailwind v4 `--color-x` aliases (already resolved to
|
|
28
|
+
* `rgb(...)`) onto the wrapping element's inline `style`, so NativeWind classes
|
|
29
|
+
* inside resolve against the seed palette instead of the document root, and
|
|
30
|
+
* (2) publishes a matching JS `theme` on `BloomThemeContext` so
|
|
31
|
+
* `useTheme()`/`useBloomTheme()` consumers inside the subtree re-theme too. The
|
|
32
|
+
* `colorPreset` field is left as the parent's (a seed is not a named preset).
|
|
33
|
+
*/
|
|
34
|
+
export declare function BloomSeedScope({ seed, variant, contrastLevel, asChild, style, children, }: BloomSeedScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
//# sourceMappingURL=index.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/seed-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAK3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yGAAyG;IACzG,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAoBD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,mBAAmB,2CA6CrB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SchemeVariant } from './color-engine';
|
|
2
|
+
import type { Theme, ThemeColors } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Build the JS `theme.colors` object from an ARBITRARY seed colour — the dynamic
|
|
5
|
+
* counterpart of `buildTheme(preset, …)`.
|
|
6
|
+
*
|
|
7
|
+
* This mirrors `buildColorsFromPreset` (`build-theme.ts`) field-for-field, but
|
|
8
|
+
* sources its tokens from `buildSeedScopeVars({ seed })` instead of a named
|
|
9
|
+
* preset, so a preset's seed reproduces that preset's JS theme exactly. Keeping
|
|
10
|
+
* the two in lockstep is enforced by `__tests__/build-theme-from-seed-parity.test.ts`.
|
|
11
|
+
*
|
|
12
|
+
* Token-backed fields read the resolved `rgb(...)` token map; the brand-tint
|
|
13
|
+
* family (primarySubtle / negative / …) reads the engine's container/error roles
|
|
14
|
+
* directly — identical to the preset path.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildColorsFromSeed(seed: string, resolved: 'light' | 'dark', variant?: SchemeVariant, contrastLevel?: number): ThemeColors;
|
|
17
|
+
/**
|
|
18
|
+
* Build a full `Theme` from a seed colour and a resolved light/dark mode. Unlike
|
|
19
|
+
* `buildTheme`, there is no adaptive (Material You / iOS dynamic) override — a
|
|
20
|
+
* seed IS the dynamic source here.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildThemeFromSeed(seed: string, resolved: 'light' | 'dark', variant?: SchemeVariant, contrastLevel?: number): Theme;
|
|
23
|
+
//# sourceMappingURL=build-theme-from-seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-theme-from-seed.d.ts","sourceRoot":"","sources":["../../../../src/theme/build-theme-from-seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIzF,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,OAAO,CAAC,EAAE,aAAa,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,WAAW,CAsDb;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,OAAO,CAAC,EAAE,aAAa,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,KAAK,CAQP"}
|
|
@@ -2,7 +2,14 @@ export { BloomThemeProvider } from './BloomThemeProvider';
|
|
|
2
2
|
export type { BloomThemeProviderProps, BloomThemeContextValue, } from './BloomThemeProvider';
|
|
3
3
|
export { BloomColorScope, useColorScopeStyle } from './color-scope';
|
|
4
4
|
export type { BloomColorScopeProps } from './color-scope';
|
|
5
|
+
export { BloomSeedScope } from './seed-scope';
|
|
6
|
+
export type { BloomSeedScopeProps } from './seed-scope';
|
|
7
|
+
export { buildSeedScopeVars, roleColorsToPresetTokens } from './color-scope/seed-scope';
|
|
8
|
+
export type { SeedScopeOptions } from './color-scope/seed-scope';
|
|
9
|
+
export { generateRoleColors, seedHexFromImagePixels, seedsFromImagePixels, quantizeImage, argbFromHex, hexFromArgb, argbFromRgb, redFromArgb, greenFromArgb, blueFromArgb, } from './color-engine';
|
|
10
|
+
export type { RoleColors, GenerateOptions, RoleName, SchemeVariant } from './color-engine';
|
|
5
11
|
export { buildTheme, STATUS_COLORS } from './build-theme';
|
|
12
|
+
export { buildThemeFromSeed, buildColorsFromSeed } from './build-theme-from-seed';
|
|
6
13
|
export { THEME_GRADIENTS } from './gradients';
|
|
7
14
|
export { useTheme, useThemeColor, useBloomTheme } from './use-theme';
|
|
8
15
|
export { useNavigationTheme } from './use-navigation-theme';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EACV,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACnF,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cA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,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACnF,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import type { SchemeVariant } from '../color-engine';
|
|
4
|
+
export interface BloomSeedScopeProps {
|
|
5
|
+
/**
|
|
6
|
+
* The seed colour (`#rrggbb`) to derive this subtree's palette from. When
|
|
7
|
+
* `undefined`, the scope is a no-op and children inherit the parent scope
|
|
8
|
+
* unchanged — pass `undefined` to fall back to the app preset (e.g. on
|
|
9
|
+
* mouse-leave/blur when restoring the default theme).
|
|
10
|
+
*/
|
|
11
|
+
seed: string | undefined;
|
|
12
|
+
/** Tonal scheme variant. Defaults to `'vibrant'` (matches Bloom presets). */
|
|
13
|
+
variant?: SchemeVariant;
|
|
14
|
+
/** −1 (low) … 0 (normal) … 1 (high). Defaults to 0. */
|
|
15
|
+
contrastLevel?: number;
|
|
16
|
+
/**
|
|
17
|
+
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
18
|
+
* with the caller's `style` merged into its `style` prop (Radix-style).
|
|
19
|
+
*/
|
|
20
|
+
asChild?: boolean;
|
|
21
|
+
/** Additional style applied to the wrapping `<View>` (or merged into the cloned child with `asChild`). */
|
|
22
|
+
style?: StyleProp<ViewStyle>;
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Native `<BloomSeedScope>`: scopes a subtree to an ARBITRARY seed colour's
|
|
27
|
+
* palette (the dynamic counterpart of `<BloomColorScope>`, which takes a named
|
|
28
|
+
* preset). Feeds the seed through the colour engine and (1) provides the
|
|
29
|
+
* resulting canonical CSS vars to descendants via react-native-css's
|
|
30
|
+
* `VariableContext` — so `bg-background` / `bg-card` / `var(--primary)` resolve
|
|
31
|
+
* against the seed inside this subtree — and (2) publishes a matching JS `theme`
|
|
32
|
+
* on `BloomThemeContext`, so `useTheme()`/`useBloomTheme()` consumers inside the
|
|
33
|
+
* subtree also re-theme. The `colorPreset` field is left as the parent's (a seed
|
|
34
|
+
* is not a named preset).
|
|
35
|
+
*/
|
|
36
|
+
export declare function BloomSeedScope({ seed, variant, contrastLevel, asChild, style, children, }: BloomSeedScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/seed-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAMpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,mBAAmB,2CA8CrB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SchemeVariant } from '../color-engine';
|
|
3
|
+
export interface BloomSeedScopeProps {
|
|
4
|
+
/**
|
|
5
|
+
* The seed colour (`#rrggbb`) to derive this subtree's palette from. When
|
|
6
|
+
* `undefined`, the scope is a no-op and children inherit the parent scope
|
|
7
|
+
* unchanged — pass `undefined` to fall back to the app preset (e.g. on
|
|
8
|
+
* mouse-leave/blur when restoring the default theme).
|
|
9
|
+
*/
|
|
10
|
+
seed: string | undefined;
|
|
11
|
+
/** Tonal scheme variant. Defaults to `'vibrant'` (matches Bloom presets). */
|
|
12
|
+
variant?: SchemeVariant;
|
|
13
|
+
/** −1 (low) … 0 (normal) … 1 (high). Defaults to 0. */
|
|
14
|
+
contrastLevel?: number;
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
17
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
18
|
+
*/
|
|
19
|
+
asChild?: boolean;
|
|
20
|
+
/** Additional style applied to the wrapping `<div>` (or merged into the cloned child with `asChild`). */
|
|
21
|
+
style?: React.CSSProperties;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Web `<BloomSeedScope>`: scopes a subtree to an ARBITRARY seed colour's palette
|
|
26
|
+
* (the dynamic counterpart of `<BloomColorScope>`). It (1) writes every canonical
|
|
27
|
+
* `--x` token plus the Tailwind v4 `--color-x` aliases (already resolved to
|
|
28
|
+
* `rgb(...)`) onto the wrapping element's inline `style`, so NativeWind classes
|
|
29
|
+
* inside resolve against the seed palette instead of the document root, and
|
|
30
|
+
* (2) publishes a matching JS `theme` on `BloomThemeContext` so
|
|
31
|
+
* `useTheme()`/`useBloomTheme()` consumers inside the subtree re-theme too. The
|
|
32
|
+
* `colorPreset` field is left as the parent's (a seed is not a named preset).
|
|
33
|
+
*/
|
|
34
|
+
export declare function BloomSeedScope({ seed, variant, contrastLevel, asChild, style, children, }: BloomSeedScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
//# sourceMappingURL=index.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/seed-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAK3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yGAAyG;IACzG,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAoBD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,OAAO,EACP,aAAa,EACb,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,mBAAmB,2CA6CrB"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parity guard for the dynamic JS-theme seed path.
|
|
3
|
+
*
|
|
4
|
+
* A named preset is just a fixed seed, so `buildThemeFromSeed(preset.hex, mode)`
|
|
5
|
+
* MUST produce the identical `theme.colors` as the preset path
|
|
6
|
+
* `buildTheme(name, mode)`. If `buildColorsFromSeed` ever drifts from
|
|
7
|
+
* `buildColorsFromPreset`, this fails.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: `buildTheme` can apply an adaptive (Material You) override on native, but
|
|
10
|
+
* this test runs under jsdom/node where `Platform.OS !== 'web'` is false and
|
|
11
|
+
* `isAdaptive` defaults to false, so the comparison is against the preset-derived
|
|
12
|
+
* palette (not adaptive), which is exactly what the seed path reproduces.
|
|
13
|
+
*/
|
|
14
|
+
import { APP_COLOR_NAMES, APP_COLOR_PRESETS, type AppColorName } from '../color-presets';
|
|
15
|
+
import { buildTheme } from '../build-theme';
|
|
16
|
+
import { buildThemeFromSeed } from '../build-theme-from-seed';
|
|
17
|
+
|
|
18
|
+
describe('buildThemeFromSeed parity with buildTheme (preset)', () => {
|
|
19
|
+
const modes: Array<'light' | 'dark'> = ['light', 'dark'];
|
|
20
|
+
|
|
21
|
+
for (const name of APP_COLOR_NAMES as readonly AppColorName[]) {
|
|
22
|
+
for (const mode of modes) {
|
|
23
|
+
it(`matches preset "${name}" colours in ${mode} mode`, () => {
|
|
24
|
+
const preset = APP_COLOR_PRESETS[name];
|
|
25
|
+
const fromPreset = buildTheme(name, mode);
|
|
26
|
+
const fromSeed = buildThemeFromSeed(preset.hex, mode, preset.variant);
|
|
27
|
+
expect(fromSeed.colors).toEqual(fromPreset.colors);
|
|
28
|
+
expect(fromSeed.mode).toBe(fromPreset.mode);
|
|
29
|
+
expect(fromSeed.isDark).toBe(fromPreset.isDark);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { generateRoleColors, type RoleColors, type SchemeVariant } from './color-engine';
|
|
2
|
+
import { buildSeedScopeVars } from './color-scope/seed-scope';
|
|
3
|
+
import { STATUS_COLORS } from './build-theme';
|
|
4
|
+
import { THEME_GRADIENTS } from './gradients';
|
|
5
|
+
import type { Theme, ThemeColors } from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build the JS `theme.colors` object from an ARBITRARY seed colour — the dynamic
|
|
9
|
+
* counterpart of `buildTheme(preset, …)`.
|
|
10
|
+
*
|
|
11
|
+
* This mirrors `buildColorsFromPreset` (`build-theme.ts`) field-for-field, but
|
|
12
|
+
* sources its tokens from `buildSeedScopeVars({ seed })` instead of a named
|
|
13
|
+
* preset, so a preset's seed reproduces that preset's JS theme exactly. Keeping
|
|
14
|
+
* the two in lockstep is enforced by `__tests__/build-theme-from-seed-parity.test.ts`.
|
|
15
|
+
*
|
|
16
|
+
* Token-backed fields read the resolved `rgb(...)` token map; the brand-tint
|
|
17
|
+
* family (primarySubtle / negative / …) reads the engine's container/error roles
|
|
18
|
+
* directly — identical to the preset path.
|
|
19
|
+
*/
|
|
20
|
+
export function buildColorsFromSeed(
|
|
21
|
+
seed: string,
|
|
22
|
+
resolved: 'light' | 'dark',
|
|
23
|
+
variant?: SchemeVariant,
|
|
24
|
+
contrastLevel?: number,
|
|
25
|
+
): ThemeColors {
|
|
26
|
+
const t = buildSeedScopeVars({ seed, mode: resolved, variant, contrastLevel });
|
|
27
|
+
const isDark = resolved === 'dark';
|
|
28
|
+
|
|
29
|
+
// Read a resolved `rgb(...)` token by its bare name (no leading `--`).
|
|
30
|
+
const g = (k: string): string => t[`--${k}`] ?? 'rgb(0 0 0)';
|
|
31
|
+
|
|
32
|
+
const r: RoleColors = generateRoleColors({
|
|
33
|
+
seed,
|
|
34
|
+
variant,
|
|
35
|
+
isDark,
|
|
36
|
+
contrastLevel,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
background: g('background'),
|
|
41
|
+
backgroundSecondary: g('surface'),
|
|
42
|
+
backgroundTertiary: g('popover'),
|
|
43
|
+
|
|
44
|
+
text: g('foreground'),
|
|
45
|
+
textSecondary: g('muted-foreground'),
|
|
46
|
+
textTertiary: r.outline,
|
|
47
|
+
|
|
48
|
+
border: g('border'),
|
|
49
|
+
borderLight: g('input'),
|
|
50
|
+
|
|
51
|
+
primary: g('primary'),
|
|
52
|
+
primaryForeground: g('primary-foreground'),
|
|
53
|
+
primaryLight: g('surface'),
|
|
54
|
+
primaryDark: g('background'),
|
|
55
|
+
|
|
56
|
+
secondary: g('secondary'),
|
|
57
|
+
secondaryForeground: g('secondary-foreground'),
|
|
58
|
+
tertiary: g('tertiary'),
|
|
59
|
+
tertiaryForeground: g('tertiary-foreground'),
|
|
60
|
+
|
|
61
|
+
tint: g('primary'),
|
|
62
|
+
icon: g('muted-foreground'),
|
|
63
|
+
iconActive: g('primary'),
|
|
64
|
+
|
|
65
|
+
...STATUS_COLORS,
|
|
66
|
+
|
|
67
|
+
primarySubtle: r.primaryContainer,
|
|
68
|
+
primarySubtleForeground: r.onPrimaryContainer,
|
|
69
|
+
negative: r.error,
|
|
70
|
+
negativeForeground: r.onError,
|
|
71
|
+
negativeSubtle: r.errorContainer,
|
|
72
|
+
negativeSubtleForeground: r.onErrorContainer,
|
|
73
|
+
contrast50: g('muted'),
|
|
74
|
+
|
|
75
|
+
card: g('card'),
|
|
76
|
+
shadow: isDark ? 'rgba(0, 0, 0, 0.3)' : 'rgba(0, 0, 0, 0.1)',
|
|
77
|
+
overlay: 'rgba(0, 0, 0, 0.5)',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Build a full `Theme` from a seed colour and a resolved light/dark mode. Unlike
|
|
83
|
+
* `buildTheme`, there is no adaptive (Material You / iOS dynamic) override — a
|
|
84
|
+
* seed IS the dynamic source here.
|
|
85
|
+
*/
|
|
86
|
+
export function buildThemeFromSeed(
|
|
87
|
+
seed: string,
|
|
88
|
+
resolved: 'light' | 'dark',
|
|
89
|
+
variant?: SchemeVariant,
|
|
90
|
+
contrastLevel?: number,
|
|
91
|
+
): Theme {
|
|
92
|
+
return {
|
|
93
|
+
mode: resolved,
|
|
94
|
+
colors: buildColorsFromSeed(seed, resolved, variant, contrastLevel),
|
|
95
|
+
gradients: THEME_GRADIENTS,
|
|
96
|
+
isDark: resolved === 'dark',
|
|
97
|
+
isLight: resolved === 'light',
|
|
98
|
+
};
|
|
99
|
+
}
|
package/src/theme/index.ts
CHANGED
|
@@ -5,7 +5,28 @@ export type {
|
|
|
5
5
|
} from './BloomThemeProvider';
|
|
6
6
|
export { BloomColorScope, useColorScopeStyle } from './color-scope';
|
|
7
7
|
export type { BloomColorScopeProps } from './color-scope';
|
|
8
|
+
export { BloomSeedScope } from './seed-scope';
|
|
9
|
+
export type { BloomSeedScopeProps } from './seed-scope';
|
|
10
|
+
export { buildSeedScopeVars, roleColorsToPresetTokens } from './color-scope/seed-scope';
|
|
11
|
+
export type { SeedScopeOptions } from './color-scope/seed-scope';
|
|
12
|
+
// Colour engine — the dependency-free tonal system that turns ANY seed colour
|
|
13
|
+
// into a full role set. Surfaced here so consumers can derive dynamic themes
|
|
14
|
+
// (e.g. from artwork) without reaching into the internal color-engine path.
|
|
15
|
+
export {
|
|
16
|
+
generateRoleColors,
|
|
17
|
+
seedHexFromImagePixels,
|
|
18
|
+
seedsFromImagePixels,
|
|
19
|
+
quantizeImage,
|
|
20
|
+
argbFromHex,
|
|
21
|
+
hexFromArgb,
|
|
22
|
+
argbFromRgb,
|
|
23
|
+
redFromArgb,
|
|
24
|
+
greenFromArgb,
|
|
25
|
+
blueFromArgb,
|
|
26
|
+
} from './color-engine';
|
|
27
|
+
export type { RoleColors, GenerateOptions, RoleName, SchemeVariant } from './color-engine';
|
|
8
28
|
export { buildTheme, STATUS_COLORS } from './build-theme';
|
|
29
|
+
export { buildThemeFromSeed, buildColorsFromSeed } from './build-theme-from-seed';
|
|
9
30
|
export { THEME_GRADIENTS } from './gradients';
|
|
10
31
|
export { useTheme, useThemeColor, useBloomTheme } from './use-theme';
|
|
11
32
|
export { useNavigationTheme } from './use-navigation-theme';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React, { Children, cloneElement, isValidElement, useContext, useMemo } from 'react';
|
|
2
|
+
import { View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemeProvider';
|
|
5
|
+
import { buildSeedScopeVars } from '../color-scope/seed-scope';
|
|
6
|
+
import { getVariableContextProvider } from '../color-scope/style-builder';
|
|
7
|
+
import { buildThemeFromSeed } from '../build-theme-from-seed';
|
|
8
|
+
import type { SchemeVariant } from '../color-engine';
|
|
9
|
+
|
|
10
|
+
export interface BloomSeedScopeProps {
|
|
11
|
+
/**
|
|
12
|
+
* The seed colour (`#rrggbb`) to derive this subtree's palette from. When
|
|
13
|
+
* `undefined`, the scope is a no-op and children inherit the parent scope
|
|
14
|
+
* unchanged — pass `undefined` to fall back to the app preset (e.g. on
|
|
15
|
+
* mouse-leave/blur when restoring the default theme).
|
|
16
|
+
*/
|
|
17
|
+
seed: string | undefined;
|
|
18
|
+
/** Tonal scheme variant. Defaults to `'vibrant'` (matches Bloom presets). */
|
|
19
|
+
variant?: SchemeVariant;
|
|
20
|
+
/** −1 (low) … 0 (normal) … 1 (high). Defaults to 0. */
|
|
21
|
+
contrastLevel?: number;
|
|
22
|
+
/**
|
|
23
|
+
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
24
|
+
* with the caller's `style` merged into its `style` prop (Radix-style).
|
|
25
|
+
*/
|
|
26
|
+
asChild?: boolean;
|
|
27
|
+
/** Additional style applied to the wrapping `<View>` (or merged into the cloned child with `asChild`). */
|
|
28
|
+
style?: StyleProp<ViewStyle>;
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface StyleableProps {
|
|
33
|
+
style?: StyleProp<ViewStyle>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Native `<BloomSeedScope>`: scopes a subtree to an ARBITRARY seed colour's
|
|
38
|
+
* palette (the dynamic counterpart of `<BloomColorScope>`, which takes a named
|
|
39
|
+
* preset). Feeds the seed through the colour engine and (1) provides the
|
|
40
|
+
* resulting canonical CSS vars to descendants via react-native-css's
|
|
41
|
+
* `VariableContext` — so `bg-background` / `bg-card` / `var(--primary)` resolve
|
|
42
|
+
* against the seed inside this subtree — and (2) publishes a matching JS `theme`
|
|
43
|
+
* on `BloomThemeContext`, so `useTheme()`/`useBloomTheme()` consumers inside the
|
|
44
|
+
* subtree also re-theme. The `colorPreset` field is left as the parent's (a seed
|
|
45
|
+
* is not a named preset).
|
|
46
|
+
*/
|
|
47
|
+
export function BloomSeedScope({
|
|
48
|
+
seed,
|
|
49
|
+
variant,
|
|
50
|
+
contrastLevel,
|
|
51
|
+
asChild = false,
|
|
52
|
+
style,
|
|
53
|
+
children,
|
|
54
|
+
}: BloomSeedScopeProps) {
|
|
55
|
+
// Hooks run unconditionally; conditional no-op/throw is applied afterwards.
|
|
56
|
+
const parent = useContext(BloomThemeContext);
|
|
57
|
+
const resolvedMode = parent?.theme.mode ?? 'light';
|
|
58
|
+
|
|
59
|
+
const nativeVars = useMemo<Record<string, string> | null>(
|
|
60
|
+
() => (seed ? buildSeedScopeVars({ seed, mode: resolvedMode, variant, contrastLevel }) : null),
|
|
61
|
+
[seed, resolvedMode, variant, contrastLevel],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const contextValue = useMemo<BloomThemeContextValue | null>(() => {
|
|
65
|
+
if (!parent || !seed) return null;
|
|
66
|
+
const theme = buildThemeFromSeed(seed, resolvedMode, variant, contrastLevel);
|
|
67
|
+
return { ...parent, theme };
|
|
68
|
+
}, [parent, seed, resolvedMode, variant, contrastLevel]);
|
|
69
|
+
|
|
70
|
+
if (!parent) {
|
|
71
|
+
throw new Error('BloomSeedScope must be used within a <BloomThemeProvider>');
|
|
72
|
+
}
|
|
73
|
+
// `seed` undefined => no-op; children inherit the parent scope.
|
|
74
|
+
if (!nativeVars || !contextValue) return <>{children}</>;
|
|
75
|
+
|
|
76
|
+
const VariableProvider = getVariableContextProvider();
|
|
77
|
+
|
|
78
|
+
let content: React.ReactNode;
|
|
79
|
+
if (asChild) {
|
|
80
|
+
const child = Children.only(children);
|
|
81
|
+
if (!isValidElement<StyleableProps>(child)) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
'BloomSeedScope with `asChild` requires a single React element child that accepts a `style` prop.',
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const childStyle = child.props.style;
|
|
87
|
+
const mergedStyle: StyleProp<ViewStyle> = [style, childStyle];
|
|
88
|
+
content = cloneElement(child, { style: mergedStyle });
|
|
89
|
+
} else {
|
|
90
|
+
content = <View style={[{ flex: 1 }, style]}>{children}</View>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const scoped = VariableProvider ? (
|
|
94
|
+
<VariableProvider value={nativeVars}>{content}</VariableProvider>
|
|
95
|
+
) : (
|
|
96
|
+
content
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return <BloomThemeContext.Provider value={contextValue}>{scoped}</BloomThemeContext.Provider>;
|
|
100
|
+
}
|