@glasshome/ui 1.16.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.16.1",
3
+ "version": "1.18.0",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/glasshome/ui#readme",
@@ -47,11 +47,17 @@
47
47
  "./styles": "./src/styles/globals.css",
48
48
  "./package.json": "./package.json",
49
49
  "./styles/theme": "./src/styles/theme.css",
50
- "./scripts/*": "./scripts/*"
50
+ "./scripts/*": "./scripts/*",
51
+ "./backgrounds": {
52
+ "@glasshome/source": "./src/backgrounds/index.ts",
53
+ "types": "./dist/backgrounds/index.d.ts",
54
+ "import": "./dist/backgrounds/index.js"
55
+ }
51
56
  },
52
57
  "files": [
53
58
  "dist",
54
59
  "src/index.ts",
60
+ "src/backgrounds",
55
61
  "src/lib",
56
62
  "src/solid",
57
63
  "src/styles",
@@ -0,0 +1,103 @@
1
+ /* The wallpaper both apps render. Motion lives on an inner .house-pop group gated by
2
+ * html[data-motion], so the entrance plays inside the motion window and nothing animates after it.
3
+ * Written by hand once; keep the copy here and nowhere else. */
4
+ export const GEOMETRIC_HOUSES_SVG = `<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid slice">
5
+ <style>
6
+ .house-shape { opacity: 0.9; filter: blur(0.2px); transform: translate(var(--tx), var(--ty)) rotate(var(--rot)); }
7
+
8
+ @keyframes pop {
9
+ 0% { transform: scale(0.88); opacity: 0; }
10
+ 100% { transform: scale(1); opacity: 1; }
11
+ }
12
+
13
+ .h1 { --tx: 12px; --ty: 20px; --rot: 12deg; }
14
+ .h1 .house-pop { animation: pop 2.2s cubic-bezier(0.16, 1, 0.3, 1) 0.10s; }
15
+ .h2 { --tx: 85px; --ty: 25px; --rot: -15deg; }
16
+ .h2 .house-pop { animation: pop 2.2s cubic-bezier(0.16, 1, 0.3, 1) 0.40s; }
17
+ .h3 { --tx: 15px; --ty: 75px; --rot: -8deg; }
18
+ .h3 .house-pop { animation: pop 2.2s cubic-bezier(0.16, 1, 0.3, 1) 0.70s; }
19
+ .h4 { --tx: 70px; --ty: 10px; --rot: 20deg; }
20
+ .h4 .house-pop { animation: pop 2.2s cubic-bezier(0.16, 1, 0.3, 1) 1.00s; }
21
+ .h5 { --tx: 35px; --ty: 8px; --rot: -25deg; }
22
+ .h5 .house-pop { animation: pop 2.2s cubic-bezier(0.16, 1, 0.3, 1) 1.30s; }
23
+ .h6 { --tx: 55px; --ty: 55px; --rot: 18deg; }
24
+ .h6 .house-pop { animation: pop 2.2s cubic-bezier(0.16, 1, 0.3, 1) 1.60s; }
25
+
26
+ .house-shape .house-pop { animation-play-state: paused; }
27
+ [data-motion="live"] .house-shape .house-pop { animation-play-state: running; }
28
+ [data-motion="still"] .house-shape .house-pop { animation-play-state: paused; }
29
+
30
+ @media (prefers-reduced-motion: reduce) {
31
+ .house-pop { animation: none; }
32
+ }
33
+ </style>
34
+
35
+ <defs>
36
+ <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
37
+ <stop offset="0%" style="stop-color:var(--primary, oklch(0.48 0.2 215.221));stop-opacity:0.28" />
38
+ <stop offset="100%" style="stop-color:var(--accent, oklch(0.6 0.2 195));stop-opacity:0.06" />
39
+ </linearGradient>
40
+ <linearGradient id="grad2" x1="0%" y1="0%" x2="100%" y2="100%">
41
+ <stop offset="0%" style="stop-color:var(--accent, oklch(0.6 0.2 195));stop-opacity:0.30" />
42
+ <stop offset="100%" style="stop-color:var(--secondary, oklch(0.11 0.003 0));stop-opacity:0.08" />
43
+ </linearGradient>
44
+ <linearGradient id="grad3" x1="0%" y1="0%" x2="100%" y2="100%">
45
+ <stop offset="0%" style="stop-color:var(--primary, oklch(0.48 0.2 215.221));stop-opacity:0.35" />
46
+ <stop offset="100%" style="stop-color:var(--accent, oklch(0.6 0.2 195));stop-opacity:0.10" />
47
+ </linearGradient>
48
+ <linearGradient id="grad4" x1="0%" y1="0%" x2="100%" y2="100%">
49
+ <stop offset="0%" style="stop-color:var(--secondary, oklch(0.11 0.003 0));stop-opacity:0.22" />
50
+ <stop offset="100%" style="stop-color:var(--primary, oklch(0.48 0.2 215.221));stop-opacity:0.04" />
51
+ </linearGradient>
52
+ <linearGradient id="grad5" x1="0%" y1="0%" x2="100%" y2="100%">
53
+ <stop offset="0%" style="stop-color:var(--accent, oklch(0.6 0.2 195));stop-opacity:0.25" />
54
+ <stop offset="100%" style="stop-color:var(--primary, oklch(0.48 0.2 215.221));stop-opacity:0.05" />
55
+ </linearGradient>
56
+ <linearGradient id="grad6" x1="0%" y1="0%" x2="100%" y2="100%">
57
+ <stop offset="0%" style="stop-color:var(--primary, oklch(0.48 0.2 215.221));stop-opacity:0.32" />
58
+ <stop offset="100%" style="stop-color:var(--secondary, oklch(0.11 0.003 0));stop-opacity:0.07" />
59
+ </linearGradient>
60
+ <linearGradient id="overlay" x1="0%" y1="100%" x2="100%" y2="0%">
61
+ <stop offset="0%" style="stop-color:var(--primary, oklch(0.48 0.2 215.221));stop-opacity:0.20" />
62
+ <stop offset="50%" style="stop-color:transparent;stop-opacity:0" />
63
+ <stop offset="100%" style="stop-color:var(--accent, oklch(0.6 0.2 195));stop-opacity:0.40" />
64
+ </linearGradient>
65
+
66
+ <path id="house" d="M 50,4 C 52,4 53.5,4.7 54.5,6 L 86,38 C 88.8,40.2 90,43 90,46 L 90,90 C 90,93.8 87.8,96 84,96 L 16,96 C 12.2,96 10,93.8 10,90 L 10,46 C 10,43 11.2,40.2 14,38 L 45.5,6 C 46.5,4.7 48,4 50,4 Z"/>
67
+ </defs>
68
+
69
+ <rect width="100%" height="100%" fill="var(--background, oklch(0.12 0.005 0))"/>
70
+
71
+ <g class="house-shape h1">
72
+ <g class="house-pop">
73
+ <use href="#house" transform="translate(-15, -15) scale(0.31)" fill="url(#grad1)" stroke="var(--primary, oklch(0.48 0.2 215.221))" stroke-opacity="0.35" stroke-width="0.5"/>
74
+ </g>
75
+ </g>
76
+ <g class="house-shape h2">
77
+ <g class="house-pop">
78
+ <use href="#house" transform="translate(-13, -12) scale(0.26)" fill="url(#grad2)" stroke="var(--accent, oklch(0.6 0.2 195))" stroke-opacity="0.40" stroke-width="0.5"/>
79
+ </g>
80
+ </g>
81
+ <g class="house-shape h3">
82
+ <g class="house-pop">
83
+ <use href="#house" transform="translate(-8, -8) scale(0.16)" fill="url(#grad3)" stroke="var(--primary, oklch(0.48 0.2 215.221))" stroke-opacity="0.45" stroke-width="0.5"/>
84
+ </g>
85
+ </g>
86
+ <g class="house-shape h4">
87
+ <g class="house-pop">
88
+ <use href="#house" transform="translate(-5, -5) scale(0.10)" fill="url(#grad4)" stroke="var(--secondary, oklch(0.11 0.003 0))" stroke-opacity="0.28" stroke-width="0.5"/>
89
+ </g>
90
+ </g>
91
+ <g class="house-shape h5">
92
+ <g class="house-pop">
93
+ <use href="#house" transform="translate(-4, -4) scale(0.08)" fill="url(#grad5)" stroke="var(--accent, oklch(0.6 0.2 195))" stroke-opacity="0.32" stroke-width="0.5"/>
94
+ </g>
95
+ </g>
96
+ <g class="house-shape h6">
97
+ <g class="house-pop">
98
+ <use href="#house" transform="translate(-9.5, -9.5) scale(0.19)" fill="url(#grad6)" stroke="var(--primary, oklch(0.48 0.2 215.221))" stroke-opacity="0.38" stroke-width="0.5"/>
99
+ </g>
100
+ </g>
101
+
102
+ <rect width="100%" height="100%" fill="url(#overlay)" pointer-events="none"/>
103
+ </svg>`;
@@ -0,0 +1 @@
1
+ export { GEOMETRIC_HOUSES_SVG } from "./geometric-houses.js";
package/src/index.ts CHANGED
@@ -82,6 +82,7 @@ export {
82
82
  SETTLE_MOTION,
83
83
  STAGGER,
84
84
  } from "./lib/motion-classes.js";
85
+ export { MOTION_WINDOW_MS, startMotionWindow } from "./lib/motion-window.js";
85
86
  export {
86
87
  anchorToTriggerTop,
87
88
  FLOATING_PANEL,
@@ -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-full 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",
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
- /* Round ghost icon button (copy buttons, small icon actions). Size and text
49
- * color stay at the call site. */
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-full transition-glass duration-150 hover:bg-primary/10 active:scale-[0.97]";
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]";
@@ -0,0 +1,34 @@
1
+ export const MOTION_WINDOW_MS = 30_000;
2
+
3
+ /** Ambient motion runs for a window after load or a touch, then freezes; `html[data-motion="live"]`
4
+ * is the one signal, which theme.css turns into `--motion-ambient` and the wallpapers gate on.
5
+ * Returns the stop function. */
6
+ export function startMotionWindow(windowMs = MOTION_WINDOW_MS): () => void {
7
+ let timer: ReturnType<typeof setTimeout> | undefined;
8
+ const root = document.documentElement;
9
+
10
+ const freeze = () => {
11
+ clearTimeout(timer);
12
+ timer = undefined;
13
+ delete root.dataset.motion;
14
+ };
15
+ const wake = () => {
16
+ clearTimeout(timer);
17
+ timer = setTimeout(freeze, windowMs);
18
+ if (root.dataset.motion !== "live") root.dataset.motion = "live";
19
+ };
20
+ const onVisibility = () => {
21
+ if (document.visibilityState === "hidden") freeze();
22
+ else wake();
23
+ };
24
+
25
+ wake();
26
+ document.addEventListener("pointerdown", wake, { passive: true, capture: true });
27
+ document.addEventListener("visibilitychange", onVisibility);
28
+
29
+ return () => {
30
+ freeze();
31
+ document.removeEventListener("pointerdown", wake, { capture: true });
32
+ document.removeEventListener("visibilitychange", onVisibility);
33
+ };
34
+ }
@@ -1,10 +1,11 @@
1
- /* Small tinted things share the Badge material. A chip is a rounded-full glass
2
- * pill (Badge, CountPill, scope chips); an icon pill is the square-ish glass
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-full px-2.5 py-0.5 font-medium text-xs";
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)]";
@@ -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,
@@ -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-full px-2 py-0.5 font-black text-[10px] tracking-wide";
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
@@ -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 rounded-full",
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 rounded-full",
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",
@@ -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-full" />
297
- <Skeleton class="h-4 w-16 rounded-full" />
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-full transition-glass hover:bg-accent",
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
  )}
@@ -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 rounded-full text-destructive hover:text-destructive",
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
  )}
@@ -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={{ background: checked() ? "var(--thumb-face-on)" : "var(--thumb-face-off)" }}
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>
@@ -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
- --thumb-face-on: oklch(0.55 0.16 215);
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-face-on: oklch(0.78 0.1 215);
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);
@@ -5,5 +5,7 @@
5
5
 
6
6
  export * from "./hex.js";
7
7
  export * from "./presets.js";
8
+ export * from "./readability.js";
8
9
  export * from "./theme-colors.js";
9
10
  export { contrastRatio, parseThemeBlock } from "./theme-css.js";
11
+ export * from "./theme-recipe.js";
@@ -94,7 +94,7 @@ export const THEME_PRESETS: ThemePreset[] = [
94
94
  preset(
95
95
  "sunrise-studio",
96
96
  "Sunrise Studio",
97
- 1.2,
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.5,
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.6,
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.3,
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.45,
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("ride-the-wave", { url: "/backgrounds/ride-the-wave.svg" }),
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
+ }