@meetreeve/ui 0.21.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 +100 -0
- package/THIRD_PARTY_NOTICES.md +68 -0
- package/dist/charts/index.d.mts +331 -0
- package/dist/charts/index.d.ts +331 -0
- package/dist/charts/index.js +913 -0
- package/dist/charts/index.mjs +860 -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 +41 -0
- package/package.json +23 -4
|
@@ -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
|
+
};
|