@meetreeve/ui 0.22.0 → 0.23.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/README.md +41 -0
- package/dist/index.d.mts +1 -12
- package/dist/index.d.ts +1 -12
- package/dist/index.js +3 -1
- package/dist/index.mjs +3 -1
- package/dist/theme/index.d.mts +190 -0
- package/dist/theme/index.d.ts +190 -0
- package/dist/theme/index.js +351 -0
- package/dist/theme/index.mjs +309 -0
- package/dist/tokens.css +19 -17
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -350,6 +350,47 @@ chart in a tenant's brand colours, set those variables. Hosts that don't import
|
|
|
350
350
|
|
|
351
351
|
Third-party code is credited in `THIRD_PARTY_NOTICES.md`.
|
|
352
352
|
|
|
353
|
+
## Theme — `@meetreeve/ui/theme` (DEV-17886)
|
|
354
|
+
|
|
355
|
+
One brand's inputs in, light and dark semantic tokens out. Reeve's own look is
|
|
356
|
+
`brandTheme(reevePreset)`; a store or tenant site passes its own accent.
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
import { brandTheme, reevePreset } from "@meetreeve/ui/theme";
|
|
360
|
+
|
|
361
|
+
const { light, dark } = brandTheme({ accent: brand.accentColor, neutralTemperature: "cool" });
|
|
362
|
+
// light["--action"], light["--action-foreground"], light["--link"], dark["--chart-1"], …
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
- **Inputs:** `accent` (null or invalid → Reeve's dot `#FF6B2B`), `ink` (the
|
|
366
|
+
neutral primary button), `neutralTemperature` (`"cool"` navy/slate, the
|
|
367
|
+
Reeve default; `"neutral"` zinc; `"warm"` stone), `radius`, `fonts`
|
|
368
|
+
(`sans` / `display` / `mono`). `radius` and fonts are emitted only when they
|
|
369
|
+
are a plain CSS length or a font-family list.
|
|
370
|
+
- **Outputs (per mode):** the shadcn set (`--background`, `--foreground`,
|
|
371
|
+
`--card`, `--popover`, `--primary`, `--secondary`, `--muted`, `--accent`,
|
|
372
|
+
each with `-foreground`; `--border`, `--input`, `--ring`), plus `--link`,
|
|
373
|
+
`--action` (+fg, the one dominant action), `--brand-accent` (the dot),
|
|
374
|
+
`--destructive` / `--success` / `--warning` (+fg, and a `-subtle` surface
|
|
375
|
+
with its own `-foreground`), `--shadow-sm/md/lg` and `--chart-1..8`.
|
|
376
|
+
`--accent` stays shadcn's quiet hover surface; the brand colour is
|
|
377
|
+
`--brand-accent`.
|
|
378
|
+
- **Contrast is derived, not hoped for.** Every foreground is picked by WCAG
|
|
379
|
+
2.x contrast; when nothing passes, lightness is stepped in OKLCH (hue kept)
|
|
380
|
+
until text reaches 4.5 and rings and indicators reach 3 on the background,
|
|
381
|
+
card and muted surfaces. Fills are judged differently: the action keeps the
|
|
382
|
+
accent unless it is perceptually lost against the page (OKLab ΔE under
|
|
383
|
+
0.1, e.g. a white brand on white), and a pale `ink` is held to 3:1. Status
|
|
384
|
+
hues are fixed per mode and never follow the accent. Sidebar tokens are not
|
|
385
|
+
emitted: the sidebar is Reeve chrome.
|
|
386
|
+
- **The contrast helper** is exported too: `contrastRatio`,
|
|
387
|
+
`relativeLuminance`, `readableOn(color, backgrounds, min)`,
|
|
388
|
+
`pickForeground`, `solidPair`, `deltaE`, `CONTRAST` (`{ text: 4.5, indicator: 3 }`).
|
|
389
|
+
Use it instead of writing another copy.
|
|
390
|
+
|
|
391
|
+
Pure functions with no React or DOM, so the entry is server-safe. The chart
|
|
392
|
+
defaults in `tokens.css` are `brandTheme(reevePreset)`'s `--chart-*`.
|
|
393
|
+
|
|
353
394
|
## Tokens
|
|
354
395
|
|
|
355
396
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -2,19 +2,8 @@ import * as react from 'react';
|
|
|
2
2
|
import { ReactNode, ElementType, RefObject, CSSProperties, MouseEventHandler } from 'react';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Brand glyph with a favicon-first cascade (ported/generalised from
|
|
7
|
-
* DEV-4164's `context/brand-glyph`).
|
|
8
|
-
*
|
|
9
|
-
* A tiny square favicon reads far better than a wide wordmark, so we try, in
|
|
10
|
-
* order:
|
|
11
|
-
* 1. `brand.favicon` — the site's own square icon,
|
|
12
|
-
* 2. `brand.logo` rendered `object-contain` (no squish),
|
|
13
|
-
* 3. a single-letter monogram in the brand colour + an accent dot
|
|
14
|
-
* (DEV-4539 — modeled on Reeve's own "R." canon; no boxed container).
|
|
15
|
-
* Each image load error advances to the next candidate.
|
|
16
|
-
*/
|
|
17
5
|
declare const REEVE_ACCENT = "#FF6B2B";
|
|
6
|
+
|
|
18
7
|
interface Brand {
|
|
19
8
|
/** Display name — drives the wordmark and the monogram fallback. */
|
|
20
9
|
name: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,19 +2,8 @@ import * as react from 'react';
|
|
|
2
2
|
import { ReactNode, ElementType, RefObject, CSSProperties, MouseEventHandler } from 'react';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Brand glyph with a favicon-first cascade (ported/generalised from
|
|
7
|
-
* DEV-4164's `context/brand-glyph`).
|
|
8
|
-
*
|
|
9
|
-
* A tiny square favicon reads far better than a wide wordmark, so we try, in
|
|
10
|
-
* order:
|
|
11
|
-
* 1. `brand.favicon` — the site's own square icon,
|
|
12
|
-
* 2. `brand.logo` rendered `object-contain` (no squish),
|
|
13
|
-
* 3. a single-letter monogram in the brand colour + an accent dot
|
|
14
|
-
* (DEV-4539 — modeled on Reeve's own "R." canon; no boxed container).
|
|
15
|
-
* Each image load error advances to the next candidate.
|
|
16
|
-
*/
|
|
17
5
|
declare const REEVE_ACCENT = "#FF6B2B";
|
|
6
|
+
|
|
18
7
|
interface Brand {
|
|
19
8
|
/** Display name — drives the wordmark and the monogram fallback. */
|
|
20
9
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -132,9 +132,11 @@ function monogramColor(seed) {
|
|
|
132
132
|
return MONOGRAM_COLORS[Math.abs(h) % MONOGRAM_COLORS.length];
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
// src/lib/reeve-accent.ts
|
|
136
|
+
var REEVE_ACCENT = "#FF6B2B";
|
|
137
|
+
|
|
135
138
|
// src/brand-glyph.tsx
|
|
136
139
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
137
|
-
var REEVE_ACCENT = "#FF6B2B";
|
|
138
140
|
function faviconUrl(domain) {
|
|
139
141
|
if (!domain) return null;
|
|
140
142
|
const host = domain.trim().toLowerCase();
|
package/dist/index.mjs
CHANGED
|
@@ -66,9 +66,11 @@ function monogramColor(seed) {
|
|
|
66
66
|
return MONOGRAM_COLORS[Math.abs(h) % MONOGRAM_COLORS.length];
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// src/lib/reeve-accent.ts
|
|
70
|
+
var REEVE_ACCENT = "#FF6B2B";
|
|
71
|
+
|
|
69
72
|
// src/brand-glyph.tsx
|
|
70
73
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
71
|
-
var REEVE_ACCENT = "#FF6B2B";
|
|
72
74
|
function faviconUrl(domain) {
|
|
73
75
|
if (!domain) return null;
|
|
74
76
|
const host = domain.trim().toLowerCase();
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* brandTheme (DEV-17886): one brand's inputs → light and dark semantic tokens.
|
|
3
|
+
*
|
|
4
|
+
* The DEV-17839 visual system, built once. Reeve's own look is
|
|
5
|
+
* `brandTheme(reevePreset)`; a store or tenant site passes its brand's accent.
|
|
6
|
+
* Every foreground and every text/ring shade is derived by contrast (./contrast),
|
|
7
|
+
* so any accent gets AA pairings: 4.5 for text, 3 for indicators.
|
|
8
|
+
*
|
|
9
|
+
* What comes from where:
|
|
10
|
+
* - neutral surfaces, text and chart steps: a fixed ramp per
|
|
11
|
+
* `neutralTemperature` ("cool" is Reeve's navy/slate);
|
|
12
|
+
* - `ink`: the neutral primary button (light) and the border tint;
|
|
13
|
+
* - `accent`: the brand mark (`--brand-accent`), the dominant action
|
|
14
|
+
* (`--action`), and the link / ring / chart-1 shade derived from it;
|
|
15
|
+
* - status (destructive, success, warning): fixed semantic hues per mode,
|
|
16
|
+
* never the accent ("status only, never decoration").
|
|
17
|
+
* Sidebar tokens are deliberately absent: the sidebar is Reeve chrome and never
|
|
18
|
+
* takes a brand's theme (reeve-frontend globals.css).
|
|
19
|
+
*
|
|
20
|
+
* Pure and deterministic, no DOM: safe in server components and build scripts.
|
|
21
|
+
*/
|
|
22
|
+
type NeutralTemperature = "cool" | "neutral" | "warm";
|
|
23
|
+
interface BrandThemeInput {
|
|
24
|
+
/** The brand colour. null / missing / not a hex → Reeve's dot. */
|
|
25
|
+
accent?: string | null;
|
|
26
|
+
/** Neutral primary button colour in light mode. Defaults to the ramp's ink. */
|
|
27
|
+
ink?: string | null;
|
|
28
|
+
/** Which neutral ramp the surfaces use. Default "cool". */
|
|
29
|
+
neutralTemperature?: NeutralTemperature;
|
|
30
|
+
/** `--radius`, a CSS length. Omitted unless valid. */
|
|
31
|
+
radius?: string | null;
|
|
32
|
+
/** `--font-sans` / `--font-display` / `--font-mono`. Omitted unless valid. */
|
|
33
|
+
fonts?: {
|
|
34
|
+
sans?: string | null;
|
|
35
|
+
display?: string | null;
|
|
36
|
+
mono?: string | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Hand-tuned shades that replace a derived one, used only when they clear the
|
|
40
|
+
* same contrast bar the derivation enforces (otherwise ignored).
|
|
41
|
+
*/
|
|
42
|
+
tuned?: {
|
|
43
|
+
/** Link / ring / chart-1 text shade per mode (≥ 4.5 on every surface). */
|
|
44
|
+
link?: {
|
|
45
|
+
light?: string;
|
|
46
|
+
dark?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Chart series 7, a light tint of the accent (decorative). */
|
|
49
|
+
chartTint?: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** The semantic tokens brandTheme emits for one mode. */
|
|
53
|
+
interface ThemeTokens {
|
|
54
|
+
"--background": string;
|
|
55
|
+
"--foreground": string;
|
|
56
|
+
"--card": string;
|
|
57
|
+
"--card-foreground": string;
|
|
58
|
+
"--popover": string;
|
|
59
|
+
"--popover-foreground": string;
|
|
60
|
+
"--primary": string;
|
|
61
|
+
"--primary-foreground": string;
|
|
62
|
+
"--secondary": string;
|
|
63
|
+
"--secondary-foreground": string;
|
|
64
|
+
"--muted": string;
|
|
65
|
+
"--muted-foreground": string;
|
|
66
|
+
/** shadcn's quiet hover surface, NOT the brand colour (that is --brand-accent). */
|
|
67
|
+
"--accent": string;
|
|
68
|
+
"--accent-foreground": string;
|
|
69
|
+
"--destructive": string;
|
|
70
|
+
"--destructive-foreground": string;
|
|
71
|
+
"--destructive-subtle": string;
|
|
72
|
+
"--destructive-subtle-foreground": string;
|
|
73
|
+
"--success": string;
|
|
74
|
+
"--success-foreground": string;
|
|
75
|
+
"--success-subtle": string;
|
|
76
|
+
"--success-subtle-foreground": string;
|
|
77
|
+
"--warning": string;
|
|
78
|
+
"--warning-foreground": string;
|
|
79
|
+
"--warning-subtle": string;
|
|
80
|
+
"--warning-subtle-foreground": string;
|
|
81
|
+
"--border": string;
|
|
82
|
+
"--input": string;
|
|
83
|
+
"--ring": string;
|
|
84
|
+
"--link": string;
|
|
85
|
+
/** The one dominant action per task region. */
|
|
86
|
+
"--action": string;
|
|
87
|
+
"--action-foreground": string;
|
|
88
|
+
/** The brand mark itself (the dot). Never text on a light surface. */
|
|
89
|
+
"--brand-accent": string;
|
|
90
|
+
"--shadow-sm": string;
|
|
91
|
+
"--shadow-md": string;
|
|
92
|
+
"--shadow-lg": string;
|
|
93
|
+
"--chart-1": string;
|
|
94
|
+
"--chart-2": string;
|
|
95
|
+
"--chart-3": string;
|
|
96
|
+
"--chart-4": string;
|
|
97
|
+
"--chart-5": string;
|
|
98
|
+
"--chart-6": string;
|
|
99
|
+
"--chart-7": string;
|
|
100
|
+
"--chart-8": string;
|
|
101
|
+
"--radius"?: string;
|
|
102
|
+
"--font-sans"?: string;
|
|
103
|
+
"--font-display"?: string;
|
|
104
|
+
"--font-mono"?: string;
|
|
105
|
+
}
|
|
106
|
+
interface BrandTheme {
|
|
107
|
+
light: ThemeTokens;
|
|
108
|
+
dark: ThemeTokens;
|
|
109
|
+
}
|
|
110
|
+
/** Reeve's inputs: the dot and navy ink, plus the two shades Matt approved by eye. */
|
|
111
|
+
declare const reevePreset: {
|
|
112
|
+
readonly accent: "#FF6B2B";
|
|
113
|
+
readonly ink: "#1D3557";
|
|
114
|
+
readonly tuned: {
|
|
115
|
+
readonly link: {
|
|
116
|
+
readonly light: "#C2410C";
|
|
117
|
+
readonly dark: "#FF8A57";
|
|
118
|
+
};
|
|
119
|
+
readonly chartTint: "#FF9B5C";
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* A brand's light and dark semantic tokens. No input (or null) → Reeve's base.
|
|
124
|
+
* Never throws: every brand value is validated, and anything invalid falls back.
|
|
125
|
+
*/
|
|
126
|
+
declare function brandTheme(theme?: BrandThemeInput | null): BrandTheme;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The one contrast helper (DEV-17886). WCAG 2.x relative luminance and
|
|
130
|
+
* contrast ratio, plus deterministic fixes that step OKLCH lightness until a
|
|
131
|
+
* pairing passes. Pure: no DOM, no randomness, same input → same hex.
|
|
132
|
+
*
|
|
133
|
+
* Meant to replace two copies that grew independently: reeve-frontend's
|
|
134
|
+
* src/lib/brand-contrast.ts (HSL steps, used by build-store's 4.5 / 3.5 picks;
|
|
135
|
+
* moves here in DEV-17912) and reeve-tenant-frontend's brand-theme.ts
|
|
136
|
+
* (DEV-17890). Unlike the old readableOn, this one throws on a non-hex colour
|
|
137
|
+
* and defaults to 4.5, not 4.0. OKLCH keeps hue and perceived chroma while
|
|
138
|
+
* lightness moves, so a darkened orange stays an orange.
|
|
139
|
+
*/
|
|
140
|
+
type Rgb = [number, number, number];
|
|
141
|
+
/** WCAG 2.x thresholds: normal text, and large text / UI indicators. */
|
|
142
|
+
declare const CONTRAST: {
|
|
143
|
+
readonly text: 4.5;
|
|
144
|
+
readonly indicator: 3;
|
|
145
|
+
};
|
|
146
|
+
/** `#rgb` / `#rrggbb` (hash optional) → 0-255 channels, or null. */
|
|
147
|
+
declare function parseHex(hex: string | null | undefined): Rgb | null;
|
|
148
|
+
/** 0-255 channels → lowercase `#rrggbb`, clamped and rounded. */
|
|
149
|
+
declare function toHex([r, g, b]: Rgb): string;
|
|
150
|
+
/** Valid colour → lowercase `#rrggbb`; anything else → null. */
|
|
151
|
+
declare function normalizeHex(hex: string | null | undefined): string | null;
|
|
152
|
+
/** WCAG 2.x relative luminance, 0 (black) to 1 (white). Unparseable → 0. */
|
|
153
|
+
declare function relativeLuminance(hex: string): number;
|
|
154
|
+
/** WCAG 2.x contrast ratio, 1 to 21. An unparseable colour scores 1. */
|
|
155
|
+
declare function contrastRatio(a: string, b: string): number;
|
|
156
|
+
/**
|
|
157
|
+
* Perceptual distance (ΔE in OKLab, 0 = identical, ~1 = black vs white). WCAG
|
|
158
|
+
* contrast is luminance-only, so it calls a saturated yellow on white (1.3:1)
|
|
159
|
+
* as close as a near-white grey; this tells them apart. Unparseable → 0.
|
|
160
|
+
*/
|
|
161
|
+
declare function deltaE(a: string, b: string): number;
|
|
162
|
+
/**
|
|
163
|
+
* The colour nearest `color` (same OKLCH hue and chroma, lightness moved in
|
|
164
|
+
* 0.005 steps) that reaches `min` against every background. Unchanged
|
|
165
|
+
* (normalised) when it already passes; the smaller move wins, darker on a tie.
|
|
166
|
+
* If no lightness works (backgrounds on both ends), returns whichever of black
|
|
167
|
+
* or white scores the higher worst-case contrast.
|
|
168
|
+
*/
|
|
169
|
+
declare function readableOn(color: string, backgrounds: string | readonly string[], min?: number): string;
|
|
170
|
+
/** The candidate with the most contrast on `background` (first wins a tie). */
|
|
171
|
+
declare function pickForeground(background: string, candidates: readonly string[]): string;
|
|
172
|
+
/**
|
|
173
|
+
* A filled surface (button, badge) and its text. Keeps `fill` when one of the
|
|
174
|
+
* candidate foregrounds reaches `min` on it; otherwise moves the FILL's
|
|
175
|
+
* lightness (text colours stay the theme's own) until one does.
|
|
176
|
+
*/
|
|
177
|
+
declare function solidPair(fill: string, candidates: readonly string[], min?: number): {
|
|
178
|
+
background: string;
|
|
179
|
+
foreground: string;
|
|
180
|
+
};
|
|
181
|
+
/** `weight` of `a` over `b`, in gamma sRGB (what `color-mix(in srgb, …)` does). */
|
|
182
|
+
declare function mix(a: string, b: string, weight: number): string;
|
|
183
|
+
/** `rgba(r, g, b, alpha)` for a hex colour (borders, shadows). */
|
|
184
|
+
declare function rgba(hex: string, alpha: number): string;
|
|
185
|
+
/** Lighten (positive) or darken (negative) in OKLCH lightness, hue kept. */
|
|
186
|
+
declare function shiftLightness(hex: string, delta: number): string;
|
|
187
|
+
|
|
188
|
+
declare const REEVE_ACCENT = "#FF6B2B";
|
|
189
|
+
|
|
190
|
+
export { type BrandTheme, type BrandThemeInput, CONTRAST, type NeutralTemperature, REEVE_ACCENT, type Rgb, type ThemeTokens, brandTheme, contrastRatio, deltaE, mix, normalizeHex, parseHex, pickForeground, readableOn, reevePreset, relativeLuminance, rgba, shiftLightness, solidPair, toHex };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* brandTheme (DEV-17886): one brand's inputs → light and dark semantic tokens.
|
|
3
|
+
*
|
|
4
|
+
* The DEV-17839 visual system, built once. Reeve's own look is
|
|
5
|
+
* `brandTheme(reevePreset)`; a store or tenant site passes its brand's accent.
|
|
6
|
+
* Every foreground and every text/ring shade is derived by contrast (./contrast),
|
|
7
|
+
* so any accent gets AA pairings: 4.5 for text, 3 for indicators.
|
|
8
|
+
*
|
|
9
|
+
* What comes from where:
|
|
10
|
+
* - neutral surfaces, text and chart steps: a fixed ramp per
|
|
11
|
+
* `neutralTemperature` ("cool" is Reeve's navy/slate);
|
|
12
|
+
* - `ink`: the neutral primary button (light) and the border tint;
|
|
13
|
+
* - `accent`: the brand mark (`--brand-accent`), the dominant action
|
|
14
|
+
* (`--action`), and the link / ring / chart-1 shade derived from it;
|
|
15
|
+
* - status (destructive, success, warning): fixed semantic hues per mode,
|
|
16
|
+
* never the accent ("status only, never decoration").
|
|
17
|
+
* Sidebar tokens are deliberately absent: the sidebar is Reeve chrome and never
|
|
18
|
+
* takes a brand's theme (reeve-frontend globals.css).
|
|
19
|
+
*
|
|
20
|
+
* Pure and deterministic, no DOM: safe in server components and build scripts.
|
|
21
|
+
*/
|
|
22
|
+
type NeutralTemperature = "cool" | "neutral" | "warm";
|
|
23
|
+
interface BrandThemeInput {
|
|
24
|
+
/** The brand colour. null / missing / not a hex → Reeve's dot. */
|
|
25
|
+
accent?: string | null;
|
|
26
|
+
/** Neutral primary button colour in light mode. Defaults to the ramp's ink. */
|
|
27
|
+
ink?: string | null;
|
|
28
|
+
/** Which neutral ramp the surfaces use. Default "cool". */
|
|
29
|
+
neutralTemperature?: NeutralTemperature;
|
|
30
|
+
/** `--radius`, a CSS length. Omitted unless valid. */
|
|
31
|
+
radius?: string | null;
|
|
32
|
+
/** `--font-sans` / `--font-display` / `--font-mono`. Omitted unless valid. */
|
|
33
|
+
fonts?: {
|
|
34
|
+
sans?: string | null;
|
|
35
|
+
display?: string | null;
|
|
36
|
+
mono?: string | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Hand-tuned shades that replace a derived one, used only when they clear the
|
|
40
|
+
* same contrast bar the derivation enforces (otherwise ignored).
|
|
41
|
+
*/
|
|
42
|
+
tuned?: {
|
|
43
|
+
/** Link / ring / chart-1 text shade per mode (≥ 4.5 on every surface). */
|
|
44
|
+
link?: {
|
|
45
|
+
light?: string;
|
|
46
|
+
dark?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Chart series 7, a light tint of the accent (decorative). */
|
|
49
|
+
chartTint?: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** The semantic tokens brandTheme emits for one mode. */
|
|
53
|
+
interface ThemeTokens {
|
|
54
|
+
"--background": string;
|
|
55
|
+
"--foreground": string;
|
|
56
|
+
"--card": string;
|
|
57
|
+
"--card-foreground": string;
|
|
58
|
+
"--popover": string;
|
|
59
|
+
"--popover-foreground": string;
|
|
60
|
+
"--primary": string;
|
|
61
|
+
"--primary-foreground": string;
|
|
62
|
+
"--secondary": string;
|
|
63
|
+
"--secondary-foreground": string;
|
|
64
|
+
"--muted": string;
|
|
65
|
+
"--muted-foreground": string;
|
|
66
|
+
/** shadcn's quiet hover surface, NOT the brand colour (that is --brand-accent). */
|
|
67
|
+
"--accent": string;
|
|
68
|
+
"--accent-foreground": string;
|
|
69
|
+
"--destructive": string;
|
|
70
|
+
"--destructive-foreground": string;
|
|
71
|
+
"--destructive-subtle": string;
|
|
72
|
+
"--destructive-subtle-foreground": string;
|
|
73
|
+
"--success": string;
|
|
74
|
+
"--success-foreground": string;
|
|
75
|
+
"--success-subtle": string;
|
|
76
|
+
"--success-subtle-foreground": string;
|
|
77
|
+
"--warning": string;
|
|
78
|
+
"--warning-foreground": string;
|
|
79
|
+
"--warning-subtle": string;
|
|
80
|
+
"--warning-subtle-foreground": string;
|
|
81
|
+
"--border": string;
|
|
82
|
+
"--input": string;
|
|
83
|
+
"--ring": string;
|
|
84
|
+
"--link": string;
|
|
85
|
+
/** The one dominant action per task region. */
|
|
86
|
+
"--action": string;
|
|
87
|
+
"--action-foreground": string;
|
|
88
|
+
/** The brand mark itself (the dot). Never text on a light surface. */
|
|
89
|
+
"--brand-accent": string;
|
|
90
|
+
"--shadow-sm": string;
|
|
91
|
+
"--shadow-md": string;
|
|
92
|
+
"--shadow-lg": string;
|
|
93
|
+
"--chart-1": string;
|
|
94
|
+
"--chart-2": string;
|
|
95
|
+
"--chart-3": string;
|
|
96
|
+
"--chart-4": string;
|
|
97
|
+
"--chart-5": string;
|
|
98
|
+
"--chart-6": string;
|
|
99
|
+
"--chart-7": string;
|
|
100
|
+
"--chart-8": string;
|
|
101
|
+
"--radius"?: string;
|
|
102
|
+
"--font-sans"?: string;
|
|
103
|
+
"--font-display"?: string;
|
|
104
|
+
"--font-mono"?: string;
|
|
105
|
+
}
|
|
106
|
+
interface BrandTheme {
|
|
107
|
+
light: ThemeTokens;
|
|
108
|
+
dark: ThemeTokens;
|
|
109
|
+
}
|
|
110
|
+
/** Reeve's inputs: the dot and navy ink, plus the two shades Matt approved by eye. */
|
|
111
|
+
declare const reevePreset: {
|
|
112
|
+
readonly accent: "#FF6B2B";
|
|
113
|
+
readonly ink: "#1D3557";
|
|
114
|
+
readonly tuned: {
|
|
115
|
+
readonly link: {
|
|
116
|
+
readonly light: "#C2410C";
|
|
117
|
+
readonly dark: "#FF8A57";
|
|
118
|
+
};
|
|
119
|
+
readonly chartTint: "#FF9B5C";
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* A brand's light and dark semantic tokens. No input (or null) → Reeve's base.
|
|
124
|
+
* Never throws: every brand value is validated, and anything invalid falls back.
|
|
125
|
+
*/
|
|
126
|
+
declare function brandTheme(theme?: BrandThemeInput | null): BrandTheme;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The one contrast helper (DEV-17886). WCAG 2.x relative luminance and
|
|
130
|
+
* contrast ratio, plus deterministic fixes that step OKLCH lightness until a
|
|
131
|
+
* pairing passes. Pure: no DOM, no randomness, same input → same hex.
|
|
132
|
+
*
|
|
133
|
+
* Meant to replace two copies that grew independently: reeve-frontend's
|
|
134
|
+
* src/lib/brand-contrast.ts (HSL steps, used by build-store's 4.5 / 3.5 picks;
|
|
135
|
+
* moves here in DEV-17912) and reeve-tenant-frontend's brand-theme.ts
|
|
136
|
+
* (DEV-17890). Unlike the old readableOn, this one throws on a non-hex colour
|
|
137
|
+
* and defaults to 4.5, not 4.0. OKLCH keeps hue and perceived chroma while
|
|
138
|
+
* lightness moves, so a darkened orange stays an orange.
|
|
139
|
+
*/
|
|
140
|
+
type Rgb = [number, number, number];
|
|
141
|
+
/** WCAG 2.x thresholds: normal text, and large text / UI indicators. */
|
|
142
|
+
declare const CONTRAST: {
|
|
143
|
+
readonly text: 4.5;
|
|
144
|
+
readonly indicator: 3;
|
|
145
|
+
};
|
|
146
|
+
/** `#rgb` / `#rrggbb` (hash optional) → 0-255 channels, or null. */
|
|
147
|
+
declare function parseHex(hex: string | null | undefined): Rgb | null;
|
|
148
|
+
/** 0-255 channels → lowercase `#rrggbb`, clamped and rounded. */
|
|
149
|
+
declare function toHex([r, g, b]: Rgb): string;
|
|
150
|
+
/** Valid colour → lowercase `#rrggbb`; anything else → null. */
|
|
151
|
+
declare function normalizeHex(hex: string | null | undefined): string | null;
|
|
152
|
+
/** WCAG 2.x relative luminance, 0 (black) to 1 (white). Unparseable → 0. */
|
|
153
|
+
declare function relativeLuminance(hex: string): number;
|
|
154
|
+
/** WCAG 2.x contrast ratio, 1 to 21. An unparseable colour scores 1. */
|
|
155
|
+
declare function contrastRatio(a: string, b: string): number;
|
|
156
|
+
/**
|
|
157
|
+
* Perceptual distance (ΔE in OKLab, 0 = identical, ~1 = black vs white). WCAG
|
|
158
|
+
* contrast is luminance-only, so it calls a saturated yellow on white (1.3:1)
|
|
159
|
+
* as close as a near-white grey; this tells them apart. Unparseable → 0.
|
|
160
|
+
*/
|
|
161
|
+
declare function deltaE(a: string, b: string): number;
|
|
162
|
+
/**
|
|
163
|
+
* The colour nearest `color` (same OKLCH hue and chroma, lightness moved in
|
|
164
|
+
* 0.005 steps) that reaches `min` against every background. Unchanged
|
|
165
|
+
* (normalised) when it already passes; the smaller move wins, darker on a tie.
|
|
166
|
+
* If no lightness works (backgrounds on both ends), returns whichever of black
|
|
167
|
+
* or white scores the higher worst-case contrast.
|
|
168
|
+
*/
|
|
169
|
+
declare function readableOn(color: string, backgrounds: string | readonly string[], min?: number): string;
|
|
170
|
+
/** The candidate with the most contrast on `background` (first wins a tie). */
|
|
171
|
+
declare function pickForeground(background: string, candidates: readonly string[]): string;
|
|
172
|
+
/**
|
|
173
|
+
* A filled surface (button, badge) and its text. Keeps `fill` when one of the
|
|
174
|
+
* candidate foregrounds reaches `min` on it; otherwise moves the FILL's
|
|
175
|
+
* lightness (text colours stay the theme's own) until one does.
|
|
176
|
+
*/
|
|
177
|
+
declare function solidPair(fill: string, candidates: readonly string[], min?: number): {
|
|
178
|
+
background: string;
|
|
179
|
+
foreground: string;
|
|
180
|
+
};
|
|
181
|
+
/** `weight` of `a` over `b`, in gamma sRGB (what `color-mix(in srgb, …)` does). */
|
|
182
|
+
declare function mix(a: string, b: string, weight: number): string;
|
|
183
|
+
/** `rgba(r, g, b, alpha)` for a hex colour (borders, shadows). */
|
|
184
|
+
declare function rgba(hex: string, alpha: number): string;
|
|
185
|
+
/** Lighten (positive) or darken (negative) in OKLCH lightness, hue kept. */
|
|
186
|
+
declare function shiftLightness(hex: string, delta: number): string;
|
|
187
|
+
|
|
188
|
+
declare const REEVE_ACCENT = "#FF6B2B";
|
|
189
|
+
|
|
190
|
+
export { type BrandTheme, type BrandThemeInput, CONTRAST, type NeutralTemperature, REEVE_ACCENT, type Rgb, type ThemeTokens, brandTheme, contrastRatio, deltaE, mix, normalizeHex, parseHex, pickForeground, readableOn, reevePreset, relativeLuminance, rgba, shiftLightness, solidPair, toHex };
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/theme/index.ts
|
|
21
|
+
var theme_exports = {};
|
|
22
|
+
__export(theme_exports, {
|
|
23
|
+
CONTRAST: () => CONTRAST,
|
|
24
|
+
REEVE_ACCENT: () => REEVE_ACCENT,
|
|
25
|
+
brandTheme: () => brandTheme,
|
|
26
|
+
contrastRatio: () => contrastRatio,
|
|
27
|
+
deltaE: () => deltaE,
|
|
28
|
+
mix: () => mix,
|
|
29
|
+
normalizeHex: () => normalizeHex,
|
|
30
|
+
parseHex: () => parseHex,
|
|
31
|
+
pickForeground: () => pickForeground,
|
|
32
|
+
readableOn: () => readableOn,
|
|
33
|
+
reevePreset: () => reevePreset,
|
|
34
|
+
relativeLuminance: () => relativeLuminance,
|
|
35
|
+
rgba: () => rgba,
|
|
36
|
+
shiftLightness: () => shiftLightness,
|
|
37
|
+
solidPair: () => solidPair,
|
|
38
|
+
toHex: () => toHex
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(theme_exports);
|
|
41
|
+
|
|
42
|
+
// src/lib/reeve-accent.ts
|
|
43
|
+
var REEVE_ACCENT = "#FF6B2B";
|
|
44
|
+
|
|
45
|
+
// src/theme/contrast.ts
|
|
46
|
+
var CONTRAST = { text: 4.5, indicator: 3 };
|
|
47
|
+
var HEX_RE = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
48
|
+
function parseHex(hex) {
|
|
49
|
+
if (typeof hex !== "string") return null;
|
|
50
|
+
const m = hex.trim().match(HEX_RE);
|
|
51
|
+
if (!m) return null;
|
|
52
|
+
const h = m[1].length === 3 ? m[1].replace(/./g, "$&$&") : m[1];
|
|
53
|
+
const n = parseInt(h, 16);
|
|
54
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
55
|
+
}
|
|
56
|
+
function toHex([r, g, b]) {
|
|
57
|
+
const c = (v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0");
|
|
58
|
+
return `#${c(r)}${c(g)}${c(b)}`;
|
|
59
|
+
}
|
|
60
|
+
function normalizeHex(hex) {
|
|
61
|
+
const rgb = parseHex(hex);
|
|
62
|
+
return rgb ? toHex(rgb) : null;
|
|
63
|
+
}
|
|
64
|
+
var toLinear = (c) => {
|
|
65
|
+
const s = c / 255;
|
|
66
|
+
return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
67
|
+
};
|
|
68
|
+
var fromLinear = (v) => {
|
|
69
|
+
const c = Math.max(0, Math.min(1, v));
|
|
70
|
+
return 255 * (c <= 31308e-7 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
71
|
+
};
|
|
72
|
+
function relativeLuminance(hex) {
|
|
73
|
+
const rgb = parseHex(hex);
|
|
74
|
+
if (!rgb) return 0;
|
|
75
|
+
const [r, g, b] = rgb.map(toLinear);
|
|
76
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
77
|
+
}
|
|
78
|
+
function contrastRatio(a, b) {
|
|
79
|
+
if (!parseHex(a) || !parseHex(b)) return 1;
|
|
80
|
+
const la = relativeLuminance(a);
|
|
81
|
+
const lb = relativeLuminance(b);
|
|
82
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
83
|
+
}
|
|
84
|
+
function minContrast(color, backgrounds) {
|
|
85
|
+
return Math.min(...backgrounds.map((bg) => contrastRatio(color, bg)));
|
|
86
|
+
}
|
|
87
|
+
function rgbToOklch(rgb) {
|
|
88
|
+
const [r, g, b] = rgb.map(toLinear);
|
|
89
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
90
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
91
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
92
|
+
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
93
|
+
const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
94
|
+
const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
95
|
+
return [L, Math.hypot(A, B), Math.atan2(B, A)];
|
|
96
|
+
}
|
|
97
|
+
function deltaE(a, b) {
|
|
98
|
+
const x = parseHex(a);
|
|
99
|
+
const y = parseHex(b);
|
|
100
|
+
if (!x || !y) return 0;
|
|
101
|
+
const toLab = ([L, C, h]) => [L, C * Math.cos(h), C * Math.sin(h)];
|
|
102
|
+
const [l1, a1, b1] = toLab(rgbToOklch(x));
|
|
103
|
+
const [l2, a2, b2] = toLab(rgbToOklch(y));
|
|
104
|
+
return Math.hypot(l1 - l2, a1 - a2, b1 - b2);
|
|
105
|
+
}
|
|
106
|
+
function oklchToLinear([L, C, h]) {
|
|
107
|
+
const A = C * Math.cos(h);
|
|
108
|
+
const B = C * Math.sin(h);
|
|
109
|
+
const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;
|
|
110
|
+
const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;
|
|
111
|
+
const s = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;
|
|
112
|
+
return [
|
|
113
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
114
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
115
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
var inGamut = (rgb) => rgb.every((c) => c >= -1e-6 && c <= 1 + 1e-6);
|
|
119
|
+
function oklchToHex([L, C, h]) {
|
|
120
|
+
let lo = 0;
|
|
121
|
+
let hi = C;
|
|
122
|
+
if (!inGamut(oklchToLinear([L, C, h]))) {
|
|
123
|
+
for (let i = 0; i < 24; i++) {
|
|
124
|
+
const mid = (lo + hi) / 2;
|
|
125
|
+
if (inGamut(oklchToLinear([L, mid, h]))) lo = mid;
|
|
126
|
+
else hi = mid;
|
|
127
|
+
}
|
|
128
|
+
C = lo;
|
|
129
|
+
}
|
|
130
|
+
return toHex(oklchToLinear([L, C, h]).map(fromLinear));
|
|
131
|
+
}
|
|
132
|
+
var L_STEP = 5e-3;
|
|
133
|
+
function stepUntil(lch, dir, test) {
|
|
134
|
+
for (let i = 1; ; i++) {
|
|
135
|
+
const L = lch[0] + dir * i * L_STEP;
|
|
136
|
+
if (L < 0 || L > 1) return null;
|
|
137
|
+
const hex = oklchToHex([L, lch[1], lch[2]]);
|
|
138
|
+
if (test(hex)) return { hex, steps: i };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function readableOn(color, backgrounds, min = CONTRAST.text) {
|
|
142
|
+
const bgs = typeof backgrounds === "string" ? [backgrounds] : backgrounds;
|
|
143
|
+
const rgb = parseHex(color);
|
|
144
|
+
if (!rgb) throw new Error(`readableOn: not a hex colour: ${color}`);
|
|
145
|
+
const hex = toHex(rgb);
|
|
146
|
+
const passes = (c) => minContrast(c, bgs) >= min;
|
|
147
|
+
if (passes(hex)) return hex;
|
|
148
|
+
const lch = rgbToOklch(rgb);
|
|
149
|
+
const darker = stepUntil(lch, -1, passes);
|
|
150
|
+
const lighter = stepUntil(lch, 1, passes);
|
|
151
|
+
if (darker && (!lighter || darker.steps <= lighter.steps)) return darker.hex;
|
|
152
|
+
if (lighter) return lighter.hex;
|
|
153
|
+
return minContrast("#000000", bgs) >= minContrast("#ffffff", bgs) ? "#000000" : "#ffffff";
|
|
154
|
+
}
|
|
155
|
+
function pickForeground(background, candidates) {
|
|
156
|
+
let best = candidates[0];
|
|
157
|
+
for (const c of candidates) if (contrastRatio(c, background) > contrastRatio(best, background)) best = c;
|
|
158
|
+
return normalizeHex(best) ?? best;
|
|
159
|
+
}
|
|
160
|
+
function solidPair(fill, candidates, min = CONTRAST.text) {
|
|
161
|
+
const rgb = parseHex(fill);
|
|
162
|
+
if (!rgb) throw new Error(`solidPair: not a hex colour: ${fill}`);
|
|
163
|
+
const hex = toHex(rgb);
|
|
164
|
+
const fg = pickForeground(hex, candidates);
|
|
165
|
+
if (contrastRatio(fg, hex) >= min) return { background: hex, foreground: fg };
|
|
166
|
+
const passes = (c) => contrastRatio(pickForeground(c, candidates), c) >= min;
|
|
167
|
+
const lch = rgbToOklch(rgb);
|
|
168
|
+
const darker = stepUntil(lch, -1, passes);
|
|
169
|
+
const lighter = stepUntil(lch, 1, passes);
|
|
170
|
+
const moved = darker && (!lighter || darker.steps <= lighter.steps) ? darker.hex : lighter?.hex ?? "#000000";
|
|
171
|
+
return { background: moved, foreground: pickForeground(moved, candidates) };
|
|
172
|
+
}
|
|
173
|
+
function mix(a, b, weight) {
|
|
174
|
+
const x = parseHex(a);
|
|
175
|
+
const y = parseHex(b);
|
|
176
|
+
if (!x || !y) throw new Error(`mix: not hex colours: ${a}, ${b}`);
|
|
177
|
+
return toHex(x.map((c, i) => c * weight + y[i] * (1 - weight)));
|
|
178
|
+
}
|
|
179
|
+
function rgba(hex, alpha) {
|
|
180
|
+
const rgb = parseHex(hex);
|
|
181
|
+
if (!rgb) throw new Error(`rgba: not a hex colour: ${hex}`);
|
|
182
|
+
return `rgba(${rgb.join(", ")}, ${alpha})`;
|
|
183
|
+
}
|
|
184
|
+
function shiftLightness(hex, delta) {
|
|
185
|
+
const rgb = parseHex(hex);
|
|
186
|
+
if (!rgb) throw new Error(`shiftLightness: not a hex colour: ${hex}`);
|
|
187
|
+
const [L, C, h] = rgbToOklch(rgb);
|
|
188
|
+
return oklchToHex([Math.max(0, Math.min(1, L + delta)), C, h]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/theme/brand-theme.ts
|
|
192
|
+
var reevePreset = {
|
|
193
|
+
accent: REEVE_ACCENT,
|
|
194
|
+
ink: "#1D3557",
|
|
195
|
+
// T0 proof (DEV-17840, approved 2026-11-03). Derivation alone lands on
|
|
196
|
+
// nearby shades; these are the approved ones and pass the same bar.
|
|
197
|
+
tuned: { link: { light: "#C2410C", dark: "#FF8A57" }, chartTint: "#FF9B5C" }
|
|
198
|
+
};
|
|
199
|
+
var RAMPS = {
|
|
200
|
+
// Reeve: navy undertone, slate working surfaces (DEV-17839).
|
|
201
|
+
cool: {
|
|
202
|
+
ink: "#1d3557",
|
|
203
|
+
light: { background: "#ffffff", card: "#ffffff", surface: "#f1f5f9", foreground: "#0d1b2a", mutedForeground: "#475569", steps: ["#64748b", "#94a3b8", "#cbd5e1", "#475569"] },
|
|
204
|
+
dark: { background: "#0d1b2a", card: "#122536", surface: "#1d3557", foreground: "#edf2f4", mutedForeground: "#a3b1c6", steps: ["#a3b1c6", "#64748b", "#3a5270", "#8d99ae"] }
|
|
205
|
+
},
|
|
206
|
+
// Zinc.
|
|
207
|
+
neutral: {
|
|
208
|
+
ink: "#18181b",
|
|
209
|
+
light: { background: "#ffffff", card: "#ffffff", surface: "#f4f4f5", foreground: "#09090b", mutedForeground: "#52525b", steps: ["#71717a", "#a1a1aa", "#d4d4d8", "#52525b"] },
|
|
210
|
+
dark: { background: "#09090b", card: "#18181b", surface: "#27272a", foreground: "#fafafa", mutedForeground: "#a1a1aa", steps: ["#a1a1aa", "#71717a", "#3f3f46", "#d4d4d8"] }
|
|
211
|
+
},
|
|
212
|
+
// Stone.
|
|
213
|
+
warm: {
|
|
214
|
+
ink: "#292524",
|
|
215
|
+
light: { background: "#ffffff", card: "#ffffff", surface: "#f5f5f4", foreground: "#0c0a09", mutedForeground: "#57534e", steps: ["#78716c", "#a8a29e", "#d6d3d1", "#57534e"] },
|
|
216
|
+
dark: { background: "#0c0a09", card: "#1c1917", surface: "#292524", foreground: "#fafaf9", mutedForeground: "#a8a29e", steps: ["#a8a29e", "#78716c", "#44403c", "#d6d3d1"] }
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
var STATUS = {
|
|
220
|
+
light: { destructive: "#dc2626", success: "#047857", warning: "#b45309" },
|
|
221
|
+
dark: { destructive: "#f87171", success: "#34d399", warning: "#fbbf24" }
|
|
222
|
+
};
|
|
223
|
+
var SUBTLE_WEIGHT = { light: 0.1, dark: 0.16 };
|
|
224
|
+
var MIN_FILL_DELTA_E = 0.1;
|
|
225
|
+
var CHART_TINT_SHIFT = 0.08;
|
|
226
|
+
var CSS_LENGTH_RE = /^(0|\d+(\.\d+)?(px|rem|em))$/;
|
|
227
|
+
var FONT_FAMILY_RE = /^([\w .-]+|"[\w .'-]+"|'[\w .-]+'|var\(--[\w-]+\))$/;
|
|
228
|
+
function safeLength(value) {
|
|
229
|
+
if (typeof value !== "string") return void 0;
|
|
230
|
+
const v = value.trim();
|
|
231
|
+
return v.length <= 16 && CSS_LENGTH_RE.test(v) ? v : void 0;
|
|
232
|
+
}
|
|
233
|
+
function safeFontList(value) {
|
|
234
|
+
if (typeof value !== "string") return void 0;
|
|
235
|
+
const v = value.trim();
|
|
236
|
+
if (!v || v.length > 160) return void 0;
|
|
237
|
+
const families = v.split(",").map((f) => f.trim());
|
|
238
|
+
return families.every((f) => FONT_FAMILY_RE.test(f)) ? families.join(", ") : void 0;
|
|
239
|
+
}
|
|
240
|
+
function tunedShade(value, surfaces, min) {
|
|
241
|
+
const hex = normalizeHex(value);
|
|
242
|
+
return hex && surfaces.every((s) => contrastRatio(hex, s) >= min) ? hex : void 0;
|
|
243
|
+
}
|
|
244
|
+
function mode(name, ramp, accent, ink, input) {
|
|
245
|
+
const r = ramp[name];
|
|
246
|
+
const surfaces = [r.background, r.card, r.surface];
|
|
247
|
+
const onFill = ["#ffffff", ramp.light.foreground];
|
|
248
|
+
const foreground = readableOn(r.foreground, surfaces, CONTRAST.text);
|
|
249
|
+
const mutedForeground = readableOn(r.mutedForeground, surfaces, CONTRAST.text);
|
|
250
|
+
const primary = solidPair(name === "light" ? ink : foreground, onFill, CONTRAST.text);
|
|
251
|
+
const page = [r.background, r.card];
|
|
252
|
+
const standsOut = (c) => page.every((s) => deltaE(c, s) >= MIN_FILL_DELTA_E);
|
|
253
|
+
const actionFill = standsOut(accent) ? accent : readableOn(accent, page, CONTRAST.indicator);
|
|
254
|
+
const action = solidPair(actionFill, onFill, CONTRAST.text);
|
|
255
|
+
const link = tunedShade(input.tuned?.link?.[name], surfaces, CONTRAST.text) ?? readableOn(accent, surfaces, CONTRAST.text);
|
|
256
|
+
const chart1 = surfaces.every((s) => contrastRatio(accent, s) >= CONTRAST.indicator) ? accent : link;
|
|
257
|
+
const tints = [shiftLightness(accent, CHART_TINT_SHIFT), shiftLightness(accent, -CHART_TINT_SHIFT)];
|
|
258
|
+
const chartTint = normalizeHex(input.tuned?.chartTint) ?? tints.find(standsOut) ?? readableOn(accent, page, CONTRAST.indicator);
|
|
259
|
+
const status = (hue) => {
|
|
260
|
+
const base = readableOn(hue, surfaces, CONTRAST.indicator);
|
|
261
|
+
const fill = solidPair(base, onFill, CONTRAST.text);
|
|
262
|
+
const subtle = mix(base, r.background, SUBTLE_WEIGHT[name]);
|
|
263
|
+
return { fill, subtle, subtleForeground: readableOn(base, subtle, CONTRAST.text) };
|
|
264
|
+
};
|
|
265
|
+
const destructive = status(STATUS[name].destructive);
|
|
266
|
+
const success = status(STATUS[name].success);
|
|
267
|
+
const warning = status(STATUS[name].warning);
|
|
268
|
+
const tokens = {
|
|
269
|
+
"--background": r.background,
|
|
270
|
+
"--foreground": foreground,
|
|
271
|
+
"--card": r.card,
|
|
272
|
+
"--card-foreground": foreground,
|
|
273
|
+
"--popover": r.card,
|
|
274
|
+
"--popover-foreground": foreground,
|
|
275
|
+
"--primary": primary.background,
|
|
276
|
+
"--primary-foreground": primary.foreground,
|
|
277
|
+
"--secondary": r.surface,
|
|
278
|
+
"--secondary-foreground": foreground,
|
|
279
|
+
"--muted": r.surface,
|
|
280
|
+
"--muted-foreground": mutedForeground,
|
|
281
|
+
"--accent": r.surface,
|
|
282
|
+
"--accent-foreground": foreground,
|
|
283
|
+
"--destructive": destructive.fill.background,
|
|
284
|
+
"--destructive-foreground": destructive.fill.foreground,
|
|
285
|
+
"--destructive-subtle": destructive.subtle,
|
|
286
|
+
"--destructive-subtle-foreground": destructive.subtleForeground,
|
|
287
|
+
"--success": success.fill.background,
|
|
288
|
+
"--success-foreground": success.fill.foreground,
|
|
289
|
+
"--success-subtle": success.subtle,
|
|
290
|
+
"--success-subtle-foreground": success.subtleForeground,
|
|
291
|
+
"--warning": warning.fill.background,
|
|
292
|
+
"--warning-foreground": warning.fill.foreground,
|
|
293
|
+
"--warning-subtle": warning.subtle,
|
|
294
|
+
"--warning-subtle-foreground": warning.subtleForeground,
|
|
295
|
+
"--border": name === "light" ? rgba(ink, 0.12) : rgba(foreground, 0.1),
|
|
296
|
+
"--input": name === "light" ? rgba(ink, 0.16) : rgba(foreground, 0.14),
|
|
297
|
+
"--ring": link,
|
|
298
|
+
"--link": link,
|
|
299
|
+
"--action": action.background,
|
|
300
|
+
"--action-foreground": action.foreground,
|
|
301
|
+
"--brand-accent": accent,
|
|
302
|
+
"--shadow-sm": name === "light" ? `0 1px 2px ${rgba(foreground, 0.06)}` : "0 1px 2px rgba(0, 0, 0, 0.3)",
|
|
303
|
+
"--shadow-md": name === "light" ? `0 4px 16px ${rgba(foreground, 0.08)}` : "0 4px 16px rgba(0, 0, 0, 0.35)",
|
|
304
|
+
"--shadow-lg": name === "light" ? `0 12px 32px ${rgba(foreground, 0.12)}` : "0 12px 32px rgba(0, 0, 0, 0.45)",
|
|
305
|
+
"--chart-1": chart1,
|
|
306
|
+
"--chart-2": name === "light" ? primary.background : foreground,
|
|
307
|
+
"--chart-3": r.steps[0],
|
|
308
|
+
"--chart-4": r.steps[1],
|
|
309
|
+
"--chart-5": r.steps[2],
|
|
310
|
+
"--chart-6": r.steps[3],
|
|
311
|
+
"--chart-7": chartTint,
|
|
312
|
+
"--chart-8": name === "light" ? foreground : ink
|
|
313
|
+
};
|
|
314
|
+
const radius = safeLength(input.radius);
|
|
315
|
+
if (radius) tokens["--radius"] = radius;
|
|
316
|
+
const sans = safeFontList(input.fonts?.sans);
|
|
317
|
+
if (sans) tokens["--font-sans"] = sans;
|
|
318
|
+
const display = safeFontList(input.fonts?.display);
|
|
319
|
+
if (display) tokens["--font-display"] = display;
|
|
320
|
+
const mono = safeFontList(input.fonts?.mono);
|
|
321
|
+
if (mono) tokens["--font-mono"] = mono;
|
|
322
|
+
return tokens;
|
|
323
|
+
}
|
|
324
|
+
function brandTheme(theme) {
|
|
325
|
+
const input = theme ?? {};
|
|
326
|
+
const temp = input.neutralTemperature;
|
|
327
|
+
const ramp = temp && Object.prototype.hasOwnProperty.call(RAMPS, temp) ? RAMPS[temp] : RAMPS.cool;
|
|
328
|
+
const accent = normalizeHex(input.accent) ?? normalizeHex(REEVE_ACCENT);
|
|
329
|
+
const l = ramp.light;
|
|
330
|
+
const ink = readableOn(normalizeHex(input.ink) ?? ramp.ink, [l.background, l.card, l.surface], CONTRAST.indicator);
|
|
331
|
+
return { light: mode("light", ramp, accent, ink, input), dark: mode("dark", ramp, accent, ink, input) };
|
|
332
|
+
}
|
|
333
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
334
|
+
0 && (module.exports = {
|
|
335
|
+
CONTRAST,
|
|
336
|
+
REEVE_ACCENT,
|
|
337
|
+
brandTheme,
|
|
338
|
+
contrastRatio,
|
|
339
|
+
deltaE,
|
|
340
|
+
mix,
|
|
341
|
+
normalizeHex,
|
|
342
|
+
parseHex,
|
|
343
|
+
pickForeground,
|
|
344
|
+
readableOn,
|
|
345
|
+
reevePreset,
|
|
346
|
+
relativeLuminance,
|
|
347
|
+
rgba,
|
|
348
|
+
shiftLightness,
|
|
349
|
+
solidPair,
|
|
350
|
+
toHex
|
|
351
|
+
});
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// src/lib/reeve-accent.ts
|
|
2
|
+
var REEVE_ACCENT = "#FF6B2B";
|
|
3
|
+
|
|
4
|
+
// src/theme/contrast.ts
|
|
5
|
+
var CONTRAST = { text: 4.5, indicator: 3 };
|
|
6
|
+
var HEX_RE = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
7
|
+
function parseHex(hex) {
|
|
8
|
+
if (typeof hex !== "string") return null;
|
|
9
|
+
const m = hex.trim().match(HEX_RE);
|
|
10
|
+
if (!m) return null;
|
|
11
|
+
const h = m[1].length === 3 ? m[1].replace(/./g, "$&$&") : m[1];
|
|
12
|
+
const n = parseInt(h, 16);
|
|
13
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
14
|
+
}
|
|
15
|
+
function toHex([r, g, b]) {
|
|
16
|
+
const c = (v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0");
|
|
17
|
+
return `#${c(r)}${c(g)}${c(b)}`;
|
|
18
|
+
}
|
|
19
|
+
function normalizeHex(hex) {
|
|
20
|
+
const rgb = parseHex(hex);
|
|
21
|
+
return rgb ? toHex(rgb) : null;
|
|
22
|
+
}
|
|
23
|
+
var toLinear = (c) => {
|
|
24
|
+
const s = c / 255;
|
|
25
|
+
return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
26
|
+
};
|
|
27
|
+
var fromLinear = (v) => {
|
|
28
|
+
const c = Math.max(0, Math.min(1, v));
|
|
29
|
+
return 255 * (c <= 31308e-7 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
30
|
+
};
|
|
31
|
+
function relativeLuminance(hex) {
|
|
32
|
+
const rgb = parseHex(hex);
|
|
33
|
+
if (!rgb) return 0;
|
|
34
|
+
const [r, g, b] = rgb.map(toLinear);
|
|
35
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
36
|
+
}
|
|
37
|
+
function contrastRatio(a, b) {
|
|
38
|
+
if (!parseHex(a) || !parseHex(b)) return 1;
|
|
39
|
+
const la = relativeLuminance(a);
|
|
40
|
+
const lb = relativeLuminance(b);
|
|
41
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
42
|
+
}
|
|
43
|
+
function minContrast(color, backgrounds) {
|
|
44
|
+
return Math.min(...backgrounds.map((bg) => contrastRatio(color, bg)));
|
|
45
|
+
}
|
|
46
|
+
function rgbToOklch(rgb) {
|
|
47
|
+
const [r, g, b] = rgb.map(toLinear);
|
|
48
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
49
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
50
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
51
|
+
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
52
|
+
const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
53
|
+
const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
54
|
+
return [L, Math.hypot(A, B), Math.atan2(B, A)];
|
|
55
|
+
}
|
|
56
|
+
function deltaE(a, b) {
|
|
57
|
+
const x = parseHex(a);
|
|
58
|
+
const y = parseHex(b);
|
|
59
|
+
if (!x || !y) return 0;
|
|
60
|
+
const toLab = ([L, C, h]) => [L, C * Math.cos(h), C * Math.sin(h)];
|
|
61
|
+
const [l1, a1, b1] = toLab(rgbToOklch(x));
|
|
62
|
+
const [l2, a2, b2] = toLab(rgbToOklch(y));
|
|
63
|
+
return Math.hypot(l1 - l2, a1 - a2, b1 - b2);
|
|
64
|
+
}
|
|
65
|
+
function oklchToLinear([L, C, h]) {
|
|
66
|
+
const A = C * Math.cos(h);
|
|
67
|
+
const B = C * Math.sin(h);
|
|
68
|
+
const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;
|
|
69
|
+
const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;
|
|
70
|
+
const s = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;
|
|
71
|
+
return [
|
|
72
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
73
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
74
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
var inGamut = (rgb) => rgb.every((c) => c >= -1e-6 && c <= 1 + 1e-6);
|
|
78
|
+
function oklchToHex([L, C, h]) {
|
|
79
|
+
let lo = 0;
|
|
80
|
+
let hi = C;
|
|
81
|
+
if (!inGamut(oklchToLinear([L, C, h]))) {
|
|
82
|
+
for (let i = 0; i < 24; i++) {
|
|
83
|
+
const mid = (lo + hi) / 2;
|
|
84
|
+
if (inGamut(oklchToLinear([L, mid, h]))) lo = mid;
|
|
85
|
+
else hi = mid;
|
|
86
|
+
}
|
|
87
|
+
C = lo;
|
|
88
|
+
}
|
|
89
|
+
return toHex(oklchToLinear([L, C, h]).map(fromLinear));
|
|
90
|
+
}
|
|
91
|
+
var L_STEP = 5e-3;
|
|
92
|
+
function stepUntil(lch, dir, test) {
|
|
93
|
+
for (let i = 1; ; i++) {
|
|
94
|
+
const L = lch[0] + dir * i * L_STEP;
|
|
95
|
+
if (L < 0 || L > 1) return null;
|
|
96
|
+
const hex = oklchToHex([L, lch[1], lch[2]]);
|
|
97
|
+
if (test(hex)) return { hex, steps: i };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function readableOn(color, backgrounds, min = CONTRAST.text) {
|
|
101
|
+
const bgs = typeof backgrounds === "string" ? [backgrounds] : backgrounds;
|
|
102
|
+
const rgb = parseHex(color);
|
|
103
|
+
if (!rgb) throw new Error(`readableOn: not a hex colour: ${color}`);
|
|
104
|
+
const hex = toHex(rgb);
|
|
105
|
+
const passes = (c) => minContrast(c, bgs) >= min;
|
|
106
|
+
if (passes(hex)) return hex;
|
|
107
|
+
const lch = rgbToOklch(rgb);
|
|
108
|
+
const darker = stepUntil(lch, -1, passes);
|
|
109
|
+
const lighter = stepUntil(lch, 1, passes);
|
|
110
|
+
if (darker && (!lighter || darker.steps <= lighter.steps)) return darker.hex;
|
|
111
|
+
if (lighter) return lighter.hex;
|
|
112
|
+
return minContrast("#000000", bgs) >= minContrast("#ffffff", bgs) ? "#000000" : "#ffffff";
|
|
113
|
+
}
|
|
114
|
+
function pickForeground(background, candidates) {
|
|
115
|
+
let best = candidates[0];
|
|
116
|
+
for (const c of candidates) if (contrastRatio(c, background) > contrastRatio(best, background)) best = c;
|
|
117
|
+
return normalizeHex(best) ?? best;
|
|
118
|
+
}
|
|
119
|
+
function solidPair(fill, candidates, min = CONTRAST.text) {
|
|
120
|
+
const rgb = parseHex(fill);
|
|
121
|
+
if (!rgb) throw new Error(`solidPair: not a hex colour: ${fill}`);
|
|
122
|
+
const hex = toHex(rgb);
|
|
123
|
+
const fg = pickForeground(hex, candidates);
|
|
124
|
+
if (contrastRatio(fg, hex) >= min) return { background: hex, foreground: fg };
|
|
125
|
+
const passes = (c) => contrastRatio(pickForeground(c, candidates), c) >= min;
|
|
126
|
+
const lch = rgbToOklch(rgb);
|
|
127
|
+
const darker = stepUntil(lch, -1, passes);
|
|
128
|
+
const lighter = stepUntil(lch, 1, passes);
|
|
129
|
+
const moved = darker && (!lighter || darker.steps <= lighter.steps) ? darker.hex : lighter?.hex ?? "#000000";
|
|
130
|
+
return { background: moved, foreground: pickForeground(moved, candidates) };
|
|
131
|
+
}
|
|
132
|
+
function mix(a, b, weight) {
|
|
133
|
+
const x = parseHex(a);
|
|
134
|
+
const y = parseHex(b);
|
|
135
|
+
if (!x || !y) throw new Error(`mix: not hex colours: ${a}, ${b}`);
|
|
136
|
+
return toHex(x.map((c, i) => c * weight + y[i] * (1 - weight)));
|
|
137
|
+
}
|
|
138
|
+
function rgba(hex, alpha) {
|
|
139
|
+
const rgb = parseHex(hex);
|
|
140
|
+
if (!rgb) throw new Error(`rgba: not a hex colour: ${hex}`);
|
|
141
|
+
return `rgba(${rgb.join(", ")}, ${alpha})`;
|
|
142
|
+
}
|
|
143
|
+
function shiftLightness(hex, delta) {
|
|
144
|
+
const rgb = parseHex(hex);
|
|
145
|
+
if (!rgb) throw new Error(`shiftLightness: not a hex colour: ${hex}`);
|
|
146
|
+
const [L, C, h] = rgbToOklch(rgb);
|
|
147
|
+
return oklchToHex([Math.max(0, Math.min(1, L + delta)), C, h]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/theme/brand-theme.ts
|
|
151
|
+
var reevePreset = {
|
|
152
|
+
accent: REEVE_ACCENT,
|
|
153
|
+
ink: "#1D3557",
|
|
154
|
+
// T0 proof (DEV-17840, approved 2026-11-03). Derivation alone lands on
|
|
155
|
+
// nearby shades; these are the approved ones and pass the same bar.
|
|
156
|
+
tuned: { link: { light: "#C2410C", dark: "#FF8A57" }, chartTint: "#FF9B5C" }
|
|
157
|
+
};
|
|
158
|
+
var RAMPS = {
|
|
159
|
+
// Reeve: navy undertone, slate working surfaces (DEV-17839).
|
|
160
|
+
cool: {
|
|
161
|
+
ink: "#1d3557",
|
|
162
|
+
light: { background: "#ffffff", card: "#ffffff", surface: "#f1f5f9", foreground: "#0d1b2a", mutedForeground: "#475569", steps: ["#64748b", "#94a3b8", "#cbd5e1", "#475569"] },
|
|
163
|
+
dark: { background: "#0d1b2a", card: "#122536", surface: "#1d3557", foreground: "#edf2f4", mutedForeground: "#a3b1c6", steps: ["#a3b1c6", "#64748b", "#3a5270", "#8d99ae"] }
|
|
164
|
+
},
|
|
165
|
+
// Zinc.
|
|
166
|
+
neutral: {
|
|
167
|
+
ink: "#18181b",
|
|
168
|
+
light: { background: "#ffffff", card: "#ffffff", surface: "#f4f4f5", foreground: "#09090b", mutedForeground: "#52525b", steps: ["#71717a", "#a1a1aa", "#d4d4d8", "#52525b"] },
|
|
169
|
+
dark: { background: "#09090b", card: "#18181b", surface: "#27272a", foreground: "#fafafa", mutedForeground: "#a1a1aa", steps: ["#a1a1aa", "#71717a", "#3f3f46", "#d4d4d8"] }
|
|
170
|
+
},
|
|
171
|
+
// Stone.
|
|
172
|
+
warm: {
|
|
173
|
+
ink: "#292524",
|
|
174
|
+
light: { background: "#ffffff", card: "#ffffff", surface: "#f5f5f4", foreground: "#0c0a09", mutedForeground: "#57534e", steps: ["#78716c", "#a8a29e", "#d6d3d1", "#57534e"] },
|
|
175
|
+
dark: { background: "#0c0a09", card: "#1c1917", surface: "#292524", foreground: "#fafaf9", mutedForeground: "#a8a29e", steps: ["#a8a29e", "#78716c", "#44403c", "#d6d3d1"] }
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var STATUS = {
|
|
179
|
+
light: { destructive: "#dc2626", success: "#047857", warning: "#b45309" },
|
|
180
|
+
dark: { destructive: "#f87171", success: "#34d399", warning: "#fbbf24" }
|
|
181
|
+
};
|
|
182
|
+
var SUBTLE_WEIGHT = { light: 0.1, dark: 0.16 };
|
|
183
|
+
var MIN_FILL_DELTA_E = 0.1;
|
|
184
|
+
var CHART_TINT_SHIFT = 0.08;
|
|
185
|
+
var CSS_LENGTH_RE = /^(0|\d+(\.\d+)?(px|rem|em))$/;
|
|
186
|
+
var FONT_FAMILY_RE = /^([\w .-]+|"[\w .'-]+"|'[\w .-]+'|var\(--[\w-]+\))$/;
|
|
187
|
+
function safeLength(value) {
|
|
188
|
+
if (typeof value !== "string") return void 0;
|
|
189
|
+
const v = value.trim();
|
|
190
|
+
return v.length <= 16 && CSS_LENGTH_RE.test(v) ? v : void 0;
|
|
191
|
+
}
|
|
192
|
+
function safeFontList(value) {
|
|
193
|
+
if (typeof value !== "string") return void 0;
|
|
194
|
+
const v = value.trim();
|
|
195
|
+
if (!v || v.length > 160) return void 0;
|
|
196
|
+
const families = v.split(",").map((f) => f.trim());
|
|
197
|
+
return families.every((f) => FONT_FAMILY_RE.test(f)) ? families.join(", ") : void 0;
|
|
198
|
+
}
|
|
199
|
+
function tunedShade(value, surfaces, min) {
|
|
200
|
+
const hex = normalizeHex(value);
|
|
201
|
+
return hex && surfaces.every((s) => contrastRatio(hex, s) >= min) ? hex : void 0;
|
|
202
|
+
}
|
|
203
|
+
function mode(name, ramp, accent, ink, input) {
|
|
204
|
+
const r = ramp[name];
|
|
205
|
+
const surfaces = [r.background, r.card, r.surface];
|
|
206
|
+
const onFill = ["#ffffff", ramp.light.foreground];
|
|
207
|
+
const foreground = readableOn(r.foreground, surfaces, CONTRAST.text);
|
|
208
|
+
const mutedForeground = readableOn(r.mutedForeground, surfaces, CONTRAST.text);
|
|
209
|
+
const primary = solidPair(name === "light" ? ink : foreground, onFill, CONTRAST.text);
|
|
210
|
+
const page = [r.background, r.card];
|
|
211
|
+
const standsOut = (c) => page.every((s) => deltaE(c, s) >= MIN_FILL_DELTA_E);
|
|
212
|
+
const actionFill = standsOut(accent) ? accent : readableOn(accent, page, CONTRAST.indicator);
|
|
213
|
+
const action = solidPair(actionFill, onFill, CONTRAST.text);
|
|
214
|
+
const link = tunedShade(input.tuned?.link?.[name], surfaces, CONTRAST.text) ?? readableOn(accent, surfaces, CONTRAST.text);
|
|
215
|
+
const chart1 = surfaces.every((s) => contrastRatio(accent, s) >= CONTRAST.indicator) ? accent : link;
|
|
216
|
+
const tints = [shiftLightness(accent, CHART_TINT_SHIFT), shiftLightness(accent, -CHART_TINT_SHIFT)];
|
|
217
|
+
const chartTint = normalizeHex(input.tuned?.chartTint) ?? tints.find(standsOut) ?? readableOn(accent, page, CONTRAST.indicator);
|
|
218
|
+
const status = (hue) => {
|
|
219
|
+
const base = readableOn(hue, surfaces, CONTRAST.indicator);
|
|
220
|
+
const fill = solidPair(base, onFill, CONTRAST.text);
|
|
221
|
+
const subtle = mix(base, r.background, SUBTLE_WEIGHT[name]);
|
|
222
|
+
return { fill, subtle, subtleForeground: readableOn(base, subtle, CONTRAST.text) };
|
|
223
|
+
};
|
|
224
|
+
const destructive = status(STATUS[name].destructive);
|
|
225
|
+
const success = status(STATUS[name].success);
|
|
226
|
+
const warning = status(STATUS[name].warning);
|
|
227
|
+
const tokens = {
|
|
228
|
+
"--background": r.background,
|
|
229
|
+
"--foreground": foreground,
|
|
230
|
+
"--card": r.card,
|
|
231
|
+
"--card-foreground": foreground,
|
|
232
|
+
"--popover": r.card,
|
|
233
|
+
"--popover-foreground": foreground,
|
|
234
|
+
"--primary": primary.background,
|
|
235
|
+
"--primary-foreground": primary.foreground,
|
|
236
|
+
"--secondary": r.surface,
|
|
237
|
+
"--secondary-foreground": foreground,
|
|
238
|
+
"--muted": r.surface,
|
|
239
|
+
"--muted-foreground": mutedForeground,
|
|
240
|
+
"--accent": r.surface,
|
|
241
|
+
"--accent-foreground": foreground,
|
|
242
|
+
"--destructive": destructive.fill.background,
|
|
243
|
+
"--destructive-foreground": destructive.fill.foreground,
|
|
244
|
+
"--destructive-subtle": destructive.subtle,
|
|
245
|
+
"--destructive-subtle-foreground": destructive.subtleForeground,
|
|
246
|
+
"--success": success.fill.background,
|
|
247
|
+
"--success-foreground": success.fill.foreground,
|
|
248
|
+
"--success-subtle": success.subtle,
|
|
249
|
+
"--success-subtle-foreground": success.subtleForeground,
|
|
250
|
+
"--warning": warning.fill.background,
|
|
251
|
+
"--warning-foreground": warning.fill.foreground,
|
|
252
|
+
"--warning-subtle": warning.subtle,
|
|
253
|
+
"--warning-subtle-foreground": warning.subtleForeground,
|
|
254
|
+
"--border": name === "light" ? rgba(ink, 0.12) : rgba(foreground, 0.1),
|
|
255
|
+
"--input": name === "light" ? rgba(ink, 0.16) : rgba(foreground, 0.14),
|
|
256
|
+
"--ring": link,
|
|
257
|
+
"--link": link,
|
|
258
|
+
"--action": action.background,
|
|
259
|
+
"--action-foreground": action.foreground,
|
|
260
|
+
"--brand-accent": accent,
|
|
261
|
+
"--shadow-sm": name === "light" ? `0 1px 2px ${rgba(foreground, 0.06)}` : "0 1px 2px rgba(0, 0, 0, 0.3)",
|
|
262
|
+
"--shadow-md": name === "light" ? `0 4px 16px ${rgba(foreground, 0.08)}` : "0 4px 16px rgba(0, 0, 0, 0.35)",
|
|
263
|
+
"--shadow-lg": name === "light" ? `0 12px 32px ${rgba(foreground, 0.12)}` : "0 12px 32px rgba(0, 0, 0, 0.45)",
|
|
264
|
+
"--chart-1": chart1,
|
|
265
|
+
"--chart-2": name === "light" ? primary.background : foreground,
|
|
266
|
+
"--chart-3": r.steps[0],
|
|
267
|
+
"--chart-4": r.steps[1],
|
|
268
|
+
"--chart-5": r.steps[2],
|
|
269
|
+
"--chart-6": r.steps[3],
|
|
270
|
+
"--chart-7": chartTint,
|
|
271
|
+
"--chart-8": name === "light" ? foreground : ink
|
|
272
|
+
};
|
|
273
|
+
const radius = safeLength(input.radius);
|
|
274
|
+
if (radius) tokens["--radius"] = radius;
|
|
275
|
+
const sans = safeFontList(input.fonts?.sans);
|
|
276
|
+
if (sans) tokens["--font-sans"] = sans;
|
|
277
|
+
const display = safeFontList(input.fonts?.display);
|
|
278
|
+
if (display) tokens["--font-display"] = display;
|
|
279
|
+
const mono = safeFontList(input.fonts?.mono);
|
|
280
|
+
if (mono) tokens["--font-mono"] = mono;
|
|
281
|
+
return tokens;
|
|
282
|
+
}
|
|
283
|
+
function brandTheme(theme) {
|
|
284
|
+
const input = theme ?? {};
|
|
285
|
+
const temp = input.neutralTemperature;
|
|
286
|
+
const ramp = temp && Object.prototype.hasOwnProperty.call(RAMPS, temp) ? RAMPS[temp] : RAMPS.cool;
|
|
287
|
+
const accent = normalizeHex(input.accent) ?? normalizeHex(REEVE_ACCENT);
|
|
288
|
+
const l = ramp.light;
|
|
289
|
+
const ink = readableOn(normalizeHex(input.ink) ?? ramp.ink, [l.background, l.card, l.surface], CONTRAST.indicator);
|
|
290
|
+
return { light: mode("light", ramp, accent, ink, input), dark: mode("dark", ramp, accent, ink, input) };
|
|
291
|
+
}
|
|
292
|
+
export {
|
|
293
|
+
CONTRAST,
|
|
294
|
+
REEVE_ACCENT,
|
|
295
|
+
brandTheme,
|
|
296
|
+
contrastRatio,
|
|
297
|
+
deltaE,
|
|
298
|
+
mix,
|
|
299
|
+
normalizeHex,
|
|
300
|
+
parseHex,
|
|
301
|
+
pickForeground,
|
|
302
|
+
readableOn,
|
|
303
|
+
reevePreset,
|
|
304
|
+
relativeLuminance,
|
|
305
|
+
rgba,
|
|
306
|
+
shiftLightness,
|
|
307
|
+
solidPair,
|
|
308
|
+
toHex
|
|
309
|
+
};
|
package/dist/tokens.css
CHANGED
|
@@ -32,32 +32,34 @@
|
|
|
32
32
|
* Chart tokens (@meetreeve/ui/charts, DEV-17042). Every chart colour reads one
|
|
33
33
|
* of these; components contain no hex. In a base layer so a host's own
|
|
34
34
|
* (unlayered) :root / .dark values win — set them to re-skin every chart in
|
|
35
|
-
* the brand's colours. Defaults are
|
|
35
|
+
* the brand's colours. Defaults are brandTheme(reevePreset)'s --chart-* from
|
|
36
|
+
* @meetreeve/ui/theme (DEV-17886), pinned by theme/brand-theme.test.ts:
|
|
37
|
+
* neutral-first, series 1 the Reeve orange, the rest ink/slate steps.
|
|
36
38
|
*/
|
|
37
39
|
@layer base {
|
|
38
40
|
:root {
|
|
39
|
-
--chart-1: #
|
|
40
|
-
--chart-2: #
|
|
41
|
-
--chart-3: #
|
|
42
|
-
--chart-4: #
|
|
43
|
-
--chart-5: #
|
|
44
|
-
--chart-6: #
|
|
45
|
-
--chart-7: #
|
|
46
|
-
--chart-8: #
|
|
41
|
+
--chart-1: #c2410c;
|
|
42
|
+
--chart-2: #1d3557;
|
|
43
|
+
--chart-3: #64748b;
|
|
44
|
+
--chart-4: #94a3b8;
|
|
45
|
+
--chart-5: #cbd5e1;
|
|
46
|
+
--chart-6: #475569;
|
|
47
|
+
--chart-7: #ff9b5c;
|
|
48
|
+
--chart-8: #0d1b2a;
|
|
47
49
|
--chart-positive: #059669;
|
|
48
50
|
--chart-negative: #e11d48;
|
|
49
51
|
--chart-grid: var(--border);
|
|
50
52
|
--chart-muted: var(--muted-foreground);
|
|
51
53
|
}
|
|
52
54
|
.dark {
|
|
53
|
-
--chart-1: #
|
|
54
|
-
--chart-2: #
|
|
55
|
-
--chart-3: #
|
|
56
|
-
--chart-4: #
|
|
57
|
-
--chart-5: #
|
|
58
|
-
--chart-6: #
|
|
59
|
-
--chart-7: #
|
|
60
|
-
--chart-8: #
|
|
55
|
+
--chart-1: #ff6b2b;
|
|
56
|
+
--chart-2: #edf2f4;
|
|
57
|
+
--chart-3: #a3b1c6;
|
|
58
|
+
--chart-4: #64748b;
|
|
59
|
+
--chart-5: #3a5270;
|
|
60
|
+
--chart-6: #8d99ae;
|
|
61
|
+
--chart-7: #ff9b5c;
|
|
62
|
+
--chart-8: #1d3557;
|
|
61
63
|
--chart-positive: #34d399;
|
|
62
64
|
--chart-negative: #fb7185;
|
|
63
65
|
/* Re-declared so they resolve against the dark --border / --muted-foreground
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meetreeve/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Shared brand-adaptive UI primitives for MindFortress frontends — min-size tokens, a favicon→logo→monogram BrandGlyph, a responsive header that keeps the search bar usable on mobile, AppSidebar's viewport-driven auto-collapse ladder, the StageRail flow-of-cards primitives, the tenant SiteFooter, the LockedValue/LockedBlock/UnlockCta paywall primitives,
|
|
3
|
+
"version": "0.23.0",
|
|
4
|
+
"description": "Shared brand-adaptive UI primitives for MindFortress frontends — min-size tokens, a favicon→logo→monogram BrandGlyph, a responsive header that keeps the search bar usable on mobile, AppSidebar's viewport-driven auto-collapse ladder, the StageRail flow-of-cards primitives, the tenant SiteFooter, the LockedValue/LockedBlock/UnlockCta paywall primitives, the @meetreeve/ui/charts dashboard kit (token-driven charts, KpiCard, ChartCard, DashboardGrid), and @meetreeve/ui/theme (brandTheme: one brand's inputs to contrast-checked light and dark semantic tokens, with the Reeve preset).",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"import": "./dist/charts/index.mjs",
|
|
38
38
|
"require": "./dist/charts/index.js"
|
|
39
39
|
},
|
|
40
|
+
"./theme": {
|
|
41
|
+
"types": "./dist/theme/index.d.ts",
|
|
42
|
+
"import": "./dist/theme/index.mjs",
|
|
43
|
+
"require": "./dist/theme/index.js"
|
|
44
|
+
},
|
|
40
45
|
"./tokens.css": "./dist/tokens.css"
|
|
41
46
|
},
|
|
42
47
|
"files": [
|