@glasshome/ui 1.17.0 → 1.18.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/SPEC.md +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/button-variants.d.ts +1 -1
- package/dist/lib/pill-classes.d.ts +1 -1
- package/dist/lib/thumb-classes.d.ts +1 -0
- package/dist/lib/tier-badge.d.ts +1 -1
- package/dist/solid/index.js +4001 -4001
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.js +203 -7
- package/dist/tokens/readability.d.ts +21 -0
- package/dist/tokens/theme-recipe.d.ts +25 -0
- package/dist/{utils-DMaksjvy.js → utils-COITV1s9.js} +327 -327
- package/package.json +1 -1
- package/src/lib/button-variants.ts +6 -4
- package/src/lib/pill-classes.ts +4 -3
- package/src/lib/thumb-classes.ts +7 -0
- package/src/lib/tier-badge.ts +1 -1
- package/src/solid/carousel.tsx +2 -2
- package/src/solid/data-table.tsx +2 -2
- package/src/solid/icon-picker.tsx +1 -1
- package/src/solid/media-tile.tsx +1 -1
- package/src/solid/switch.tsx +5 -2
- package/src/styles/theme.css +9 -3
- package/src/tokens/index.ts +2 -0
- package/src/tokens/presets.ts +6 -6
- package/src/tokens/readability.ts +67 -0
- package/src/tokens/theme-recipe.ts +147 -0
package/package.json
CHANGED
|
@@ -8,11 +8,13 @@ export const OUTLINE_SURFACE =
|
|
|
8
8
|
/* Buttons are glass pills on an OPAQUE --card base: a translucent fill goes
|
|
9
9
|
* muddy over dark heroes/sections. Every class is literal for Tailwind's
|
|
10
10
|
* scanner. `size: none` is sizeless for callers that own height/padding. */
|
|
11
|
+
/* Controls take the theme's corner (rounded-lg is --radius): a capsule at the
|
|
12
|
+
* roundness every preset but the sharp one ships, square at zero. */
|
|
11
13
|
export const buttonVariants = cva({
|
|
12
14
|
// structural-ok: the [&_svg]: utilities stay in Tailwind's utility layer so a
|
|
13
15
|
// caller's own [&_svg]:size-* override can still win; unlayered real CSS in
|
|
14
16
|
// globals.css would beat every consumer utility regardless of specificity.
|
|
15
|
-
base: "inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-
|
|
17
|
+
base: "inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-lg font-medium text-sm outline-none transition-glass focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 active:scale-[0.97] disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
16
18
|
variants: {
|
|
17
19
|
variant: {
|
|
18
20
|
default:
|
|
@@ -45,7 +47,7 @@ export const buttonVariants = cva({
|
|
|
45
47
|
export const BUTTON_DEFAULT_CLASS = buttonVariants({ variant: "default", size: "none" });
|
|
46
48
|
export const BUTTON_OUTLINE_CLASS = buttonVariants({ variant: "outline", size: "none" });
|
|
47
49
|
|
|
48
|
-
/*
|
|
49
|
-
*
|
|
50
|
+
/* Ghost icon button (copy buttons, small icon actions). Size and text color
|
|
51
|
+
* stay at the call site. */
|
|
50
52
|
export const ICON_BUTTON_CLASS =
|
|
51
|
-
"inline-flex shrink-0 cursor-pointer items-center justify-center rounded-
|
|
53
|
+
"inline-flex shrink-0 cursor-pointer items-center justify-center rounded-lg transition-glass duration-150 hover:bg-primary/10 active:scale-[0.97]";
|
package/src/lib/pill-classes.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/* Small tinted things share the Badge material. A chip is a
|
|
2
|
-
*
|
|
1
|
+
/* Small tinted things share the Badge material. A chip is a glass pill at the
|
|
2
|
+
* theme's corner, so it squares off with a sharp theme (Badge, CountPill, scope
|
|
3
|
+
* chips); an icon pill is the square-ish glass
|
|
3
4
|
* well behind a glyph (SectionIcon, ItemMedia, EmptyMedia). Tone comes from the
|
|
4
5
|
* caller's --glass-tone (via Badge's style or a [--glass-tone:…] utility);
|
|
5
6
|
* neutral wells set none and read as foreground glass. */
|
|
6
7
|
export const CHIP =
|
|
7
|
-
"glass glass-tint inline-flex w-fit shrink-0 select-none items-center gap-1.5 whitespace-nowrap rounded-
|
|
8
|
+
"glass glass-tint inline-flex w-fit shrink-0 select-none items-center gap-1.5 whitespace-nowrap rounded-lg px-2.5 py-0.5 font-medium text-xs";
|
|
8
9
|
|
|
9
10
|
export const ICON_PILL =
|
|
10
11
|
"glass flex shrink-0 items-center justify-center [--glass-rim:0.4] [--glass-light:0.08] [--glass-base:color-mix(in_srgb,var(--foreground)_10%,transparent)]";
|
package/src/lib/thumb-classes.ts
CHANGED
|
@@ -11,6 +11,13 @@ export const THUMB_SIZE = 31;
|
|
|
11
11
|
export const THUMB_CLASS =
|
|
12
12
|
"block size-7 shrink-0 rounded-xl shadow-[0_2px_5px_oklch(0_0_0/0.35),inset_0_1px_0_oklch(1_0_0/0.35),inset_0_-2px_3px_oklch(0_0_0/0.2)]";
|
|
13
13
|
|
|
14
|
+
/* The lit knob wears the theme's hue at the depth theme.css sets per mode. The
|
|
15
|
+
* knob re-declares --thumb-face-on on itself with this value: a var() resolves
|
|
16
|
+
* where it is declared, so the :root one answers for the page only and a
|
|
17
|
+
* container that re-scopes --primary (a theme preview) would keep the page's. */
|
|
18
|
+
export const THUMB_FACE_ON =
|
|
19
|
+
"oklch(from var(--primary) var(--thumb-on-l) min(c, var(--thumb-on-c)) h)";
|
|
20
|
+
|
|
14
21
|
/* A rail pads by half a thumb so the knob stays inside the track at both ends;
|
|
15
22
|
* the fill cancels the same inset to reach the rounded edges. */
|
|
16
23
|
/* A thumb painted the live channel colour sits on a track of that same colour,
|
package/src/lib/tier-badge.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Metallic tier chip: 135deg brushed sweep, bright ends, dip in the middle. */
|
|
2
2
|
|
|
3
3
|
export const TIER_BADGE_CLASS =
|
|
4
|
-
"inline-flex cursor-default select-none items-center rounded-
|
|
4
|
+
"inline-flex cursor-default select-none items-center rounded-lg px-2 py-0.5 font-black text-[10px] tracking-wide";
|
|
5
5
|
|
|
6
6
|
/** Optional sweep shaping. Default is the symmetric brushed look (both ends
|
|
7
7
|
* `hi`, dipping to `lo` at the midpoint). The collectible/license golds are a
|
package/src/solid/carousel.tsx
CHANGED
|
@@ -248,7 +248,7 @@ const CarouselPrevious: Component<ComponentProps<typeof Button>> = (props) => {
|
|
|
248
248
|
variant={local.variant ?? "outline"}
|
|
249
249
|
size={local.size ?? "icon"}
|
|
250
250
|
class={cn(
|
|
251
|
-
"absolute size-8
|
|
251
|
+
"absolute size-8",
|
|
252
252
|
orientation() === "horizontal"
|
|
253
253
|
? "top-1/2 -left-12 -translate-y-1/2"
|
|
254
254
|
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
@@ -274,7 +274,7 @@ const CarouselNext: Component<ComponentProps<typeof Button>> = (props) => {
|
|
|
274
274
|
variant={local.variant ?? "outline"}
|
|
275
275
|
size={local.size ?? "icon"}
|
|
276
276
|
class={cn(
|
|
277
|
-
"absolute size-8
|
|
277
|
+
"absolute size-8",
|
|
278
278
|
orientation() === "horizontal"
|
|
279
279
|
? "top-1/2 -right-12 -translate-y-1/2"
|
|
280
280
|
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
package/src/solid/data-table.tsx
CHANGED
|
@@ -293,8 +293,8 @@ export function TableSkeleton(props: { count?: number; class?: string }) {
|
|
|
293
293
|
class={cn("h-2.5", SKELETON_META_WIDTHS[i() % SKELETON_META_WIDTHS.length])}
|
|
294
294
|
/>
|
|
295
295
|
<div class="flex gap-1 pt-0.5 sm:hidden">
|
|
296
|
-
<Skeleton class="h-4 w-12 rounded-
|
|
297
|
-
<Skeleton class="h-4 w-16 rounded-
|
|
296
|
+
<Skeleton class="h-4 w-12 rounded-lg" />
|
|
297
|
+
<Skeleton class="h-4 w-16 rounded-lg" />
|
|
298
298
|
</div>
|
|
299
299
|
</div>
|
|
300
300
|
<Skeleton class="h-3 w-12 shrink-0" />
|
|
@@ -410,7 +410,7 @@ export function IconPicker(props: IconPickerProps) {
|
|
|
410
410
|
type="button"
|
|
411
411
|
aria-pressed={props.value === icon}
|
|
412
412
|
class={cn(
|
|
413
|
-
"mx-auto flex size-11 cursor-pointer items-center justify-center rounded-
|
|
413
|
+
"mx-auto flex size-11 cursor-pointer items-center justify-center rounded-lg transition-glass hover:bg-accent",
|
|
414
414
|
props.value === icon &&
|
|
415
415
|
`${ICON_PILL_TINT} text-foreground [--glass-tone:var(--primary)] hover:bg-transparent`,
|
|
416
416
|
)}
|
package/src/solid/media-tile.tsx
CHANGED
|
@@ -85,7 +85,7 @@ export function MediaTile(props: MediaTileProps) {
|
|
|
85
85
|
data-slot="media-tile-delete"
|
|
86
86
|
// after:-inset-1.5 lifts the touch target to ~44px without growing the glyph or its scrim.
|
|
87
87
|
class={cn(
|
|
88
|
-
"absolute top-1 right-1 size-8
|
|
88
|
+
"absolute top-1 right-1 size-8 text-destructive hover:text-destructive",
|
|
89
89
|
"after:absolute after:-inset-1.5 after:content-['']",
|
|
90
90
|
SCRIM_CLASS,
|
|
91
91
|
)}
|
package/src/solid/switch.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Component, type ComponentProps, createSignal, splitProps } from "solid-js";
|
|
2
2
|
import { FIELD_CHROME, FOCUS_RING } from "../lib/input-classes.js";
|
|
3
|
-
import { THUMB_CLASS } from "../lib/thumb-classes.js";
|
|
3
|
+
import { THUMB_CLASS, THUMB_FACE_ON } from "../lib/thumb-classes.js";
|
|
4
4
|
import { cn } from "../lib/utils.js";
|
|
5
5
|
|
|
6
6
|
type SwitchProps = Omit<ComponentProps<"button">, "onChange" | "children"> & {
|
|
@@ -52,7 +52,10 @@ const Switch: Component<SwitchProps> = (props) => {
|
|
|
52
52
|
)}
|
|
53
53
|
// Off must read quieter than on: the knob dims with the track rather
|
|
54
54
|
// than staying one bright material in both states.
|
|
55
|
-
style={{
|
|
55
|
+
style={{
|
|
56
|
+
"--thumb-face-on": THUMB_FACE_ON,
|
|
57
|
+
background: checked() ? "var(--thumb-face-on)" : "var(--thumb-face-off)",
|
|
58
|
+
}}
|
|
56
59
|
/>
|
|
57
60
|
{local.name && <input type="hidden" name={local.name} value={checked() ? "on" : "off"} />}
|
|
58
61
|
</button>
|
package/src/styles/theme.css
CHANGED
|
@@ -214,8 +214,12 @@
|
|
|
214
214
|
--field-edge: var(--border);
|
|
215
215
|
/* The knob says the state too: on wears --primary's hue, off stays inert
|
|
216
216
|
* metal in the recessed well. Light reads lit by going darker than its pale
|
|
217
|
-
* track, dark by going lighter; the hue is what carries across both.
|
|
218
|
-
|
|
217
|
+
* track, dark by going lighter; the hue is what carries across both. The
|
|
218
|
+
* knob derives in its own scope (lib/thumb-classes.ts); --thumb-face-on is
|
|
219
|
+
* the same expression at page scope, for anything else that reads it. */
|
|
220
|
+
--thumb-on-l: 0.55;
|
|
221
|
+
--thumb-on-c: 0.16;
|
|
222
|
+
--thumb-face-on: oklch(from var(--primary) var(--thumb-on-l) min(c, var(--thumb-on-c)) h);
|
|
219
223
|
--thumb-face-off: oklch(0.62 0.015 250);
|
|
220
224
|
--chart-1: oklch(0.7459 0.1483 156.4499);
|
|
221
225
|
--chart-2: oklch(0.48 0.2 215.221);
|
|
@@ -309,7 +313,9 @@ html[data-motion="live"] {
|
|
|
309
313
|
--field-edge: color-mix(in srgb, var(--border) 60%, transparent);
|
|
310
314
|
/* Lit through hue, not brightness: a neutral knob this light read as the
|
|
311
315
|
* loudest pixel in the row. Carries --primary's hue, so on ties to the rim. */
|
|
312
|
-
--thumb-
|
|
316
|
+
--thumb-on-l: 0.78;
|
|
317
|
+
--thumb-on-c: 0.1;
|
|
318
|
+
--thumb-face-on: oklch(from var(--primary) var(--thumb-on-l) min(c, var(--thumb-on-c)) h);
|
|
313
319
|
--thumb-face-off: oklch(0.45 0.015 250);
|
|
314
320
|
--chart-1: oklch(0.8003 0.1821 151.711);
|
|
315
321
|
--chart-2: oklch(0.48 0.2 215.221);
|
package/src/tokens/index.ts
CHANGED
package/src/tokens/presets.ts
CHANGED
|
@@ -94,7 +94,7 @@ export const THEME_PRESETS: ThemePreset[] = [
|
|
|
94
94
|
preset(
|
|
95
95
|
"sunrise-studio",
|
|
96
96
|
"Sunrise Studio",
|
|
97
|
-
1.
|
|
97
|
+
1.1,
|
|
98
98
|
["#e8590c", "#fab005"],
|
|
99
99
|
{
|
|
100
100
|
primary: "oklch(0.68 0.16 50)",
|
|
@@ -109,7 +109,7 @@ export const THEME_PRESETS: ThemePreset[] = [
|
|
|
109
109
|
preset(
|
|
110
110
|
"forest-zen",
|
|
111
111
|
"Forest Zen",
|
|
112
|
-
1.
|
|
112
|
+
1.6,
|
|
113
113
|
["#2f9e44", "#12b886"],
|
|
114
114
|
{
|
|
115
115
|
primary: "oklch(0.58 0.13 145)",
|
|
@@ -124,7 +124,7 @@ export const THEME_PRESETS: ThemePreset[] = [
|
|
|
124
124
|
preset(
|
|
125
125
|
"lavender-dreams",
|
|
126
126
|
"Lavender Dreams",
|
|
127
|
-
1.
|
|
127
|
+
1.8,
|
|
128
128
|
["#9c36b5", "#e64980"],
|
|
129
129
|
{
|
|
130
130
|
primary: "oklch(0.62 0.14 300)",
|
|
@@ -139,7 +139,7 @@ export const THEME_PRESETS: ThemePreset[] = [
|
|
|
139
139
|
preset(
|
|
140
140
|
"coral-reef",
|
|
141
141
|
"Coral Reef",
|
|
142
|
-
1.
|
|
142
|
+
1.25,
|
|
143
143
|
["#e03131", "#fd7e14"],
|
|
144
144
|
{
|
|
145
145
|
primary: "oklch(0.66 0.19 20)",
|
|
@@ -169,7 +169,7 @@ export const THEME_PRESETS: ThemePreset[] = [
|
|
|
169
169
|
preset(
|
|
170
170
|
"ocean-breeze",
|
|
171
171
|
"Ocean Breeze",
|
|
172
|
-
1.
|
|
172
|
+
1.5,
|
|
173
173
|
["#1098ad", "#3b5bdb"],
|
|
174
174
|
{
|
|
175
175
|
primary: "oklch(0.6 0.16 235)",
|
|
@@ -179,7 +179,7 @@ export const THEME_PRESETS: ThemePreset[] = [
|
|
|
179
179
|
card: "oklch(0.97 0.01 230)",
|
|
180
180
|
background: "oklch(0.99 0.01 235)",
|
|
181
181
|
},
|
|
182
|
-
bg("
|
|
182
|
+
bg("abstract-pattern", { url: "/backgrounds/ride-the-wave.svg" }),
|
|
183
183
|
),
|
|
184
184
|
];
|
|
185
185
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { clamp, parseOklch, type ThemeColors, toOklch } from "./theme-colors.js";
|
|
2
|
+
import { contrastRatio } from "./theme-css.js";
|
|
3
|
+
|
|
4
|
+
type Key = keyof ThemeColors;
|
|
5
|
+
|
|
6
|
+
export interface ReadablePair {
|
|
7
|
+
/** The color read as text, an icon or an indicator. */
|
|
8
|
+
text: Key;
|
|
9
|
+
surface: Key;
|
|
10
|
+
/** 4.5 for text, 3 for icons and indicators (WCAG AA). */
|
|
11
|
+
min: 4.5 | 3;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* Foregrounds on the ground, cards and fills are picked black-or-white by
|
|
15
|
+
* contrast, which always clears 4.5, so they are absent here. These are the
|
|
16
|
+
* colors a theme author sets that are read against a surface. */
|
|
17
|
+
export const READABLE_PAIRS: ReadablePair[] = [
|
|
18
|
+
{ text: "mutedForeground", surface: "background", min: 4.5 },
|
|
19
|
+
{ text: "mutedForeground", surface: "card", min: 4.5 },
|
|
20
|
+
{ text: "mutedForeground", surface: "muted", min: 4.5 },
|
|
21
|
+
{ text: "destructive", surface: "background", min: 4.5 },
|
|
22
|
+
{ text: "destructive", surface: "card", min: 4.5 },
|
|
23
|
+
{ text: "primary", surface: "background", min: 3 },
|
|
24
|
+
{ text: "primary", surface: "card", min: 3 },
|
|
25
|
+
{ text: "ring", surface: "background", min: 3 },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export interface ReadabilityIssue extends ReadablePair {
|
|
29
|
+
ratio: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function findUnreadable(colors: ThemeColors): ReadabilityIssue[] {
|
|
33
|
+
return READABLE_PAIRS.flatMap((pair) => {
|
|
34
|
+
const ratio = contrastRatio(colors[pair.text], colors[pair.surface]);
|
|
35
|
+
return ratio >= pair.min ? [] : [{ ...pair, ratio }];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const STEP = 0.01;
|
|
40
|
+
|
|
41
|
+
function surfacesOf(text: Key): ReadablePair[] {
|
|
42
|
+
return READABLE_PAIRS.filter((pair) => pair.text === text);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function clears(candidate: string, colors: ThemeColors, pairs: ReadablePair[]): boolean {
|
|
46
|
+
return pairs.every((pair) => contrastRatio(candidate, colors[pair.surface]) >= pair.min);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The nearest lightness of the text color that clears every surface it is read
|
|
51
|
+
* on, hue and chroma kept. Null when no lightness can: the surfaces disagree
|
|
52
|
+
* (one dark, one light), and only a different surface fixes that.
|
|
53
|
+
*/
|
|
54
|
+
export function fixReadable(colors: ThemeColors, text: Key): string | null {
|
|
55
|
+
const parsed = parseOklch(colors[text]);
|
|
56
|
+
if (!parsed) return null;
|
|
57
|
+
const pairs = surfacesOf(text);
|
|
58
|
+
for (let distance = STEP; distance <= 1; distance += STEP) {
|
|
59
|
+
for (const direction of [-1, 1]) {
|
|
60
|
+
const l = parsed.l + direction * distance;
|
|
61
|
+
if (l < 0 || l > 1) continue;
|
|
62
|
+
const candidate = toOklch(clamp(Number(l.toFixed(4)), 0, 1), parsed.c, parsed.h);
|
|
63
|
+
if (clears(candidate, colors, pairs)) return candidate;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { findUnreadable, fixReadable } from "./readability.js";
|
|
2
|
+
import {
|
|
3
|
+
type BackgroundConfig,
|
|
4
|
+
clamp,
|
|
5
|
+
deriveDarkFromLight,
|
|
6
|
+
parseOklch,
|
|
7
|
+
resolveThemeColors,
|
|
8
|
+
type ThemeBaseColors,
|
|
9
|
+
type ThemeColors,
|
|
10
|
+
type ThemeColorsConfig,
|
|
11
|
+
toOklch,
|
|
12
|
+
} from "./theme-colors.js";
|
|
13
|
+
|
|
14
|
+
export const RECIPE_VERSION = 1;
|
|
15
|
+
|
|
16
|
+
type Mode = "light" | "dark";
|
|
17
|
+
|
|
18
|
+
/** What was chosen, never what was computed: a stored theme re-derives on read. */
|
|
19
|
+
export interface ThemeRecipe {
|
|
20
|
+
/** Selects the derivation table, so a change to the math never moves a stored theme. */
|
|
21
|
+
v: typeof RECIPE_VERSION;
|
|
22
|
+
accent: string;
|
|
23
|
+
/** Tint and depth of the ground the glass sits on, as chosen for light. */
|
|
24
|
+
surface: string;
|
|
25
|
+
radius: number;
|
|
26
|
+
background: BackgroundConfig;
|
|
27
|
+
/** Dark is derived from the light result instead of from the seeds. */
|
|
28
|
+
darkLinked: boolean;
|
|
29
|
+
/** Hand-set colors only; everything absent is derived. */
|
|
30
|
+
set: { light: Partial<ThemeColors>; dark: Partial<ThemeColors> };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Step {
|
|
34
|
+
l?: number;
|
|
35
|
+
lTo?: number;
|
|
36
|
+
c?: number;
|
|
37
|
+
cMax?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const LADDER_V1: Record<
|
|
41
|
+
Mode,
|
|
42
|
+
Record<"ground" | "card" | "border" | "secondary" | "primary" | "accent", Step>
|
|
43
|
+
> = {
|
|
44
|
+
light: {
|
|
45
|
+
ground: {},
|
|
46
|
+
card: { l: 0.015, c: 0.6 },
|
|
47
|
+
border: { l: -0.08, c: 1.2, cMax: 0.06 },
|
|
48
|
+
secondary: { l: -0.035 },
|
|
49
|
+
primary: {},
|
|
50
|
+
accent: { l: 0.05, c: 0.85 },
|
|
51
|
+
},
|
|
52
|
+
dark: {
|
|
53
|
+
ground: { lTo: 0.14, c: 1.5, cMax: 0.04 },
|
|
54
|
+
card: { lTo: 0.18, c: 1.5, cMax: 0.04 },
|
|
55
|
+
border: { lTo: 0.26, c: 1.5, cMax: 0.05 },
|
|
56
|
+
secondary: { lTo: 0.21, c: 1.5, cMax: 0.04 },
|
|
57
|
+
primary: { l: 0.08 },
|
|
58
|
+
accent: { l: 0.12, c: 0.85 },
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function step(color: string, by: Step): string {
|
|
63
|
+
const parsed = parseOklch(color);
|
|
64
|
+
if (!parsed) return color;
|
|
65
|
+
const l = clamp(by.lTo ?? parsed.l + (by.l ?? 0), 0, 1);
|
|
66
|
+
const c = clamp(parsed.c * (by.c ?? 1), 0, by.cMax ?? 0.4);
|
|
67
|
+
return toOklch(l, c, parsed.h);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function baseFromSeeds(recipe: ThemeRecipe, mode: Mode): ThemeBaseColors {
|
|
71
|
+
const ladder = LADDER_V1[mode];
|
|
72
|
+
return {
|
|
73
|
+
background: step(recipe.surface, ladder.ground),
|
|
74
|
+
card: step(recipe.surface, ladder.card),
|
|
75
|
+
border: step(recipe.surface, ladder.border),
|
|
76
|
+
secondary: step(recipe.surface, ladder.secondary),
|
|
77
|
+
primary: step(recipe.accent, ladder.primary),
|
|
78
|
+
accent: step(recipe.accent, ladder.accent),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The accent seed stays as chosen; per mode it lands on the nearest lightness that reads on its ground.
|
|
83
|
+
const SETTLED: (keyof ThemeColors)[] = ["primary", "ring", "mutedForeground", "destructive"];
|
|
84
|
+
|
|
85
|
+
/** A derived theme reads well without anyone fixing it: these move to the nearest passing lightness. */
|
|
86
|
+
function settle(colors: ThemeColors): ThemeColors {
|
|
87
|
+
const out = { ...colors };
|
|
88
|
+
const failing = new Set(findUnreadable(out).map((issue) => issue.text));
|
|
89
|
+
for (const key of SETTLED) {
|
|
90
|
+
if (failing.has(key)) out[key] = fixReadable(out, key) ?? out[key];
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function derive(recipe: ThemeRecipe): ThemeColorsConfig {
|
|
96
|
+
const lightBase = baseFromSeeds(recipe, "light");
|
|
97
|
+
const light = resolveThemeColors(lightBase, "light");
|
|
98
|
+
const dark = recipe.darkLinked
|
|
99
|
+
? deriveDarkFromLight(lightBase)
|
|
100
|
+
: resolveThemeColors(baseFromSeeds(recipe, "dark"), "dark");
|
|
101
|
+
return { light: settle(light), dark: settle(dark) };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function resolveRecipe(recipe: ThemeRecipe): ThemeColorsConfig {
|
|
105
|
+
const derived = derive(recipe);
|
|
106
|
+
return {
|
|
107
|
+
light: { ...derived.light, ...recipe.set.light },
|
|
108
|
+
dark: { ...derived.dark, ...recipe.set.dark },
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function isDerived(recipe: ThemeRecipe, mode: Mode, key: keyof ThemeColors): boolean {
|
|
113
|
+
return recipe.set[mode][key] === undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function differing(from: ThemeColors, stored: ThemeColors): Partial<ThemeColors> {
|
|
117
|
+
const out: Partial<ThemeColors> = {};
|
|
118
|
+
for (const key of Object.keys(stored) as (keyof ThemeColors)[]) {
|
|
119
|
+
if (stored[key] !== from[key]) out[key] = stored[key];
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A flat theme (a preset, a legacy row) as a recipe that resolves back to the same 24 colors. */
|
|
125
|
+
export function seedsFromColors(
|
|
126
|
+
colors: ThemeColorsConfig,
|
|
127
|
+
radius: number,
|
|
128
|
+
background: BackgroundConfig,
|
|
129
|
+
): ThemeRecipe {
|
|
130
|
+
const seeds: ThemeRecipe = {
|
|
131
|
+
v: RECIPE_VERSION,
|
|
132
|
+
accent: colors.light.primary,
|
|
133
|
+
surface: colors.light.background,
|
|
134
|
+
radius,
|
|
135
|
+
background,
|
|
136
|
+
darkLinked: false,
|
|
137
|
+
set: { light: {}, dark: {} },
|
|
138
|
+
};
|
|
139
|
+
const derived = derive(seeds);
|
|
140
|
+
return {
|
|
141
|
+
...seeds,
|
|
142
|
+
set: {
|
|
143
|
+
light: differing(derived.light, colors.light),
|
|
144
|
+
dark: differing(derived.dark, colors.dark),
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|