@glasshome/ui 1.17.0 → 1.19.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 +83 -2
- package/dist/index.js +2 -2
- package/dist/lib/button-variants.d.ts +4 -1
- package/dist/lib/card-classes.d.ts +4 -4
- package/dist/lib/motion-classes.d.ts +1 -0
- package/dist/lib/overlay-classes.d.ts +4 -2
- package/dist/lib/pill-classes.d.ts +1 -1
- package/dist/lib/spotlight-geometry.d.ts +22 -0
- package/dist/lib/thumb-classes.d.ts +1 -0
- package/dist/lib/tier-badge.d.ts +1 -1
- package/dist/solid/button.d.ts +8 -3
- package/dist/solid/dock.d.ts +9 -0
- package/dist/solid/docked-panel.d.ts +11 -0
- package/dist/solid/index.d.ts +6 -2
- package/dist/solid/index.js +4399 -4034
- package/dist/solid/option-card.d.ts +1 -1
- package/dist/solid/preview-tile.d.ts +33 -0
- package/dist/solid/spotlight.d.ts +14 -0
- package/dist/solid/swatch-picker.d.ts +12 -0
- package/dist/solid/tabs.d.ts +4 -1
- package/dist/solid/widget-identity.d.ts +2 -0
- package/dist/tokens/index.d.ts +3 -0
- package/dist/tokens/index.js +481 -67
- package/dist/tokens/material.d.ts +40 -0
- package/dist/tokens/presets.d.ts +3 -0
- package/dist/tokens/readability.d.ts +21 -0
- package/dist/tokens/theme-colors.d.ts +13 -3
- package/dist/tokens/theme-recipe.d.ts +33 -0
- package/dist/{utils-DMaksjvy.js → utils-CV6G6fr8.js} +343 -340
- package/package.json +2 -2
- package/src/lib/button-variants.ts +10 -7
- package/src/lib/card-classes.ts +4 -3
- package/src/lib/motion-classes.ts +5 -0
- package/src/lib/overlay-classes.ts +10 -2
- package/src/lib/pill-classes.ts +4 -3
- package/src/lib/spotlight-geometry.ts +90 -0
- package/src/lib/thumb-classes.ts +7 -0
- package/src/lib/tier-badge.ts +1 -1
- package/src/solid/button.tsx +17 -2
- package/src/solid/carousel.tsx +2 -2
- package/src/solid/data-table.tsx +2 -2
- package/src/solid/dock.tsx +67 -9
- package/src/solid/docked-panel.tsx +56 -0
- package/src/solid/hero-action.tsx +2 -2
- package/src/solid/icon-picker.tsx +1 -1
- package/src/solid/index.ts +11 -2
- package/src/solid/media-tile.tsx +1 -1
- package/src/solid/option-card.tsx +25 -31
- package/src/solid/preview-tile.tsx +79 -0
- package/src/solid/radio-group.tsx +7 -2
- package/src/solid/section-card.tsx +4 -2
- package/src/solid/sliding-indicator.tsx +13 -12
- package/src/solid/spotlight.tsx +179 -0
- package/src/solid/swatch-picker.tsx +47 -0
- package/src/solid/switch.tsx +5 -2
- package/src/solid/tabs.tsx +20 -4
- package/src/solid/toggle-group.tsx +1 -4
- package/src/solid/widget-identity.tsx +3 -1
- package/src/styles/globals.css +166 -14
- package/src/styles/theme.css +22 -3
- package/src/tokens/index.ts +3 -0
- package/src/tokens/material.ts +116 -0
- package/src/tokens/presets.ts +201 -62
- package/src/tokens/readability.ts +67 -0
- package/src/tokens/theme-colors.ts +15 -3
- package/src/tokens/theme-recipe.ts +161 -0
package/src/tokens/presets.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Material } from "./material.js";
|
|
1
2
|
import {
|
|
2
3
|
type BackgroundConfig,
|
|
3
4
|
deriveDarkFromLight,
|
|
@@ -14,6 +15,8 @@ export interface ThemePreset {
|
|
|
14
15
|
background: BackgroundConfig;
|
|
15
16
|
/** Curated two-stop gradient used for theme picker dots and marketing swatches. */
|
|
16
17
|
swatch: [string, string];
|
|
18
|
+
/** Absent: Frosted. */
|
|
19
|
+
material?: Material;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export const DEFAULT_THEME_ID = "midnight-glass";
|
|
@@ -22,9 +25,21 @@ export const DEFAULT_THEME_ID = "midnight-glass";
|
|
|
22
25
|
export const FONT_SANS = '"Geist Variable", ui-sans-serif, system-ui, sans-serif';
|
|
23
26
|
export const FONT_MONO = '"GeistMono Variable", "JetBrains Mono", "Fira Code", Consolas, monospace';
|
|
24
27
|
|
|
25
|
-
function bg(
|
|
28
|
+
function bg(
|
|
29
|
+
id: string,
|
|
30
|
+
options?: {
|
|
31
|
+
url?: string;
|
|
32
|
+
themed?: boolean;
|
|
33
|
+
night?: string;
|
|
34
|
+
overlay?: number;
|
|
35
|
+
blur?: number;
|
|
36
|
+
vignette?: number;
|
|
37
|
+
},
|
|
38
|
+
): BackgroundConfig {
|
|
26
39
|
const type = id === "default" ? "solid" : "static";
|
|
27
|
-
|
|
40
|
+
const dark = options?.night ? { type: "static" as const, id: options.night } : undefined;
|
|
41
|
+
const { url, overlay, blur, vignette } = options ?? {};
|
|
42
|
+
return { type, id, themed: options?.themed ?? true, url, dark, overlay, blur, vignette };
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
function preset(
|
|
@@ -35,12 +50,14 @@ function preset(
|
|
|
35
50
|
light: ThemeBaseColors,
|
|
36
51
|
background: BackgroundConfig,
|
|
37
52
|
dark?: ThemeBaseColors,
|
|
53
|
+
material?: Material,
|
|
38
54
|
): ThemePreset {
|
|
39
55
|
return {
|
|
40
56
|
id,
|
|
41
57
|
name,
|
|
42
58
|
radius,
|
|
43
59
|
swatch,
|
|
60
|
+
material,
|
|
44
61
|
colors: {
|
|
45
62
|
light: resolveThemeColors(light, "light"),
|
|
46
63
|
dark: dark ? resolveThemeColors(dark, "dark") : deriveDarkFromLight(light),
|
|
@@ -89,97 +106,219 @@ export const THEME_PRESETS: ThemePreset[] = [
|
|
|
89
106
|
destructive: "oklch(0.7106 0.1661 22.2162)",
|
|
90
107
|
},
|
|
91
108
|
},
|
|
92
|
-
background: bg("
|
|
109
|
+
background: bg("glass-house", {
|
|
110
|
+
url: "/backgrounds/glass-house.webp",
|
|
111
|
+
themed: false,
|
|
112
|
+
night: "glass-house-night",
|
|
113
|
+
vignette: 0.65,
|
|
114
|
+
}),
|
|
93
115
|
},
|
|
94
116
|
preset(
|
|
95
117
|
"sunrise-studio",
|
|
96
118
|
"Sunrise Studio",
|
|
97
|
-
1.
|
|
98
|
-
["#e8590c", "#
|
|
119
|
+
1.1,
|
|
120
|
+
["#e8590c", "#f7e3c6"],
|
|
121
|
+
{
|
|
122
|
+
primary: "oklch(0.56 0.13 48)",
|
|
123
|
+
accent: "oklch(0.54 0.11 35)",
|
|
124
|
+
secondary: "oklch(0.93 0.02 70)",
|
|
125
|
+
border: "oklch(0.84 0.025 65)",
|
|
126
|
+
card: "oklch(0.99 0.008 75)",
|
|
127
|
+
background: "oklch(0.945 0.02 72)",
|
|
128
|
+
},
|
|
129
|
+
bg("studio-geometric", {
|
|
130
|
+
url: "/backgrounds/studio-geometric.svg",
|
|
131
|
+
night: "studio-night",
|
|
132
|
+
}),
|
|
99
133
|
{
|
|
100
|
-
primary: "oklch(0.
|
|
101
|
-
accent: "oklch(0.
|
|
102
|
-
secondary: "oklch(0.
|
|
103
|
-
border: "oklch(0.
|
|
104
|
-
card: "oklch(0.
|
|
105
|
-
background: "oklch(0.
|
|
134
|
+
primary: "oklch(0.78 0.11 62)",
|
|
135
|
+
accent: "oklch(0.72 0.1 42)",
|
|
136
|
+
secondary: "oklch(0.3 0.025 55)",
|
|
137
|
+
border: "oklch(0.4 0.03 55)",
|
|
138
|
+
card: "oklch(0.27 0.025 55)",
|
|
139
|
+
background: "oklch(0.17 0.022 55)",
|
|
106
140
|
},
|
|
107
|
-
|
|
141
|
+
{ v: 1, preset: "paper" },
|
|
108
142
|
),
|
|
109
143
|
preset(
|
|
110
144
|
"forest-zen",
|
|
111
145
|
"Forest Zen",
|
|
112
|
-
1.
|
|
113
|
-
["#
|
|
146
|
+
1.6,
|
|
147
|
+
["#2b8a3e", "#a9c7b0"],
|
|
114
148
|
{
|
|
115
|
-
primary: "oklch(0.
|
|
116
|
-
accent: "oklch(0.
|
|
117
|
-
secondary: "oklch(0.
|
|
118
|
-
border: "oklch(0.
|
|
119
|
-
card: "oklch(0.
|
|
120
|
-
background: "oklch(0.
|
|
149
|
+
primary: "oklch(0.5 0.12 150)",
|
|
150
|
+
accent: "oklch(0.5 0.09 170)",
|
|
151
|
+
secondary: "oklch(0.92 0.025 150)",
|
|
152
|
+
border: "oklch(0.83 0.02 155)",
|
|
153
|
+
card: "oklch(0.99 0.008 150)",
|
|
154
|
+
background: "oklch(0.945 0.015 160)",
|
|
121
155
|
},
|
|
122
|
-
bg("
|
|
156
|
+
bg("forest-mist", {
|
|
157
|
+
url: "/backgrounds/forest-mist.webp",
|
|
158
|
+
themed: false,
|
|
159
|
+
night: "forest-mist-night",
|
|
160
|
+
vignette: 0.65,
|
|
161
|
+
}),
|
|
162
|
+
{
|
|
163
|
+
primary: "oklch(0.74 0.12 150)",
|
|
164
|
+
accent: "oklch(0.72 0.08 175)",
|
|
165
|
+
secondary: "oklch(0.24 0.025 160)",
|
|
166
|
+
border: "oklch(0.33 0.025 160)",
|
|
167
|
+
card: "oklch(0.25 0.02 160)",
|
|
168
|
+
background: "oklch(0.15 0.02 165)",
|
|
169
|
+
},
|
|
170
|
+
{ v: 1, preset: "frosted", dials: { clarity: 82 } },
|
|
123
171
|
),
|
|
124
172
|
preset(
|
|
125
173
|
"lavender-dreams",
|
|
126
174
|
"Lavender Dreams",
|
|
127
|
-
1.
|
|
128
|
-
["#
|
|
175
|
+
1.8,
|
|
176
|
+
["#845ef7", "#fff4e6"],
|
|
129
177
|
{
|
|
130
|
-
primary: "oklch(0.
|
|
131
|
-
accent: "oklch(0.
|
|
132
|
-
secondary: "oklch(0.93 0.
|
|
133
|
-
border: "oklch(0.85 0.
|
|
134
|
-
card: "oklch(0.
|
|
135
|
-
background: "oklch(0.
|
|
178
|
+
primary: "oklch(0.5 0.14 305)",
|
|
179
|
+
accent: "oklch(0.52 0.12 325)",
|
|
180
|
+
secondary: "oklch(0.93 0.025 300)",
|
|
181
|
+
border: "oklch(0.85 0.025 300)",
|
|
182
|
+
card: "oklch(0.975 0.012 90)",
|
|
183
|
+
background: "oklch(0.97 0.015 85)",
|
|
136
184
|
},
|
|
137
|
-
bg("
|
|
185
|
+
bg("lavender-ink"),
|
|
186
|
+
{
|
|
187
|
+
primary: "oklch(0.76 0.12 305)",
|
|
188
|
+
accent: "oklch(0.76 0.1 325)",
|
|
189
|
+
secondary: "oklch(0.26 0.04 310)",
|
|
190
|
+
border: "oklch(0.36 0.045 310)",
|
|
191
|
+
card: "oklch(0.23 0.045 312)",
|
|
192
|
+
background: "oklch(0.18 0.045 315)",
|
|
193
|
+
},
|
|
194
|
+
{ v: 1, preset: "paper", dials: { ink: 1 } },
|
|
138
195
|
),
|
|
139
196
|
preset(
|
|
140
197
|
"coral-reef",
|
|
141
|
-
"
|
|
142
|
-
|
|
143
|
-
["#
|
|
144
|
-
{
|
|
145
|
-
primary: "oklch(0.
|
|
146
|
-
accent: "oklch(0.
|
|
147
|
-
secondary: "oklch(0.
|
|
148
|
-
border: "oklch(0.
|
|
149
|
-
card: "oklch(0.
|
|
150
|
-
background: "oklch(0.
|
|
151
|
-
},
|
|
152
|
-
bg("
|
|
198
|
+
"Liquid Glass",
|
|
199
|
+
0.9,
|
|
200
|
+
["#0e1426", "#5fd4e8"],
|
|
201
|
+
{
|
|
202
|
+
primary: "oklch(0.5 0.11 225)",
|
|
203
|
+
accent: "oklch(0.52 0.16 345)",
|
|
204
|
+
secondary: "oklch(0.93 0.008 260)",
|
|
205
|
+
border: "oklch(0.85 0.012 260)",
|
|
206
|
+
card: "oklch(0.99 0.004 260)",
|
|
207
|
+
background: "oklch(0.94 0.008 260)",
|
|
208
|
+
},
|
|
209
|
+
bg("liquid-glass-day", {
|
|
210
|
+
url: "/backgrounds/liquid-glass-day.webp",
|
|
211
|
+
themed: false,
|
|
212
|
+
night: "liquid-glass",
|
|
213
|
+
}),
|
|
214
|
+
{
|
|
215
|
+
primary: "oklch(0.78 0.11 210)",
|
|
216
|
+
accent: "oklch(0.72 0.16 340)",
|
|
217
|
+
secondary: "oklch(0.25 0.03 265)",
|
|
218
|
+
border: "oklch(0.36 0.035 265)",
|
|
219
|
+
card: "oklch(0.24 0.03 265)",
|
|
220
|
+
background: "oklch(0.13 0.03 268)",
|
|
221
|
+
},
|
|
222
|
+
{ v: 1, preset: "frosted" },
|
|
153
223
|
),
|
|
154
224
|
preset(
|
|
155
225
|
"monochrome-pro",
|
|
156
226
|
"Monochrome Pro",
|
|
157
227
|
0,
|
|
158
|
-
["#
|
|
228
|
+
["#e9ecef", "#343a40"],
|
|
229
|
+
{
|
|
230
|
+
primary: "oklch(0.32 0.01 260)",
|
|
231
|
+
accent: "oklch(0.4 0.01 260)",
|
|
232
|
+
secondary: "oklch(0.93 0.004 260)",
|
|
233
|
+
border: "oklch(0.8 0.004 260)",
|
|
234
|
+
card: "oklch(0.99 0.002 260)",
|
|
235
|
+
background: "oklch(0.955 0.003 260)",
|
|
236
|
+
},
|
|
237
|
+
bg("monochrome-blocks", {
|
|
238
|
+
url: "/backgrounds/monochrome-blocks.svg",
|
|
239
|
+
night: "monochrome-night",
|
|
240
|
+
}),
|
|
159
241
|
{
|
|
160
|
-
primary: "oklch(0.
|
|
161
|
-
accent: "oklch(0.
|
|
162
|
-
secondary: "oklch(0.
|
|
163
|
-
border: "oklch(0.
|
|
164
|
-
card: "oklch(0.
|
|
165
|
-
background: "oklch(0.
|
|
242
|
+
primary: "oklch(0.9 0.005 260)",
|
|
243
|
+
accent: "oklch(0.82 0.005 260)",
|
|
244
|
+
secondary: "oklch(0.24 0.004 260)",
|
|
245
|
+
border: "oklch(0.36 0.004 260)",
|
|
246
|
+
card: "oklch(0.2 0.003 260)",
|
|
247
|
+
background: "oklch(0.14 0.003 260)",
|
|
166
248
|
},
|
|
167
|
-
|
|
249
|
+
{ v: 1, preset: "paper" },
|
|
168
250
|
),
|
|
169
251
|
preset(
|
|
170
252
|
"ocean-breeze",
|
|
171
|
-
"
|
|
172
|
-
1.
|
|
173
|
-
["#
|
|
174
|
-
{
|
|
175
|
-
primary: "oklch(0.
|
|
176
|
-
accent: "oklch(0.
|
|
177
|
-
secondary: "oklch(0.
|
|
178
|
-
border: "oklch(0.84 0.02
|
|
179
|
-
card: "oklch(0.
|
|
180
|
-
background: "oklch(0.
|
|
181
|
-
},
|
|
182
|
-
bg("
|
|
253
|
+
"Tide",
|
|
254
|
+
1.5,
|
|
255
|
+
["#2b4a8b", "#efe6d2"],
|
|
256
|
+
{
|
|
257
|
+
primary: "oklch(0.42 0.12 262)",
|
|
258
|
+
accent: "oklch(0.48 0.09 225)",
|
|
259
|
+
secondary: "oklch(0.93 0.015 85)",
|
|
260
|
+
border: "oklch(0.84 0.02 80)",
|
|
261
|
+
card: "oklch(0.975 0.012 85)",
|
|
262
|
+
background: "oklch(0.955 0.018 85)",
|
|
263
|
+
},
|
|
264
|
+
bg("tide-waves"),
|
|
265
|
+
{
|
|
266
|
+
primary: "oklch(0.78 0.09 235)",
|
|
267
|
+
accent: "oklch(0.76 0.08 205)",
|
|
268
|
+
secondary: "oklch(0.26 0.04 262)",
|
|
269
|
+
border: "oklch(0.36 0.045 262)",
|
|
270
|
+
card: "oklch(0.23 0.045 262)",
|
|
271
|
+
background: "oklch(0.18 0.05 262)",
|
|
272
|
+
},
|
|
273
|
+
{ v: 1, preset: "paper" },
|
|
274
|
+
),
|
|
275
|
+
preset(
|
|
276
|
+
"chalkboard",
|
|
277
|
+
"Chalkboard",
|
|
278
|
+
1.2,
|
|
279
|
+
["#2f4a40", "#f2e6a0"],
|
|
280
|
+
{
|
|
281
|
+
primary: "oklch(0.48 0.13 255)",
|
|
282
|
+
accent: "oklch(0.5 0.1 165)",
|
|
283
|
+
secondary: "oklch(0.9 0.012 165)",
|
|
284
|
+
border: "oklch(0.8 0.015 165)",
|
|
285
|
+
card: "oklch(0.965 0.006 165)",
|
|
286
|
+
background: "oklch(0.93 0.012 165)",
|
|
287
|
+
},
|
|
288
|
+
bg("chalkboard"),
|
|
289
|
+
{
|
|
290
|
+
primary: "oklch(0.88 0.12 95)",
|
|
291
|
+
accent: "oklch(0.8 0.09 220)",
|
|
292
|
+
secondary: "oklch(0.29 0.025 165)",
|
|
293
|
+
border: "oklch(0.43 0.02 165)",
|
|
294
|
+
card: "oklch(0.28 0.028 165)",
|
|
295
|
+
background: "oklch(0.22 0.03 165)",
|
|
296
|
+
},
|
|
297
|
+
{ v: 1, preset: "chalk" },
|
|
298
|
+
),
|
|
299
|
+
preset(
|
|
300
|
+
"retrowave",
|
|
301
|
+
"Retrowave",
|
|
302
|
+
1.2,
|
|
303
|
+
["#ff2bd6", "#35e0ff"],
|
|
304
|
+
{
|
|
305
|
+
primary: "oklch(0.58 0.24 345)",
|
|
306
|
+
accent: "oklch(0.6 0.14 215)",
|
|
307
|
+
secondary: "oklch(0.93 0.03 320)",
|
|
308
|
+
border: "oklch(0.84 0.04 320)",
|
|
309
|
+
card: "oklch(0.96 0.02 320)",
|
|
310
|
+
background: "oklch(0.98 0.015 320)",
|
|
311
|
+
},
|
|
312
|
+
bg("sunset-grid", { url: "/backgrounds/sunset-grid.svg" }),
|
|
313
|
+
{
|
|
314
|
+
primary: "oklch(0.68 0.27 345)",
|
|
315
|
+
accent: "oklch(0.8 0.14 205)",
|
|
316
|
+
secondary: "oklch(0.2 0.06 290)",
|
|
317
|
+
border: "oklch(0.34 0.1 300)",
|
|
318
|
+
card: "oklch(0.19 0.07 290)",
|
|
319
|
+
background: "oklch(0.13 0.06 285)",
|
|
320
|
+
},
|
|
321
|
+
{ v: 1, preset: "neon", dials: { glow: 14 } },
|
|
183
322
|
),
|
|
184
323
|
];
|
|
185
324
|
|
|
@@ -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
|
+
}
|
|
@@ -23,14 +23,26 @@ export interface ThemeColorsConfig {
|
|
|
23
23
|
dark: ThemeColors;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export interface
|
|
26
|
+
export interface BackgroundLayer {
|
|
27
27
|
type: "solid" | "static" | "custom";
|
|
28
28
|
id: string;
|
|
29
|
-
themed: boolean;
|
|
30
|
-
url?: string;
|
|
31
29
|
fit?: "cover" | "contain" | "tile";
|
|
30
|
+
/** 0 to 1: how far the wallpaper fades toward `--background`. */
|
|
32
31
|
overlay?: number;
|
|
32
|
+
/** 0 to 20, in px. */
|
|
33
33
|
blur?: number;
|
|
34
|
+
/** 0 to 1: how dark the corners fall. */
|
|
35
|
+
vignette?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The picture alone; visibility and softness belong to the theme, the same in both modes. */
|
|
39
|
+
export type BackgroundImage = Pick<BackgroundLayer, "type" | "id" | "fit">;
|
|
40
|
+
|
|
41
|
+
export interface BackgroundConfig extends BackgroundLayer {
|
|
42
|
+
themed: boolean;
|
|
43
|
+
url?: string;
|
|
44
|
+
/** Shown in dark mode instead of the top-level picture. */
|
|
45
|
+
dark?: BackgroundImage;
|
|
34
46
|
}
|
|
35
47
|
|
|
36
48
|
/** The 6 base colors used as input for resolving a full ThemeColors */
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Material } from "./material.js";
|
|
2
|
+
import { findUnreadable, fixReadable } from "./readability.js";
|
|
3
|
+
import {
|
|
4
|
+
type BackgroundConfig,
|
|
5
|
+
clamp,
|
|
6
|
+
deriveDarkFromLight,
|
|
7
|
+
parseOklch,
|
|
8
|
+
resolveThemeColors,
|
|
9
|
+
type ThemeBaseColors,
|
|
10
|
+
type ThemeColors,
|
|
11
|
+
type ThemeColorsConfig,
|
|
12
|
+
toOklch,
|
|
13
|
+
} from "./theme-colors.js";
|
|
14
|
+
|
|
15
|
+
export const RECIPE_VERSION = 1;
|
|
16
|
+
|
|
17
|
+
/** The studio's glass tint: `auto` follows the background picture; the rest are fixed surfaces. */
|
|
18
|
+
export type GlassTint = "auto" | "cool" | "neutral" | "warm";
|
|
19
|
+
|
|
20
|
+
export const TINT_SURFACES: Record<Exclude<GlassTint, "auto">, string> = {
|
|
21
|
+
cool: "oklch(0.965 0.02 240)",
|
|
22
|
+
neutral: "oklch(0.97 0 0)",
|
|
23
|
+
warm: "oklch(0.965 0.025 75)",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type Mode = "light" | "dark";
|
|
27
|
+
|
|
28
|
+
/** What was chosen, never what was computed: a stored theme re-derives on read. */
|
|
29
|
+
export interface ThemeRecipe {
|
|
30
|
+
/** Selects the derivation table, so a change to the math never moves a stored theme. */
|
|
31
|
+
v: typeof RECIPE_VERSION;
|
|
32
|
+
accent: string;
|
|
33
|
+
/** Tint and depth of the ground the glass sits on, as chosen for light. */
|
|
34
|
+
surface: string;
|
|
35
|
+
radius: number;
|
|
36
|
+
background: BackgroundConfig;
|
|
37
|
+
/** Dark is derived from the light result instead of from the seeds. */
|
|
38
|
+
darkLinked: boolean;
|
|
39
|
+
/** Hand-set colors only; everything absent is derived. */
|
|
40
|
+
set: { light: Partial<ThemeColors>; dark: Partial<ThemeColors> };
|
|
41
|
+
/** What the studio's tint choice was; `surface` stays the value the math reads. Absent is a hand-set surface. */
|
|
42
|
+
tint?: GlassTint;
|
|
43
|
+
/** The glass material; absent is Frosted, so no stored theme moved when this arrived. */
|
|
44
|
+
material?: Material;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Step {
|
|
48
|
+
l?: number;
|
|
49
|
+
lTo?: number;
|
|
50
|
+
c?: number;
|
|
51
|
+
cMax?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const LADDER_V1: Record<
|
|
55
|
+
Mode,
|
|
56
|
+
Record<"ground" | "card" | "border" | "secondary" | "primary" | "accent", Step>
|
|
57
|
+
> = {
|
|
58
|
+
light: {
|
|
59
|
+
ground: {},
|
|
60
|
+
card: { l: 0.015, c: 0.6 },
|
|
61
|
+
border: { l: -0.08, c: 1.2, cMax: 0.06 },
|
|
62
|
+
secondary: { l: -0.035 },
|
|
63
|
+
primary: {},
|
|
64
|
+
accent: { l: 0.05, c: 0.85 },
|
|
65
|
+
},
|
|
66
|
+
dark: {
|
|
67
|
+
ground: { lTo: 0.15, c: 2.6, cMax: 0.07 },
|
|
68
|
+
card: { lTo: 0.19, c: 2.6, cMax: 0.07 },
|
|
69
|
+
border: { lTo: 0.27, c: 2.6, cMax: 0.08 },
|
|
70
|
+
secondary: { lTo: 0.22, c: 2.6, cMax: 0.07 },
|
|
71
|
+
primary: { l: 0.08 },
|
|
72
|
+
accent: { l: 0.12, c: 0.85 },
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
function step(color: string, by: Step): string {
|
|
77
|
+
const parsed = parseOklch(color);
|
|
78
|
+
if (!parsed) return color;
|
|
79
|
+
const l = clamp(by.lTo ?? parsed.l + (by.l ?? 0), 0, 1);
|
|
80
|
+
const c = clamp(parsed.c * (by.c ?? 1), 0, by.cMax ?? 0.4);
|
|
81
|
+
return toOklch(l, c, parsed.h);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function baseFromSeeds(recipe: ThemeRecipe, mode: Mode): ThemeBaseColors {
|
|
85
|
+
const ladder = LADDER_V1[mode];
|
|
86
|
+
return {
|
|
87
|
+
background: step(recipe.surface, ladder.ground),
|
|
88
|
+
card: step(recipe.surface, ladder.card),
|
|
89
|
+
border: step(recipe.surface, ladder.border),
|
|
90
|
+
secondary: step(recipe.surface, ladder.secondary),
|
|
91
|
+
primary: step(recipe.accent, ladder.primary),
|
|
92
|
+
accent: step(recipe.accent, ladder.accent),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The accent seed stays as chosen; per mode it lands on the nearest lightness that reads on its ground.
|
|
97
|
+
const SETTLED: (keyof ThemeColors)[] = ["primary", "ring", "mutedForeground", "destructive"];
|
|
98
|
+
|
|
99
|
+
/** A derived theme reads well without anyone fixing it: these move to the nearest passing lightness. */
|
|
100
|
+
function settle(colors: ThemeColors): ThemeColors {
|
|
101
|
+
const out = { ...colors };
|
|
102
|
+
const failing = new Set(findUnreadable(out).map((issue) => issue.text));
|
|
103
|
+
for (const key of SETTLED) {
|
|
104
|
+
if (failing.has(key)) out[key] = fixReadable(out, key) ?? out[key];
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function derive(recipe: ThemeRecipe): ThemeColorsConfig {
|
|
110
|
+
const lightBase = baseFromSeeds(recipe, "light");
|
|
111
|
+
const light = resolveThemeColors(lightBase, "light");
|
|
112
|
+
const dark = recipe.darkLinked
|
|
113
|
+
? deriveDarkFromLight(lightBase)
|
|
114
|
+
: resolveThemeColors(baseFromSeeds(recipe, "dark"), "dark");
|
|
115
|
+
return { light: settle(light), dark: settle(dark) };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function resolveRecipe(recipe: ThemeRecipe): ThemeColorsConfig {
|
|
119
|
+
const derived = derive(recipe);
|
|
120
|
+
return {
|
|
121
|
+
light: { ...derived.light, ...recipe.set.light },
|
|
122
|
+
dark: { ...derived.dark, ...recipe.set.dark },
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function isDerived(recipe: ThemeRecipe, mode: Mode, key: keyof ThemeColors): boolean {
|
|
127
|
+
return recipe.set[mode][key] === undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function differing(from: ThemeColors, stored: ThemeColors): Partial<ThemeColors> {
|
|
131
|
+
const out: Partial<ThemeColors> = {};
|
|
132
|
+
for (const key of Object.keys(stored) as (keyof ThemeColors)[]) {
|
|
133
|
+
if (stored[key] !== from[key]) out[key] = stored[key];
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A flat theme (a preset, a legacy row) as a recipe that resolves back to the same 24 colors. */
|
|
139
|
+
export function seedsFromColors(
|
|
140
|
+
colors: ThemeColorsConfig,
|
|
141
|
+
radius: number,
|
|
142
|
+
background: BackgroundConfig,
|
|
143
|
+
): ThemeRecipe {
|
|
144
|
+
const seeds: ThemeRecipe = {
|
|
145
|
+
v: RECIPE_VERSION,
|
|
146
|
+
accent: colors.light.primary,
|
|
147
|
+
surface: colors.light.background,
|
|
148
|
+
radius,
|
|
149
|
+
background,
|
|
150
|
+
darkLinked: false,
|
|
151
|
+
set: { light: {}, dark: {} },
|
|
152
|
+
};
|
|
153
|
+
const derived = derive(seeds);
|
|
154
|
+
return {
|
|
155
|
+
...seeds,
|
|
156
|
+
set: {
|
|
157
|
+
light: differing(derived.light, colors.light),
|
|
158
|
+
dark: differing(derived.dark, colors.dark),
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|