@glasshome/ui 1.10.0 → 1.10.1
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 +5 -2
- package/scripts/check-pack.ts +32 -0
- package/src/index.ts +111 -0
- package/src/solid/accordion.tsx +60 -0
- package/src/solid/alert-dialog.tsx +148 -0
- package/src/solid/alert.tsx +118 -0
- package/src/solid/area-picker.tsx +225 -0
- package/src/solid/aspect-ratio.tsx +21 -0
- package/src/solid/avatar.tsx +41 -0
- package/src/solid/badge.tsx +74 -0
- package/src/solid/bottom-sheet/arbitration.ts +40 -0
- package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
- package/src/solid/bottom-sheet/constants.ts +8 -0
- package/src/solid/bottom-sheet/drag-controller.ts +221 -0
- package/src/solid/bottom-sheet/focus-trap.ts +56 -0
- package/src/solid/bottom-sheet/index.ts +14 -0
- package/src/solid/bottom-sheet/keyboard.ts +35 -0
- package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
- package/src/solid/bottom-sheet/state-machine.ts +40 -0
- package/src/solid/bottom-sheet/velocity.ts +42 -0
- package/src/solid/breadcrumb.tsx +105 -0
- package/src/solid/button-group.tsx +66 -0
- package/src/solid/button.tsx +20 -0
- package/src/solid/card.tsx +101 -0
- package/src/solid/carousel.tsx +302 -0
- package/src/solid/charts.tsx +338 -0
- package/src/solid/checkbox.tsx +70 -0
- package/src/solid/collapsible.tsx +38 -0
- package/src/solid/color-slider.tsx +98 -0
- package/src/solid/color-wheel.tsx +77 -0
- package/src/solid/context-menu.tsx +109 -0
- package/src/solid/copy-button.tsx +46 -0
- package/src/solid/count-pill.tsx +24 -0
- package/src/solid/data-table.tsx +248 -0
- package/src/solid/dialog-parts.tsx +242 -0
- package/src/solid/dialog.tsx +121 -0
- package/src/solid/dock.tsx +186 -0
- package/src/solid/dropdown-menu.tsx +130 -0
- package/src/solid/empty.tsx +99 -0
- package/src/solid/entity-data.ts +78 -0
- package/src/solid/entity-selector.tsx +697 -0
- package/src/solid/field.tsx +253 -0
- package/src/solid/form.tsx +231 -0
- package/src/solid/hero-action.tsx +117 -0
- package/src/solid/hover-card.tsx +26 -0
- package/src/solid/icon-picker.tsx +432 -0
- package/src/solid/icon.tsx +20 -0
- package/src/solid/image-picker.tsx +380 -0
- package/src/solid/index.ts +417 -0
- package/src/solid/input-group.tsx +170 -0
- package/src/solid/input-otp.tsx +175 -0
- package/src/solid/input.tsx +12 -0
- package/src/solid/item.tsx +179 -0
- package/src/solid/kbd.tsx +30 -0
- package/src/solid/label.tsx +19 -0
- package/src/solid/list-reorder.ts +148 -0
- package/src/solid/logo.tsx +79 -0
- package/src/solid/media-copy.ts +37 -0
- package/src/solid/media-store.ts +110 -0
- package/src/solid/media-tile.tsx +100 -0
- package/src/solid/menu-parts.tsx +248 -0
- package/src/solid/number-field.tsx +72 -0
- package/src/solid/option-card.tsx +218 -0
- package/src/solid/ornament.tsx +53 -0
- package/src/solid/overlay.tsx +16 -0
- package/src/solid/page-header.tsx +102 -0
- package/src/solid/pagination.tsx +111 -0
- package/src/solid/password-input.tsx +69 -0
- package/src/solid/picker-row.tsx +102 -0
- package/src/solid/picker-search.tsx +78 -0
- package/src/solid/popover.tsx +103 -0
- package/src/solid/progress.tsx +31 -0
- package/src/solid/radio-group.tsx +60 -0
- package/src/solid/resizable.tsx +149 -0
- package/src/solid/responsive-dialog.tsx +180 -0
- package/src/solid/schema-form.tsx +830 -0
- package/src/solid/scope-indicator.tsx +13 -0
- package/src/solid/scroll-area.tsx +27 -0
- package/src/solid/section-card.tsx +358 -0
- package/src/solid/select.tsx +139 -0
- package/src/solid/separator.tsx +35 -0
- package/src/solid/settings-row.tsx +159 -0
- package/src/solid/sheet.tsx +157 -0
- package/src/solid/skeleton.tsx +15 -0
- package/src/solid/slider.tsx +148 -0
- package/src/solid/sliding-indicator.tsx +294 -0
- package/src/solid/sonner.tsx +219 -0
- package/src/solid/spinner.tsx +20 -0
- package/src/solid/step-indicator.tsx +30 -0
- package/src/solid/switch.tsx +62 -0
- package/src/solid/table.tsx +98 -0
- package/src/solid/tabs.tsx +86 -0
- package/src/solid/textarea.tsx +16 -0
- package/src/solid/toggle-group.tsx +102 -0
- package/src/solid/toggle.tsx +57 -0
- package/src/solid/tooltip.tsx +38 -0
- package/src/solid/widget-card.tsx +117 -0
- package/src/solid/widget-identity.tsx +135 -0
- package/src/solid/widget-trust-badge.tsx +37 -0
- package/src/tokens/hex.ts +50 -0
- package/src/tokens/index.ts +8 -0
- package/src/tokens/presets.ts +192 -0
- package/src/tokens/theme-colors.ts +147 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Official / Community trust marker, single source for every widget surface
|
|
5
|
+
* (browser card, picker card, detail dialog) in both apps. Was drifted: hub used
|
|
6
|
+
* `lucide:badge-check`, dash used `mdi:check-decagram`; unified on the decagram,
|
|
7
|
+
* inlined as SVG so it needs no iconify collection registered by the consumer
|
|
8
|
+
* (hub has no `mdi` collection). The `title` is hover-only and ignored by screen
|
|
9
|
+
* readers, so the sr-only span carries the verbal label alongside the glyph.
|
|
10
|
+
*
|
|
11
|
+
* Both states are glyph-only: official is the decagram check (primary),
|
|
12
|
+
* community is the account-group people icon (muted). Community was a full
|
|
13
|
+
* `Badge` word before, but the label ate horizontal space next to the widget
|
|
14
|
+
* name, so it now matches the official marker's compact icon form.
|
|
15
|
+
*/
|
|
16
|
+
export function WidgetTrustBadge(props: { isOfficial: boolean }) {
|
|
17
|
+
return (
|
|
18
|
+
<Show
|
|
19
|
+
when={props.isOfficial}
|
|
20
|
+
fallback={
|
|
21
|
+
<span class="inline-flex items-center text-muted-foreground" title="Community widget">
|
|
22
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
23
|
+
<path d="M12 5.5A3.5 3.5 0 0 1 15.5 9a3.5 3.5 0 0 1-3.5 3.5A3.5 3.5 0 0 1 8.5 9 3.5 3.5 0 0 1 12 5.5M5 8c.56 0 1.08.15 1.53.42-.15 1.43.27 2.85 1.13 3.96C7.16 13.34 6.16 14 5 14a3 3 0 0 1-3-3 3 3 0 0 1 3-3m14 0a3 3 0 0 1 3 3 3 3 0 0 1-3 3c-1.16 0-2.16-.66-2.66-1.62a5.54 5.54 0 0 0 1.13-3.96c.45-.27.97-.42 1.53-.42M5.5 18.25c0-2.07 2.91-3.75 6.5-3.75s6.5 1.68 6.5 3.75V20h-13v-1.75M0 20v-1.5c0-1.39 1.89-2.56 4.45-2.9-.59.68-.95 1.62-.95 2.65V20H0m24 0h-3.5v-1.75c0-1.03-.36-1.97-.95-2.65 2.56.34 4.45 1.51 4.45 2.9V20Z" />
|
|
24
|
+
</svg>
|
|
25
|
+
<span class="sr-only">Community</span>
|
|
26
|
+
</span>
|
|
27
|
+
}
|
|
28
|
+
>
|
|
29
|
+
<span class="inline-flex items-center text-primary" title="Official GlassHome widget">
|
|
30
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
31
|
+
<path d="M23 12l-2.44-2.78.34-3.68-3.61-.82-1.89-3.18L12 3 8.6 1.54 6.71 4.72l-3.61.81.34 3.68L1 12l2.44 2.78-.34 3.69 3.61.82 1.89 3.18L12 21l3.4 1.46 1.89-3.18 3.61-.82-.34-3.68L23 12m-13 5l-4-4 1.41-1.41L10 14.17l6.59-6.59L18 9l-8 8z" />
|
|
32
|
+
</svg>
|
|
33
|
+
<span class="sr-only">Official</span>
|
|
34
|
+
</span>
|
|
35
|
+
</Show>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { parseOklch } from "./theme-colors.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* oklch() string -> sRGB hex, matching browser rendering: out-of-gamut colors
|
|
5
|
+
* are gamut-mapped by chroma reduction (CSS Color 4), not channel-clipped.
|
|
6
|
+
* For renderers that cannot parse oklch (librsvg, sharp SVG, canvas fills).
|
|
7
|
+
*/
|
|
8
|
+
export function oklchToHex(oklch: string): string {
|
|
9
|
+
const parsed = parseOklch(oklch);
|
|
10
|
+
if (!parsed) throw new Error(`oklchToHex: cannot parse "${oklch}"`);
|
|
11
|
+
let rgb = oklchToLinearSrgb(parsed.l, parsed.c, parsed.h);
|
|
12
|
+
if (!inGamut(rgb)) {
|
|
13
|
+
let lo = 0;
|
|
14
|
+
let hi = parsed.c;
|
|
15
|
+
for (let i = 0; i < 40; i++) {
|
|
16
|
+
const mid = (lo + hi) / 2;
|
|
17
|
+
if (inGamut(oklchToLinearSrgb(parsed.l, mid, parsed.h))) lo = mid;
|
|
18
|
+
else hi = mid;
|
|
19
|
+
}
|
|
20
|
+
rgb = oklchToLinearSrgb(parsed.l, lo, parsed.h);
|
|
21
|
+
}
|
|
22
|
+
return `#${rgb.map(linearToByte).map(toHexByte).join("")}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function oklchToLinearSrgb(L: number, C: number, hDeg: number): [number, number, number] {
|
|
26
|
+
const h = (hDeg * Math.PI) / 180;
|
|
27
|
+
const a = C * Math.cos(h);
|
|
28
|
+
const b = C * Math.sin(h);
|
|
29
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
30
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
31
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
32
|
+
return [
|
|
33
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
34
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
35
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function inGamut(rgb: [number, number, number]): boolean {
|
|
40
|
+
return rgb.every((x) => x >= -1e-6 && x <= 1 + 1e-6);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function linearToByte(x: number): number {
|
|
44
|
+
const v = x <= 0.0031308 ? 12.92 * x : 1.055 * Math.max(0, x) ** (1 / 2.4) - 0.055;
|
|
45
|
+
return Math.round(Math.min(1, Math.max(0, v)) * 255);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function toHexByte(n: number): string {
|
|
49
|
+
return n.toString(16).padStart(2, "0");
|
|
50
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BackgroundConfig,
|
|
3
|
+
deriveDarkFromLight,
|
|
4
|
+
resolveThemeColors,
|
|
5
|
+
type ThemeBaseColors,
|
|
6
|
+
type ThemeColorsConfig,
|
|
7
|
+
} from "./theme-colors.js";
|
|
8
|
+
|
|
9
|
+
export interface ThemePreset {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
radius: number;
|
|
13
|
+
colors: ThemeColorsConfig;
|
|
14
|
+
background: BackgroundConfig;
|
|
15
|
+
/** Curated two-stop gradient used for theme picker dots and marketing swatches. */
|
|
16
|
+
swatch: [string, string];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_THEME_ID = "midnight-glass";
|
|
20
|
+
|
|
21
|
+
/** Font stacks as shipped in styles/theme.css. */
|
|
22
|
+
export const FONT_SANS = '"Geist Variable", ui-sans-serif, system-ui, sans-serif';
|
|
23
|
+
export const FONT_MONO = '"GeistMono Variable", "JetBrains Mono", "Fira Code", Consolas, monospace';
|
|
24
|
+
|
|
25
|
+
function bg(id: string, options?: { url?: string; themed?: boolean }): BackgroundConfig {
|
|
26
|
+
const type = id === "default" ? "solid" : "static";
|
|
27
|
+
return { type, id, themed: options?.themed ?? true, url: options?.url };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function preset(
|
|
31
|
+
id: string,
|
|
32
|
+
name: string,
|
|
33
|
+
radius: number,
|
|
34
|
+
swatch: [string, string],
|
|
35
|
+
light: ThemeBaseColors,
|
|
36
|
+
background: BackgroundConfig,
|
|
37
|
+
dark?: ThemeBaseColors,
|
|
38
|
+
): ThemePreset {
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
name,
|
|
42
|
+
radius,
|
|
43
|
+
swatch,
|
|
44
|
+
colors: {
|
|
45
|
+
light: resolveThemeColors(light, "light"),
|
|
46
|
+
dark: dark ? resolveThemeColors(dark, "dark") : deriveDarkFromLight(light),
|
|
47
|
+
},
|
|
48
|
+
background,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const THEME_PRESETS: ThemePreset[] = [
|
|
53
|
+
// Midnight Glass — hand-tuned, canonical palette from styles/theme.css.
|
|
54
|
+
{
|
|
55
|
+
id: "midnight-glass",
|
|
56
|
+
name: "Midnight Glass",
|
|
57
|
+
radius: 1.4,
|
|
58
|
+
swatch: ["#1a6baa", "#22b8cf"],
|
|
59
|
+
colors: {
|
|
60
|
+
light: {
|
|
61
|
+
primary: "oklch(0.48 0.2 215.221)",
|
|
62
|
+
accent: "oklch(0.6 0.2 195)",
|
|
63
|
+
secondary: "oklch(0.96 0.01 250)",
|
|
64
|
+
border: "oklch(0.855 0.014 250)",
|
|
65
|
+
card: "oklch(0.96 0.005 250)",
|
|
66
|
+
background: "oklch(0.995 0.003 250)",
|
|
67
|
+
popover: "oklch(0.937 0.006 250)",
|
|
68
|
+
muted: "oklch(0.9702 0.008 250)",
|
|
69
|
+
mutedForeground: "oklch(0.34 0 0)",
|
|
70
|
+
input: "oklch(0.85 0.016 250)",
|
|
71
|
+
// The focus ring follows primary here, not the derived accent: the two
|
|
72
|
+
// are different hues, so an accent ring landed teal on blue controls.
|
|
73
|
+
// See the light block of styles/theme.css.
|
|
74
|
+
ring: "oklch(0.48 0.2 215.221)",
|
|
75
|
+
destructive: "oklch(0.54 0.19 23.0704)",
|
|
76
|
+
},
|
|
77
|
+
dark: {
|
|
78
|
+
primary: "oklch(0.48 0.2 215.221)",
|
|
79
|
+
accent: "oklch(0.6 0.2 195)",
|
|
80
|
+
secondary: "oklch(0.14 0.01 250)",
|
|
81
|
+
border: "oklch(0.26 0.012 250)",
|
|
82
|
+
card: "oklch(0.17 0.01 250)",
|
|
83
|
+
background: "oklch(0.12 0.01 250)",
|
|
84
|
+
popover: "oklch(0.11 0.005 250)",
|
|
85
|
+
muted: "oklch(0.22 0.02 250)",
|
|
86
|
+
mutedForeground: "oklch(0.81 0 0)",
|
|
87
|
+
input: "oklch(0.19 0.01 250)",
|
|
88
|
+
ring: "oklch(0.6 0.2 195)",
|
|
89
|
+
destructive: "oklch(0.7106 0.1661 22.2162)",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
background: bg("geometric-houses", { url: "/backgrounds/geometric-houses.svg" }),
|
|
93
|
+
},
|
|
94
|
+
preset(
|
|
95
|
+
"sunrise-studio",
|
|
96
|
+
"Sunrise Studio",
|
|
97
|
+
1.2,
|
|
98
|
+
["#e8590c", "#fab005"],
|
|
99
|
+
{
|
|
100
|
+
primary: "oklch(0.68 0.16 50)",
|
|
101
|
+
accent: "oklch(0.74 0.14 28)",
|
|
102
|
+
secondary: "oklch(0.92 0.04 82)",
|
|
103
|
+
border: "oklch(0.84 0.03 78)",
|
|
104
|
+
card: "oklch(0.96 0.02 85)",
|
|
105
|
+
background: "oklch(0.985 0.01 90)",
|
|
106
|
+
},
|
|
107
|
+
bg("diagonal-stripes"),
|
|
108
|
+
),
|
|
109
|
+
preset(
|
|
110
|
+
"forest-zen",
|
|
111
|
+
"Forest Zen",
|
|
112
|
+
1.5,
|
|
113
|
+
["#2f9e44", "#12b886"],
|
|
114
|
+
{
|
|
115
|
+
primary: "oklch(0.58 0.13 145)",
|
|
116
|
+
accent: "oklch(0.66 0.1 165)",
|
|
117
|
+
secondary: "oklch(0.9 0.03 150)",
|
|
118
|
+
border: "oklch(0.82 0.02 155)",
|
|
119
|
+
card: "oklch(0.95 0.01 150)",
|
|
120
|
+
background: "oklch(0.98 0.01 160)",
|
|
121
|
+
},
|
|
122
|
+
bg("trees"),
|
|
123
|
+
),
|
|
124
|
+
preset(
|
|
125
|
+
"lavender-dreams",
|
|
126
|
+
"Lavender Dreams",
|
|
127
|
+
1.6,
|
|
128
|
+
["#9c36b5", "#e64980"],
|
|
129
|
+
{
|
|
130
|
+
primary: "oklch(0.62 0.14 300)",
|
|
131
|
+
accent: "oklch(0.7 0.12 320)",
|
|
132
|
+
secondary: "oklch(0.93 0.03 290)",
|
|
133
|
+
border: "oklch(0.85 0.03 295)",
|
|
134
|
+
card: "oklch(0.97 0.02 300)",
|
|
135
|
+
background: "oklch(0.99 0.01 305)",
|
|
136
|
+
},
|
|
137
|
+
bg("streets", { url: "/backgrounds/streets.svg" }),
|
|
138
|
+
),
|
|
139
|
+
preset(
|
|
140
|
+
"coral-reef",
|
|
141
|
+
"Coral Reef",
|
|
142
|
+
1.3,
|
|
143
|
+
["#e03131", "#fd7e14"],
|
|
144
|
+
{
|
|
145
|
+
primary: "oklch(0.66 0.19 20)",
|
|
146
|
+
accent: "oklch(0.7 0.16 45)",
|
|
147
|
+
secondary: "oklch(0.91 0.04 35)",
|
|
148
|
+
border: "oklch(0.83 0.03 28)",
|
|
149
|
+
card: "oklch(0.96 0.02 25)",
|
|
150
|
+
background: "oklch(0.985 0.01 30)",
|
|
151
|
+
},
|
|
152
|
+
bg("beauty-over-cliff", { url: "/backgrounds/beauty-over-cliff.jpg", themed: false }),
|
|
153
|
+
),
|
|
154
|
+
preset(
|
|
155
|
+
"monochrome-pro",
|
|
156
|
+
"Monochrome Pro",
|
|
157
|
+
0,
|
|
158
|
+
["#868e96", "#495057"],
|
|
159
|
+
{
|
|
160
|
+
primary: "oklch(0.4 0.01 260)",
|
|
161
|
+
accent: "oklch(0.55 0.01 260)",
|
|
162
|
+
secondary: "oklch(0.94 0.005 260)",
|
|
163
|
+
border: "oklch(0.86 0.005 260)",
|
|
164
|
+
card: "oklch(0.98 0.003 260)",
|
|
165
|
+
background: "oklch(0.995 0.002 260)",
|
|
166
|
+
},
|
|
167
|
+
bg("grid"),
|
|
168
|
+
),
|
|
169
|
+
preset(
|
|
170
|
+
"ocean-breeze",
|
|
171
|
+
"Ocean Breeze",
|
|
172
|
+
1.45,
|
|
173
|
+
["#1098ad", "#3b5bdb"],
|
|
174
|
+
{
|
|
175
|
+
primary: "oklch(0.6 0.16 235)",
|
|
176
|
+
accent: "oklch(0.68 0.11 205)",
|
|
177
|
+
secondary: "oklch(0.92 0.03 225)",
|
|
178
|
+
border: "oklch(0.84 0.02 230)",
|
|
179
|
+
card: "oklch(0.97 0.01 230)",
|
|
180
|
+
background: "oklch(0.99 0.01 235)",
|
|
181
|
+
},
|
|
182
|
+
bg("ride-the-wave", { url: "/backgrounds/ride-the-wave.svg" }),
|
|
183
|
+
),
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
export function getAllPresets(): ThemePreset[] {
|
|
187
|
+
return THEME_PRESETS;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function getPreset(id: string): ThemePreset | undefined {
|
|
191
|
+
return THEME_PRESETS.find((p) => p.id === id);
|
|
192
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme color model + derivation. Framework-free: safe to import from servers,
|
|
3
|
+
* build scripts, and non-Solid renderers.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface ThemeColors {
|
|
7
|
+
primary: string;
|
|
8
|
+
accent: string;
|
|
9
|
+
secondary: string;
|
|
10
|
+
border: string;
|
|
11
|
+
card: string;
|
|
12
|
+
background: string;
|
|
13
|
+
muted: string;
|
|
14
|
+
mutedForeground: string;
|
|
15
|
+
input: string;
|
|
16
|
+
ring: string;
|
|
17
|
+
destructive: string;
|
|
18
|
+
popover: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ThemeColorsConfig {
|
|
22
|
+
light: ThemeColors;
|
|
23
|
+
dark: ThemeColors;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface BackgroundConfig {
|
|
27
|
+
type: "solid" | "static" | "custom";
|
|
28
|
+
id: string;
|
|
29
|
+
themed: boolean;
|
|
30
|
+
url?: string;
|
|
31
|
+
fit?: "cover" | "contain" | "tile";
|
|
32
|
+
overlay?: number;
|
|
33
|
+
blur?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The 6 base colors used as input for resolving a full ThemeColors */
|
|
37
|
+
export type ThemeBaseColors = Pick<
|
|
38
|
+
ThemeColors,
|
|
39
|
+
"primary" | "accent" | "secondary" | "border" | "card" | "background"
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
const OKLCH_REGEX =
|
|
43
|
+
/^oklch\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))\s*\)$/i;
|
|
44
|
+
|
|
45
|
+
export function clamp(value: number, min: number, max: number) {
|
|
46
|
+
return Math.min(Math.max(value, min), max);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function formatNumber(value: number) {
|
|
50
|
+
if (Number.isInteger(value)) return String(value);
|
|
51
|
+
return String(Number(value.toFixed(6)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function parseOklch(input: string): { l: number; c: number; h: number } | null {
|
|
55
|
+
const match = OKLCH_REGEX.exec(input.trim());
|
|
56
|
+
if (!match) return null;
|
|
57
|
+
return {
|
|
58
|
+
l: Number(match[1]),
|
|
59
|
+
c: Number(match[2]),
|
|
60
|
+
h: Number(match[3]),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function toOklch(l: number, c: number, h: number): string {
|
|
65
|
+
return `oklch(${formatNumber(l)} ${formatNumber(c)} ${formatNumber(h)})`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function adjustLightness(oklch: string, delta: number): string {
|
|
69
|
+
const parsed = parseOklch(oklch);
|
|
70
|
+
if (!parsed) return oklch;
|
|
71
|
+
const l = clamp(parsed.l + delta, 0, 1);
|
|
72
|
+
return toOklch(l, parsed.c, parsed.h);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function invertLightness(oklch: string, targetL: number): string {
|
|
76
|
+
const parsed = parseOklch(oklch);
|
|
77
|
+
if (!parsed) return oklch;
|
|
78
|
+
return toOklch(clamp(targetL, 0, 1), clamp(parsed.c * 0.8, 0, 0.4), parsed.h);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resolve the 6 base colors into a full ThemeColors.
|
|
83
|
+
* Used for presets and for backwards-compat with old DB data.
|
|
84
|
+
*/
|
|
85
|
+
export function resolveThemeColors(base: ThemeBaseColors, mode: "light" | "dark"): ThemeColors {
|
|
86
|
+
return {
|
|
87
|
+
...base,
|
|
88
|
+
popover: base.card,
|
|
89
|
+
muted:
|
|
90
|
+
mode === "light"
|
|
91
|
+
? adjustLightness(base.background, -0.015)
|
|
92
|
+
: adjustLightness(base.background, 0.1),
|
|
93
|
+
mutedForeground: mode === "light" ? "oklch(0.44 0 0)" : "oklch(0.71 0 0)",
|
|
94
|
+
input:
|
|
95
|
+
mode === "light" ? adjustLightness(base.border, 0.01) : adjustLightness(base.border, 0.04),
|
|
96
|
+
ring: base.accent,
|
|
97
|
+
/* Fixed per mode, not derived: destructive is read as text and as a filled
|
|
98
|
+
* surface with white on it, so both ends are contrast-tuned against the
|
|
99
|
+
* theme's ground rather than against whatever accent the preset picked. */
|
|
100
|
+
destructive: mode === "light" ? "oklch(0.54 0.19 23.0704)" : "oklch(0.7106 0.1661 22.2162)",
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function deriveDarkFromLight(light: ThemeBaseColors): ThemeColors {
|
|
105
|
+
const darkBase: ThemeBaseColors = {
|
|
106
|
+
primary: adjustLightness(light.primary, 0.15),
|
|
107
|
+
accent: adjustLightness(light.accent, 0.1),
|
|
108
|
+
secondary: invertLightness(light.secondary, 0.14),
|
|
109
|
+
border: invertLightness(light.border, 0.26),
|
|
110
|
+
card: invertLightness(light.card, 0.17),
|
|
111
|
+
background: invertLightness(light.background, 0.12),
|
|
112
|
+
};
|
|
113
|
+
return resolveThemeColors(darkBase, "dark");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const THEME_COLOR_KEYS: (keyof ThemeColors)[] = [
|
|
117
|
+
"primary",
|
|
118
|
+
"accent",
|
|
119
|
+
"secondary",
|
|
120
|
+
"border",
|
|
121
|
+
"card",
|
|
122
|
+
"background",
|
|
123
|
+
"muted",
|
|
124
|
+
"mutedForeground",
|
|
125
|
+
"input",
|
|
126
|
+
"ring",
|
|
127
|
+
"destructive",
|
|
128
|
+
"popover",
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Ensure a potentially partial colors object (from old DB data) has all fields.
|
|
133
|
+
* Existing values are preserved; missing ones are resolved from the base colors.
|
|
134
|
+
*/
|
|
135
|
+
export function ensureFullThemeColors(
|
|
136
|
+
partial: ThemeBaseColors & Partial<ThemeColors>,
|
|
137
|
+
mode: "light" | "dark",
|
|
138
|
+
): ThemeColors {
|
|
139
|
+
const resolved = resolveThemeColors(partial, mode);
|
|
140
|
+
const result = { ...resolved };
|
|
141
|
+
for (const key of THEME_COLOR_KEYS) {
|
|
142
|
+
if (partial[key]) {
|
|
143
|
+
result[key] = partial[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|