@lmring/theme 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/index.d.ts +253 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +498 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
- package/src/theme.css +89 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @lmring/theme
|
|
2
|
+
|
|
3
|
+
Theme engine, design tokens, and CSS variable utilities for LMRing.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @lmring/theme
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { getPreset, paletteToCssVars } from "@lmring/theme";
|
|
15
|
+
import "@lmring/theme/css";
|
|
16
|
+
|
|
17
|
+
const cssVars = paletteToCssVars(getPreset("ocean-blue"));
|
|
18
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Core type definitions for @lmring/theme
|
|
4
|
+
*
|
|
5
|
+
* All color values use the OKLCH color space for perceptual uniformity.
|
|
6
|
+
*/
|
|
7
|
+
/** A color in the OKLCH color space. */
|
|
8
|
+
interface OklchColor {
|
|
9
|
+
/** Lightness: 0–1 */
|
|
10
|
+
l: number;
|
|
11
|
+
/** Chroma: 0–0.4 */
|
|
12
|
+
c: number;
|
|
13
|
+
/** Hue: 0–360 */
|
|
14
|
+
h: number;
|
|
15
|
+
}
|
|
16
|
+
/** Full set of semantic color slots used by the design system. */
|
|
17
|
+
interface SemanticPalette {
|
|
18
|
+
primary: OklchColor;
|
|
19
|
+
primaryForeground: OklchColor;
|
|
20
|
+
secondary: OklchColor;
|
|
21
|
+
secondaryForeground: OklchColor;
|
|
22
|
+
accent: OklchColor;
|
|
23
|
+
accentForeground: OklchColor;
|
|
24
|
+
muted: OklchColor;
|
|
25
|
+
mutedForeground: OklchColor;
|
|
26
|
+
destructive: OklchColor;
|
|
27
|
+
destructiveForeground: OklchColor;
|
|
28
|
+
background: OklchColor;
|
|
29
|
+
foreground: OklchColor;
|
|
30
|
+
card: OklchColor;
|
|
31
|
+
cardForeground: OklchColor;
|
|
32
|
+
border: OklchColor;
|
|
33
|
+
input: OklchColor;
|
|
34
|
+
ring: OklchColor;
|
|
35
|
+
}
|
|
36
|
+
/** Light and dark mode palettes derived from a seed color. */
|
|
37
|
+
interface ThemePalette {
|
|
38
|
+
light: SemanticPalette;
|
|
39
|
+
dark: SemanticPalette;
|
|
40
|
+
}
|
|
41
|
+
/** Serializable theme configuration stored in localStorage / server DB. */
|
|
42
|
+
interface PersistedThemeConfig {
|
|
43
|
+
mode: 'light' | 'dark' | 'system';
|
|
44
|
+
seedColor: OklchColor;
|
|
45
|
+
presetName: string | null;
|
|
46
|
+
}
|
|
47
|
+
/** A named preset theme with its OKLCH seed parameters. */
|
|
48
|
+
interface ThemePreset {
|
|
49
|
+
name: string;
|
|
50
|
+
hue: number;
|
|
51
|
+
chroma: number;
|
|
52
|
+
lightness: number;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/color-convert.d.ts
|
|
56
|
+
/**
|
|
57
|
+
* Convert a HEX color string to an OKLCH color object.
|
|
58
|
+
*
|
|
59
|
+
* @param hex - A valid 3 or 6 digit HEX string with `#` prefix (e.g. `#ff0000`, `#f00`)
|
|
60
|
+
* @returns The color in OKLCH space
|
|
61
|
+
* @throws If the HEX string is invalid
|
|
62
|
+
*/
|
|
63
|
+
declare function hexToOklch(hex: string): OklchColor;
|
|
64
|
+
/**
|
|
65
|
+
* Convert an OKLCH color object back to a 6-digit HEX string.
|
|
66
|
+
*
|
|
67
|
+
* @param color - An OKLCH color
|
|
68
|
+
* @returns A HEX string like `#rrggbb`
|
|
69
|
+
*/
|
|
70
|
+
declare function oklchToHex(color: OklchColor): string;
|
|
71
|
+
/**
|
|
72
|
+
* Format an OKLCH color as a CSS `oklch()` function string.
|
|
73
|
+
*
|
|
74
|
+
* @param color - An OKLCH color
|
|
75
|
+
* @returns A string like `oklch(0.5 0.2 270)`
|
|
76
|
+
*/
|
|
77
|
+
declare function oklchToCss(color: OklchColor): string;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/contrast.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Compute the WCAG 2.1 relative luminance of an OKLCH color.
|
|
82
|
+
*
|
|
83
|
+
* Converts the color to sRGB, linearizes each channel, then applies
|
|
84
|
+
* the standard luminance coefficients: 0.2126·R + 0.7152·G + 0.0722·B.
|
|
85
|
+
*
|
|
86
|
+
* @param color - An OKLCH color
|
|
87
|
+
* @returns Relative luminance in [0, 1]
|
|
88
|
+
*/
|
|
89
|
+
declare function getRelativeLuminance(color: OklchColor): number;
|
|
90
|
+
/**
|
|
91
|
+
* Compute the WCAG 2.1 contrast ratio between two OKLCH colors.
|
|
92
|
+
*
|
|
93
|
+
* The ratio is always ≥ 1, with 21:1 being the maximum (black on white).
|
|
94
|
+
*
|
|
95
|
+
* @param fg - Foreground color
|
|
96
|
+
* @param bg - Background color
|
|
97
|
+
* @returns Contrast ratio (e.g. 4.5 means 4.5:1)
|
|
98
|
+
*/
|
|
99
|
+
declare function getContrastRatio(fg: OklchColor, bg: OklchColor): number;
|
|
100
|
+
/**
|
|
101
|
+
* Check whether two OKLCH colors meet the WCAG 2.1 AA contrast requirement.
|
|
102
|
+
*
|
|
103
|
+
* - Normal text: contrast ratio ≥ 4.5:1
|
|
104
|
+
* - Large text (≥ 18pt or ≥ 14pt bold): contrast ratio ≥ 3.0:1
|
|
105
|
+
*
|
|
106
|
+
* @param fg - Foreground color
|
|
107
|
+
* @param bg - Background color
|
|
108
|
+
* @param isLargeText - Whether the text qualifies as "large" under WCAG
|
|
109
|
+
* @returns `true` if the pair meets WCAG AA
|
|
110
|
+
*/
|
|
111
|
+
declare function meetsWcagAA(fg: OklchColor, bg: OklchColor, isLargeText: boolean): boolean;
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/color-engine.d.ts
|
|
114
|
+
/**
|
|
115
|
+
* Generate a complete light + dark semantic palette from a seed OKLCH color.
|
|
116
|
+
*
|
|
117
|
+
* The seed color's hue drives the entire palette. Lightness and chroma
|
|
118
|
+
* are adjusted per semantic role according to the design system rules.
|
|
119
|
+
*
|
|
120
|
+
* @param seed - The user-chosen seed color in OKLCH space
|
|
121
|
+
* @returns A `ThemePalette` with `light` and `dark` semantic palettes
|
|
122
|
+
*/
|
|
123
|
+
declare function generatePalette(seed: OklchColor): ThemePalette;
|
|
124
|
+
/**
|
|
125
|
+
* Deep-merge partial overrides into a base palette.
|
|
126
|
+
*
|
|
127
|
+
* Overridden keys take the override value; all other keys are preserved
|
|
128
|
+
* from the base. Always returns a new object (no mutation).
|
|
129
|
+
*
|
|
130
|
+
* @param base - The base palette to start from
|
|
131
|
+
* @param overrides - Partial light/dark overrides to apply
|
|
132
|
+
* @returns A new `ThemePalette` with overrides merged in
|
|
133
|
+
*/
|
|
134
|
+
declare function mergePalette(base: ThemePalette, overrides: Partial<{
|
|
135
|
+
light: Partial<SemanticPalette>;
|
|
136
|
+
dark: Partial<SemanticPalette>;
|
|
137
|
+
}>): ThemePalette;
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/presets.d.ts
|
|
140
|
+
/**
|
|
141
|
+
* All available preset themes.
|
|
142
|
+
*
|
|
143
|
+
* Each preset uses a default chroma of 0.18 and lightness of 0.55,
|
|
144
|
+
* varying only in hue to produce distinct color families.
|
|
145
|
+
*/
|
|
146
|
+
declare const presets: ThemePreset[];
|
|
147
|
+
/**
|
|
148
|
+
* Look up a preset by name and return its generated palette.
|
|
149
|
+
*
|
|
150
|
+
* @param name - Kebab-case preset name (e.g. 'ocean-blue', 'violet')
|
|
151
|
+
* @returns The full light + dark `ThemePalette` for the preset
|
|
152
|
+
* @throws {Error} If no preset matches the given name
|
|
153
|
+
*/
|
|
154
|
+
declare function getPreset(name: string): ThemePalette;
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/tokens.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* Design tokens for @lmring/theme
|
|
159
|
+
*
|
|
160
|
+
* Static design tokens covering spacing, radius, shadow, typography,
|
|
161
|
+
* line-height (leading), easing, and duration values.
|
|
162
|
+
*
|
|
163
|
+
* Spacing uses a 4px base grid. All numeric spacing values (excluding 0)
|
|
164
|
+
* are positive multiples of 4.
|
|
165
|
+
*/
|
|
166
|
+
/** All design tokens grouped by category */
|
|
167
|
+
declare const tokens: {
|
|
168
|
+
readonly spacing: {
|
|
169
|
+
readonly 0: "0px";
|
|
170
|
+
readonly 1: "4px";
|
|
171
|
+
readonly 2: "8px";
|
|
172
|
+
readonly 3: "12px";
|
|
173
|
+
readonly 4: "16px";
|
|
174
|
+
readonly 5: "20px";
|
|
175
|
+
readonly 6: "24px";
|
|
176
|
+
readonly 8: "32px";
|
|
177
|
+
readonly 10: "40px";
|
|
178
|
+
readonly 12: "48px";
|
|
179
|
+
readonly 16: "64px";
|
|
180
|
+
};
|
|
181
|
+
readonly radius: {
|
|
182
|
+
readonly sm: "calc(var(--radius) - 4px)";
|
|
183
|
+
readonly md: "calc(var(--radius) - 2px)";
|
|
184
|
+
readonly lg: "var(--radius)";
|
|
185
|
+
readonly xl: "calc(var(--radius) + 4px)";
|
|
186
|
+
readonly '2xl': "calc(var(--radius) + 8px)";
|
|
187
|
+
readonly full: "9999px";
|
|
188
|
+
};
|
|
189
|
+
readonly shadow: {
|
|
190
|
+
readonly sm: "0 1px 2px oklch(0 0 0 / 3%), 0 1px 3px oklch(0 0 0 / 2%)";
|
|
191
|
+
readonly md: "0 2px 4px oklch(0 0 0 / 3%), 0 4px 8px oklch(0 0 0 / 3%), 0 8px 16px oklch(0 0 0 / 2%)";
|
|
192
|
+
readonly lg: "0 4px 8px oklch(0 0 0 / 3%), 0 8px 16px oklch(0 0 0 / 3%), 0 16px 32px oklch(0 0 0 / 4%), 0 32px 64px oklch(0 0 0 / 2%)";
|
|
193
|
+
};
|
|
194
|
+
readonly typography: {
|
|
195
|
+
readonly xs: "0.75rem";
|
|
196
|
+
readonly sm: "0.875rem";
|
|
197
|
+
readonly base: "1rem";
|
|
198
|
+
readonly lg: "1.125rem";
|
|
199
|
+
readonly xl: "1.25rem";
|
|
200
|
+
readonly '2xl': "1.5rem";
|
|
201
|
+
readonly '3xl': "1.875rem";
|
|
202
|
+
readonly '4xl': "2.25rem";
|
|
203
|
+
};
|
|
204
|
+
readonly leading: {
|
|
205
|
+
readonly tight: "1.25";
|
|
206
|
+
readonly snug: "1.375";
|
|
207
|
+
readonly normal: "1.5";
|
|
208
|
+
readonly relaxed: "1.625";
|
|
209
|
+
readonly loose: "1.75";
|
|
210
|
+
};
|
|
211
|
+
readonly easing: {
|
|
212
|
+
readonly spring: "cubic-bezier(0.34, 1.56, 0.64, 1)";
|
|
213
|
+
readonly smooth: "cubic-bezier(0.25, 0.1, 0.25, 1)";
|
|
214
|
+
readonly outExpo: "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
215
|
+
};
|
|
216
|
+
readonly duration: {
|
|
217
|
+
readonly fast: "150ms";
|
|
218
|
+
readonly normal: "200ms";
|
|
219
|
+
readonly slow: "300ms";
|
|
220
|
+
readonly slower: "500ms";
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/css-generator.d.ts
|
|
225
|
+
/**
|
|
226
|
+
* Convert a SemanticPalette into a Record of CSS custom properties.
|
|
227
|
+
*
|
|
228
|
+
* Each key in the palette is converted from camelCase to a `--kebab-case`
|
|
229
|
+
* CSS variable name, and each value is formatted as an `oklch(l c h)` string.
|
|
230
|
+
*
|
|
231
|
+
* @param palette - A semantic palette (light or dark)
|
|
232
|
+
* @returns A record mapping CSS variable names to OKLCH CSS values
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* paletteToCssVars(palette)
|
|
236
|
+
* // { '--primary': 'oklch(0.55 0.18 255)', '--primary-foreground': 'oklch(1 0 0)', ... }
|
|
237
|
+
*/
|
|
238
|
+
declare function paletteToCssVars(palette: SemanticPalette): Record<string, string>;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/persistence.d.ts
|
|
241
|
+
/** Serialize a theme config to a JSON string. */
|
|
242
|
+
declare function serialize(config: PersistedThemeConfig): string;
|
|
243
|
+
/**
|
|
244
|
+
* Deserialize a raw JSON string into a validated {@link PersistedThemeConfig}.
|
|
245
|
+
*
|
|
246
|
+
* Returns `null` when:
|
|
247
|
+
* - the string is not valid JSON
|
|
248
|
+
* - any field fails validation (mode enum, OKLCH ranges, presetName type)
|
|
249
|
+
*/
|
|
250
|
+
declare function deserialize(raw: string): PersistedThemeConfig | null;
|
|
251
|
+
//#endregion
|
|
252
|
+
export { type OklchColor, type PersistedThemeConfig, type SemanticPalette, type ThemePalette, type ThemePreset, deserialize, generatePalette, getContrastRatio, getPreset, getRelativeLuminance, hexToOklch, meetsWcagAA, mergePalette, oklchToCss, oklchToHex, paletteToCssVars, presets, serialize, tokens };
|
|
253
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/color-convert.ts","../src/contrast.ts","../src/color-engine.ts","../src/presets.ts","../src/tokens.ts","../src/css-generator.ts","../src/persistence.ts"],"mappings":";;AAOA;;;;;UAAiB,UAAA;EAMf;EAJA,CAAA;EAIC;EAFD,CAAA;EAM8B;EAJ9B,CAAA;AAAA;;UAIe,eAAA;EACf,OAAA,EAAS,UAAA;EACT,iBAAA,EAAmB,UAAA;EACnB,SAAA,EAAW,UAAA;EACX,mBAAA,EAAqB,UAAA;EACrB,MAAA,EAAQ,UAAA;EACR,gBAAA,EAAkB,UAAA;EAClB,KAAA,EAAO,UAAA;EACP,e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;;;;;;;;;;AL9Db;;;;;;;;;;iBMegB,gBAAA,CAAiB,OAAA,EAAS,eAAA,GAAkB,MAAA;;;;iBCf5C,SAAA,CAAU,MAAA,EAAQ,oBAAA;APAlC;;;;;;;AAAA,iBOWgB,WAAA,CAAY,GAAA,WAAc,oBAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
import { converter, formatHex } from "culori";
|
|
2
|
+
|
|
3
|
+
//#region src/color-convert.ts
|
|
4
|
+
/**
|
|
5
|
+
* Color space conversion utilities.
|
|
6
|
+
*
|
|
7
|
+
* Converts between HEX, OKLCH, and CSS string representations
|
|
8
|
+
* using the `culori` library for accurate color math.
|
|
9
|
+
*/
|
|
10
|
+
const toOklch = converter("oklch");
|
|
11
|
+
const HEX_REGEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
12
|
+
/**
|
|
13
|
+
* Validate that a string is a valid HEX color (#RGB or #RRGGBB).
|
|
14
|
+
* Throws if the format is invalid.
|
|
15
|
+
*/
|
|
16
|
+
function assertValidHex(hex) {
|
|
17
|
+
if (!HEX_REGEX.test(hex)) throw new Error(`Invalid HEX color: "${hex}". Expected format: #RGB or #RRGGBB.`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert a HEX color string to an OKLCH color object.
|
|
21
|
+
*
|
|
22
|
+
* @param hex - A valid 3 or 6 digit HEX string with `#` prefix (e.g. `#ff0000`, `#f00`)
|
|
23
|
+
* @returns The color in OKLCH space
|
|
24
|
+
* @throws If the HEX string is invalid
|
|
25
|
+
*/
|
|
26
|
+
function hexToOklch(hex) {
|
|
27
|
+
assertValidHex(hex);
|
|
28
|
+
const result = toOklch(hex);
|
|
29
|
+
if (!result) throw new Error(`Failed to convert HEX "${hex}" to OKLCH.`);
|
|
30
|
+
return {
|
|
31
|
+
l: result.l,
|
|
32
|
+
c: result.c ?? 0,
|
|
33
|
+
h: result.h ?? 0
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Convert an OKLCH color object back to a 6-digit HEX string.
|
|
38
|
+
*
|
|
39
|
+
* @param color - An OKLCH color
|
|
40
|
+
* @returns A HEX string like `#rrggbb`
|
|
41
|
+
*/
|
|
42
|
+
function oklchToHex(color) {
|
|
43
|
+
return formatHex({
|
|
44
|
+
mode: "oklch",
|
|
45
|
+
l: color.l,
|
|
46
|
+
c: color.c,
|
|
47
|
+
h: color.h
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Format an OKLCH color as a CSS `oklch()` function string.
|
|
52
|
+
*
|
|
53
|
+
* @param color - An OKLCH color
|
|
54
|
+
* @returns A string like `oklch(0.5 0.2 270)`
|
|
55
|
+
*/
|
|
56
|
+
function oklchToCss(color) {
|
|
57
|
+
return `oklch(${color.l} ${color.c} ${color.h})`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/contrast.ts
|
|
62
|
+
/**
|
|
63
|
+
* WCAG 2.1 contrast ratio utilities.
|
|
64
|
+
*
|
|
65
|
+
* Computes relative luminance and contrast ratios for OKLCH colors
|
|
66
|
+
* by converting through sRGB, following the WCAG 2.1 specification.
|
|
67
|
+
*/
|
|
68
|
+
const toRgb = converter("rgb");
|
|
69
|
+
/**
|
|
70
|
+
* Linearize a single sRGB channel value for luminance calculation.
|
|
71
|
+
*
|
|
72
|
+
* @param c - sRGB channel value in [0, 1]
|
|
73
|
+
* @returns Linear RGB value
|
|
74
|
+
*/
|
|
75
|
+
function linearize(c) {
|
|
76
|
+
return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Compute the WCAG 2.1 relative luminance of an OKLCH color.
|
|
80
|
+
*
|
|
81
|
+
* Converts the color to sRGB, linearizes each channel, then applies
|
|
82
|
+
* the standard luminance coefficients: 0.2126·R + 0.7152·G + 0.0722·B.
|
|
83
|
+
*
|
|
84
|
+
* @param color - An OKLCH color
|
|
85
|
+
* @returns Relative luminance in [0, 1]
|
|
86
|
+
*/
|
|
87
|
+
function getRelativeLuminance(color) {
|
|
88
|
+
const rgb = toRgb({
|
|
89
|
+
mode: "oklch",
|
|
90
|
+
l: color.l,
|
|
91
|
+
c: color.c,
|
|
92
|
+
h: color.h
|
|
93
|
+
});
|
|
94
|
+
if (!rgb) return 0;
|
|
95
|
+
const r = linearize(Math.max(0, Math.min(1, rgb.r)));
|
|
96
|
+
const g = linearize(Math.max(0, Math.min(1, rgb.g)));
|
|
97
|
+
const b = linearize(Math.max(0, Math.min(1, rgb.b)));
|
|
98
|
+
return .2126 * r + .7152 * g + .0722 * b;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Compute the WCAG 2.1 contrast ratio between two OKLCH colors.
|
|
102
|
+
*
|
|
103
|
+
* The ratio is always ≥ 1, with 21:1 being the maximum (black on white).
|
|
104
|
+
*
|
|
105
|
+
* @param fg - Foreground color
|
|
106
|
+
* @param bg - Background color
|
|
107
|
+
* @returns Contrast ratio (e.g. 4.5 means 4.5:1)
|
|
108
|
+
*/
|
|
109
|
+
function getContrastRatio(fg, bg) {
|
|
110
|
+
const l1 = getRelativeLuminance(fg);
|
|
111
|
+
const l2 = getRelativeLuminance(bg);
|
|
112
|
+
const lighter = Math.max(l1, l2);
|
|
113
|
+
const darker = Math.min(l1, l2);
|
|
114
|
+
return (lighter + .05) / (darker + .05);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check whether two OKLCH colors meet the WCAG 2.1 AA contrast requirement.
|
|
118
|
+
*
|
|
119
|
+
* - Normal text: contrast ratio ≥ 4.5:1
|
|
120
|
+
* - Large text (≥ 18pt or ≥ 14pt bold): contrast ratio ≥ 3.0:1
|
|
121
|
+
*
|
|
122
|
+
* @param fg - Foreground color
|
|
123
|
+
* @param bg - Background color
|
|
124
|
+
* @param isLargeText - Whether the text qualifies as "large" under WCAG
|
|
125
|
+
* @returns `true` if the pair meets WCAG AA
|
|
126
|
+
*/
|
|
127
|
+
function meetsWcagAA(fg, bg, isLargeText) {
|
|
128
|
+
const ratio = getContrastRatio(fg, bg);
|
|
129
|
+
return isLargeText ? ratio >= 3 : ratio >= 4.5;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/color-engine.ts
|
|
134
|
+
/**
|
|
135
|
+
* Clamp a number to the given range.
|
|
136
|
+
*/
|
|
137
|
+
function clamp(value, min, max) {
|
|
138
|
+
return Math.min(max, Math.max(min, value));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Normalize a hue value to [0, 360).
|
|
142
|
+
*/
|
|
143
|
+
function normalizeHue(h) {
|
|
144
|
+
return (h % 360 + 360) % 360;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create a valid OklchColor with clamped values.
|
|
148
|
+
*/
|
|
149
|
+
function oklch(l, c, h) {
|
|
150
|
+
return {
|
|
151
|
+
l: clamp(l, 0, 1),
|
|
152
|
+
c: clamp(c, 0, .4),
|
|
153
|
+
h: normalizeHue(h)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Derive the light-mode semantic palette from a seed color.
|
|
158
|
+
*/
|
|
159
|
+
function generateLightPalette(seed) {
|
|
160
|
+
const h = normalizeHue(seed.h);
|
|
161
|
+
const primary = oklch(.52, seed.c, h);
|
|
162
|
+
return {
|
|
163
|
+
primary,
|
|
164
|
+
primaryForeground: oklch(1, 0, h),
|
|
165
|
+
secondary: oklch(.96, .005, h),
|
|
166
|
+
secondaryForeground: oklch(.25, .015, h),
|
|
167
|
+
accent: oklch(.96, .01, h),
|
|
168
|
+
accentForeground: oklch(.25, .015, h),
|
|
169
|
+
muted: oklch(.96, .005, h),
|
|
170
|
+
mutedForeground: oklch(.58, .01, h),
|
|
171
|
+
destructive: oklch(.55, .22, 25),
|
|
172
|
+
destructiveForeground: oklch(1, 0, 25),
|
|
173
|
+
background: oklch(.98, .002, h),
|
|
174
|
+
foreground: oklch(.2, .015, h),
|
|
175
|
+
card: oklch(1, 0, h),
|
|
176
|
+
cardForeground: oklch(.2, .015, h),
|
|
177
|
+
border: oklch(.9, .005, h),
|
|
178
|
+
input: oklch(.95, .005, h),
|
|
179
|
+
ring: primary
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Derive the dark-mode semantic palette from a seed color.
|
|
184
|
+
*
|
|
185
|
+
* Uses a layered surface system with increasing lightness:
|
|
186
|
+
* Layer 0 (background): L=0.14
|
|
187
|
+
* Layer 1 (card): L=0.18
|
|
188
|
+
* Layer 2 (elevated): L=0.22 (mapped to `input`)
|
|
189
|
+
* Layer 3 (overlay): L=0.26 (mapped to `border` at L=0.28 per rules table)
|
|
190
|
+
*/
|
|
191
|
+
function generateDarkPalette(seed) {
|
|
192
|
+
const h = normalizeHue(seed.h);
|
|
193
|
+
const primary = oklch(.45, seed.c * .9, h);
|
|
194
|
+
return {
|
|
195
|
+
primary,
|
|
196
|
+
primaryForeground: oklch(.98, .005, h),
|
|
197
|
+
secondary: oklch(.25, .01, h),
|
|
198
|
+
secondaryForeground: oklch(.9, .005, h),
|
|
199
|
+
accent: oklch(.28, .015, h),
|
|
200
|
+
accentForeground: oklch(.9, .005, h),
|
|
201
|
+
muted: oklch(.25, .01, h),
|
|
202
|
+
mutedForeground: oklch(.72, .005, h),
|
|
203
|
+
destructive: oklch(.6, .24, 25),
|
|
204
|
+
destructiveForeground: oklch(.95, .01, 25),
|
|
205
|
+
background: oklch(.14, .01, h),
|
|
206
|
+
foreground: oklch(.95, .005, h),
|
|
207
|
+
card: oklch(.18, .01, h),
|
|
208
|
+
cardForeground: oklch(.95, .005, h),
|
|
209
|
+
border: oklch(.28, .01, h),
|
|
210
|
+
input: oklch(.22, .01, h),
|
|
211
|
+
ring: primary
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Generate a complete light + dark semantic palette from a seed OKLCH color.
|
|
216
|
+
*
|
|
217
|
+
* The seed color's hue drives the entire palette. Lightness and chroma
|
|
218
|
+
* are adjusted per semantic role according to the design system rules.
|
|
219
|
+
*
|
|
220
|
+
* @param seed - The user-chosen seed color in OKLCH space
|
|
221
|
+
* @returns A `ThemePalette` with `light` and `dark` semantic palettes
|
|
222
|
+
*/
|
|
223
|
+
function generatePalette(seed) {
|
|
224
|
+
return {
|
|
225
|
+
light: generateLightPalette(seed),
|
|
226
|
+
dark: generateDarkPalette(seed)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Deep-merge partial overrides into a base palette.
|
|
231
|
+
*
|
|
232
|
+
* Overridden keys take the override value; all other keys are preserved
|
|
233
|
+
* from the base. Always returns a new object (no mutation).
|
|
234
|
+
*
|
|
235
|
+
* @param base - The base palette to start from
|
|
236
|
+
* @param overrides - Partial light/dark overrides to apply
|
|
237
|
+
* @returns A new `ThemePalette` with overrides merged in
|
|
238
|
+
*/
|
|
239
|
+
function mergePalette(base, overrides) {
|
|
240
|
+
return {
|
|
241
|
+
light: {
|
|
242
|
+
...base.light,
|
|
243
|
+
...overrides.light
|
|
244
|
+
},
|
|
245
|
+
dark: {
|
|
246
|
+
...base.dark,
|
|
247
|
+
...overrides.dark
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/presets.ts
|
|
254
|
+
/**
|
|
255
|
+
* Preset theme definitions for @lmring/theme.
|
|
256
|
+
*
|
|
257
|
+
* Each preset is defined by its OKLCH hue angle. The color engine
|
|
258
|
+
* generates a full semantic palette from the seed parameters.
|
|
259
|
+
*/
|
|
260
|
+
/**
|
|
261
|
+
* All available preset themes.
|
|
262
|
+
*
|
|
263
|
+
* Each preset uses a default chroma of 0.18 and lightness of 0.55,
|
|
264
|
+
* varying only in hue to produce distinct color families.
|
|
265
|
+
*/
|
|
266
|
+
const presets = [
|
|
267
|
+
{
|
|
268
|
+
name: "ocean-blue",
|
|
269
|
+
hue: 255,
|
|
270
|
+
chroma: .18,
|
|
271
|
+
lightness: .55
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "violet",
|
|
275
|
+
hue: 280,
|
|
276
|
+
chroma: .18,
|
|
277
|
+
lightness: .55
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: "emerald",
|
|
281
|
+
hue: 155,
|
|
282
|
+
chroma: .18,
|
|
283
|
+
lightness: .55
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
name: "amber",
|
|
287
|
+
hue: 75,
|
|
288
|
+
chroma: .18,
|
|
289
|
+
lightness: .55
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
name: "rose",
|
|
293
|
+
hue: 350,
|
|
294
|
+
chroma: .18,
|
|
295
|
+
lightness: .55
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
name: "crimson",
|
|
299
|
+
hue: 25,
|
|
300
|
+
chroma: .18,
|
|
301
|
+
lightness: .55
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
name: "cyan",
|
|
305
|
+
hue: 195,
|
|
306
|
+
chroma: .18,
|
|
307
|
+
lightness: .55
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
name: "indigo",
|
|
311
|
+
hue: 265,
|
|
312
|
+
chroma: .18,
|
|
313
|
+
lightness: .55
|
|
314
|
+
}
|
|
315
|
+
];
|
|
316
|
+
/**
|
|
317
|
+
* Look up a preset by name and return its generated palette.
|
|
318
|
+
*
|
|
319
|
+
* @param name - Kebab-case preset name (e.g. 'ocean-blue', 'violet')
|
|
320
|
+
* @returns The full light + dark `ThemePalette` for the preset
|
|
321
|
+
* @throws {Error} If no preset matches the given name
|
|
322
|
+
*/
|
|
323
|
+
function getPreset(name) {
|
|
324
|
+
const preset = presets.find((p) => p.name === name);
|
|
325
|
+
if (!preset) throw new Error(`Unknown preset "${name}". Available: ${presets.map((p) => p.name).join(", ")}`);
|
|
326
|
+
return generatePalette({
|
|
327
|
+
h: preset.hue,
|
|
328
|
+
c: preset.chroma,
|
|
329
|
+
l: preset.lightness
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/tokens.ts
|
|
335
|
+
/**
|
|
336
|
+
* Design tokens for @lmring/theme
|
|
337
|
+
*
|
|
338
|
+
* Static design tokens covering spacing, radius, shadow, typography,
|
|
339
|
+
* line-height (leading), easing, and duration values.
|
|
340
|
+
*
|
|
341
|
+
* Spacing uses a 4px base grid. All numeric spacing values (excluding 0)
|
|
342
|
+
* are positive multiples of 4.
|
|
343
|
+
*/
|
|
344
|
+
/** Spacing scale based on 4px grid */
|
|
345
|
+
const spacing = {
|
|
346
|
+
0: "0px",
|
|
347
|
+
1: "4px",
|
|
348
|
+
2: "8px",
|
|
349
|
+
3: "12px",
|
|
350
|
+
4: "16px",
|
|
351
|
+
5: "20px",
|
|
352
|
+
6: "24px",
|
|
353
|
+
8: "32px",
|
|
354
|
+
10: "40px",
|
|
355
|
+
12: "48px",
|
|
356
|
+
16: "64px"
|
|
357
|
+
};
|
|
358
|
+
/** Border-radius scale with 10px (0.625rem) base */
|
|
359
|
+
const radius = {
|
|
360
|
+
sm: "calc(var(--radius) - 4px)",
|
|
361
|
+
md: "calc(var(--radius) - 2px)",
|
|
362
|
+
lg: "var(--radius)",
|
|
363
|
+
xl: "calc(var(--radius) + 4px)",
|
|
364
|
+
"2xl": "calc(var(--radius) + 8px)",
|
|
365
|
+
full: "9999px"
|
|
366
|
+
};
|
|
367
|
+
/** Multi-layer composite shadow system (3 levels) */
|
|
368
|
+
const shadow = {
|
|
369
|
+
sm: "0 1px 2px oklch(0 0 0 / 3%), 0 1px 3px oklch(0 0 0 / 2%)",
|
|
370
|
+
md: "0 2px 4px oklch(0 0 0 / 3%), 0 4px 8px oklch(0 0 0 / 3%), 0 8px 16px oklch(0 0 0 / 2%)",
|
|
371
|
+
lg: "0 4px 8px oklch(0 0 0 / 3%), 0 8px 16px oklch(0 0 0 / 3%), 0 16px 32px oklch(0 0 0 / 4%), 0 32px 64px oklch(0 0 0 / 2%)"
|
|
372
|
+
};
|
|
373
|
+
/** Typography font-size scale (rem values) */
|
|
374
|
+
const typography = {
|
|
375
|
+
xs: "0.75rem",
|
|
376
|
+
sm: "0.875rem",
|
|
377
|
+
base: "1rem",
|
|
378
|
+
lg: "1.125rem",
|
|
379
|
+
xl: "1.25rem",
|
|
380
|
+
"2xl": "1.5rem",
|
|
381
|
+
"3xl": "1.875rem",
|
|
382
|
+
"4xl": "2.25rem"
|
|
383
|
+
};
|
|
384
|
+
/** Line-height scale */
|
|
385
|
+
const leading = {
|
|
386
|
+
tight: "1.25",
|
|
387
|
+
snug: "1.375",
|
|
388
|
+
normal: "1.5",
|
|
389
|
+
relaxed: "1.625",
|
|
390
|
+
loose: "1.75"
|
|
391
|
+
};
|
|
392
|
+
/** CSS easing functions */
|
|
393
|
+
const easing = {
|
|
394
|
+
spring: "cubic-bezier(0.34, 1.56, 0.64, 1)",
|
|
395
|
+
smooth: "cubic-bezier(0.25, 0.1, 0.25, 1)",
|
|
396
|
+
outExpo: "cubic-bezier(0.16, 1, 0.3, 1)"
|
|
397
|
+
};
|
|
398
|
+
/** Animation duration values */
|
|
399
|
+
const duration = {
|
|
400
|
+
fast: "150ms",
|
|
401
|
+
normal: "200ms",
|
|
402
|
+
slow: "300ms",
|
|
403
|
+
slower: "500ms"
|
|
404
|
+
};
|
|
405
|
+
/** All design tokens grouped by category */
|
|
406
|
+
const tokens = {
|
|
407
|
+
spacing,
|
|
408
|
+
radius,
|
|
409
|
+
shadow,
|
|
410
|
+
typography,
|
|
411
|
+
leading,
|
|
412
|
+
easing,
|
|
413
|
+
duration
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/css-generator.ts
|
|
418
|
+
/**
|
|
419
|
+
* CSS variable generator.
|
|
420
|
+
*
|
|
421
|
+
* Converts a SemanticPalette into CSS custom property key-value pairs
|
|
422
|
+
* for injection into the document root element.
|
|
423
|
+
*/
|
|
424
|
+
/**
|
|
425
|
+
* Convert a camelCase string to kebab-case.
|
|
426
|
+
*
|
|
427
|
+
* @example camelToKebab('primaryForeground') // 'primary-foreground'
|
|
428
|
+
*/
|
|
429
|
+
function camelToKebab(str) {
|
|
430
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Convert a SemanticPalette into a Record of CSS custom properties.
|
|
434
|
+
*
|
|
435
|
+
* Each key in the palette is converted from camelCase to a `--kebab-case`
|
|
436
|
+
* CSS variable name, and each value is formatted as an `oklch(l c h)` string.
|
|
437
|
+
*
|
|
438
|
+
* @param palette - A semantic palette (light or dark)
|
|
439
|
+
* @returns A record mapping CSS variable names to OKLCH CSS values
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* paletteToCssVars(palette)
|
|
443
|
+
* // { '--primary': 'oklch(0.55 0.18 255)', '--primary-foreground': 'oklch(1 0 0)', ... }
|
|
444
|
+
*/
|
|
445
|
+
function paletteToCssVars(palette) {
|
|
446
|
+
const vars = {};
|
|
447
|
+
for (const [key, color] of Object.entries(palette)) {
|
|
448
|
+
const cssVarName = `--${camelToKebab(key)}`;
|
|
449
|
+
vars[cssVarName] = oklchToCss(color);
|
|
450
|
+
}
|
|
451
|
+
return vars;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region src/persistence.ts
|
|
456
|
+
const VALID_MODES = new Set([
|
|
457
|
+
"light",
|
|
458
|
+
"dark",
|
|
459
|
+
"system"
|
|
460
|
+
]);
|
|
461
|
+
/** Serialize a theme config to a JSON string. */
|
|
462
|
+
function serialize(config) {
|
|
463
|
+
return JSON.stringify(config);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Deserialize a raw JSON string into a validated {@link PersistedThemeConfig}.
|
|
467
|
+
*
|
|
468
|
+
* Returns `null` when:
|
|
469
|
+
* - the string is not valid JSON
|
|
470
|
+
* - any field fails validation (mode enum, OKLCH ranges, presetName type)
|
|
471
|
+
*/
|
|
472
|
+
function deserialize(raw) {
|
|
473
|
+
let parsed;
|
|
474
|
+
try {
|
|
475
|
+
parsed = JSON.parse(raw);
|
|
476
|
+
} catch {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
|
|
480
|
+
const obj = parsed;
|
|
481
|
+
if (!VALID_MODES.has(obj.mode)) return null;
|
|
482
|
+
if (!isValidOklchColor(obj.seedColor)) return null;
|
|
483
|
+
if (obj.presetName !== null && typeof obj.presetName !== "string") return null;
|
|
484
|
+
return {
|
|
485
|
+
mode: obj.mode,
|
|
486
|
+
seedColor: obj.seedColor,
|
|
487
|
+
presetName: obj.presetName
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function isValidOklchColor(value) {
|
|
491
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
492
|
+
const color = value;
|
|
493
|
+
return typeof color.l === "number" && typeof color.c === "number" && typeof color.h === "number" && color.l >= 0 && color.l <= 1 && color.c >= 0 && color.c <= .4 && color.h >= 0 && color.h <= 360;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
//#endregion
|
|
497
|
+
export { deserialize, generatePalette, getContrastRatio, getPreset, getRelativeLuminance, hexToOklch, meetsWcagAA, mergePalette, oklchToCss, oklchToHex, paletteToCssVars, presets, serialize, tokens };
|
|
498
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/color-convert.ts","../src/contrast.ts","../src/color-engine.ts","../src/presets.ts","../src/tokens.ts","../src/css-generator.ts","../src/persistence.ts"],"sourcesContent":["/**\r\n * Color space conversion utilities.\r\n *\r\n * Converts between HEX, OKLCH, and CSS string representations\r\n * using the `culori` library for accurate color math.\r\n */\r\n\r\nimport { converter, formatHex } from 'culori';\r\nimport type { OklchColor } from './types';\r\n\r\nconst toOklch = converter('oklch');\r\n\r\nconst HEX_REGEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;\r\n\r\n/**\r\n * Validate that a string is a valid HEX color (#RGB or #RRGGBB).\r\n * Throws if the format is invalid.\r\n */\r\nfunction assertValidHex(hex: string): void {\r\n if (!HEX_REGEX.test(hex)) {\r\n throw new Error(\r\n `Invalid HEX color: \"${hex}\". Expected format: #RGB or #RRGGBB.`,\r\n );\r\n }\r\n}\r\n\r\n/**\r\n * Convert a HEX color string to an OKLCH color object.\r\n *\r\n * @param hex - A valid 3 or 6 digit HEX string with `#` prefix (e.g. `#ff0000`, `#f00`)\r\n * @returns The color in OKLCH space\r\n * @throws If the HEX string is invalid\r\n */\r\nexport function hexToOklch(hex: string): OklchColor {\r\n assertValidHex(hex);\r\n const result = toOklch(hex);\r\n if (!result) {\r\n throw new Error(`Failed to convert HEX \"${hex}\" to OKLCH.`);\r\n }\r\n return {\r\n l: result.l,\r\n c: result.c ?? 0,\r\n h: result.h ?? 0,\r\n };\r\n}\r\n\r\n/**\r\n * Convert an OKLCH color object back to a 6-digit HEX string.\r\n *\r\n * @param color - An OKLCH color\r\n * @returns A HEX string like `#rrggbb`\r\n */\r\nexport function oklchToHex(color: OklchColor): string {\r\n const hex = formatHex({ mode: 'oklch', l: color.l, c: color.c, h: color.h });\r\n return hex;\r\n}\r\n\r\n/**\r\n * Format an OKLCH color as a CSS `oklch()` function string.\r\n *\r\n * @param color - An OKLCH color\r\n * @returns A string like `oklch(0.5 0.2 270)`\r\n */\r\nexport function oklchToCss(color: OklchColor): string {\r\n return `oklch(${color.l} ${color.c} ${color.h})`;\r\n}\r\n","/**\r\n * WCAG 2.1 contrast ratio utilities.\r\n *\r\n * Computes relative luminance and contrast ratios for OKLCH colors\r\n * by converting through sRGB, following the WCAG 2.1 specification.\r\n */\r\n\r\nimport { converter } from 'culori';\r\nimport type { OklchColor } from './types';\r\n\r\nconst toRgb = converter('rgb');\r\n\r\n/**\r\n * Linearize a single sRGB channel value for luminance calculation.\r\n *\r\n * @param c - sRGB channel value in [0, 1]\r\n * @returns Linear RGB value\r\n */\r\nfunction linearize(c: number): number {\r\n return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\r\n}\r\n\r\n/**\r\n * Compute the WCAG 2.1 relative luminance of an OKLCH color.\r\n *\r\n * Converts the color to sRGB, linearizes each channel, then applies\r\n * the standard luminance coefficients: 0.2126·R + 0.7152·G + 0.0722·B.\r\n *\r\n * @param color - An OKLCH color\r\n * @returns Relative luminance in [0, 1]\r\n */\r\nexport function getRelativeLuminance(color: OklchColor): number {\r\n const rgb = toRgb({ mode: 'oklch', l: color.l, c: color.c, h: color.h });\r\n if (!rgb) {\r\n return 0;\r\n }\r\n\r\n const r = linearize(Math.max(0, Math.min(1, rgb.r)));\r\n const g = linearize(Math.max(0, Math.min(1, rgb.g)));\r\n const b = linearize(Math.max(0, Math.min(1, rgb.b)));\r\n\r\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\r\n}\r\n\r\n/**\r\n * Compute the WCAG 2.1 contrast ratio between two OKLCH colors.\r\n *\r\n * The ratio is always ≥ 1, with 21:1 being the maximum (black on white).\r\n *\r\n * @param fg - Foreground color\r\n * @param bg - Background color\r\n * @returns Contrast ratio (e.g. 4.5 means 4.5:1)\r\n */\r\nexport function getContrastRatio(fg: OklchColor, bg: OklchColor): number {\r\n const l1 = getRelativeLuminance(fg);\r\n const l2 = getRelativeLuminance(bg);\r\n const lighter = Math.max(l1, l2);\r\n const darker = Math.min(l1, l2);\r\n return (lighter + 0.05) / (darker + 0.05);\r\n}\r\n\r\n/**\r\n * Check whether two OKLCH colors meet the WCAG 2.1 AA contrast requirement.\r\n *\r\n * - Normal text: contrast ratio ≥ 4.5:1\r\n * - Large text (≥ 18pt or ≥ 14pt bold): contrast ratio ≥ 3.0:1\r\n *\r\n * @param fg - Foreground color\r\n * @param bg - Background color\r\n * @param isLargeText - Whether the text qualifies as \"large\" under WCAG\r\n * @returns `true` if the pair meets WCAG AA\r\n */\r\nexport function meetsWcagAA(\r\n fg: OklchColor,\r\n bg: OklchColor,\r\n isLargeText: boolean,\r\n): boolean {\r\n const ratio = getContrastRatio(fg, bg);\r\n return isLargeText ? ratio >= 3.0 : ratio >= 4.5;\r\n}\r\n","/**\r\n * OKLCH palette generation engine.\r\n *\r\n * Given a seed color in OKLCH space, generates a complete semantic palette\r\n * for both light and dark modes following the design system's generation rules.\r\n */\r\n\r\nimport type { OklchColor, SemanticPalette, ThemePalette } from './types';\r\n\r\n/**\r\n * Clamp a number to the given range.\r\n */\r\nfunction clamp(value: number, min: number, max: number): number {\r\n return Math.min(max, Math.max(min, value));\r\n}\r\n\r\n/**\r\n * Normalize a hue value to [0, 360).\r\n */\r\nfunction normalizeHue(h: number): number {\r\n return ((h % 360) + 360) % 360;\r\n}\r\n\r\n/**\r\n * Create a valid OklchColor with clamped values.\r\n */\r\nfunction oklch(l: number, c: number, h: number): OklchColor {\r\n return {\r\n l: clamp(l, 0, 1),\r\n c: clamp(c, 0, 0.4),\r\n h: normalizeHue(h),\r\n };\r\n}\r\n\r\n/**\r\n * Derive the light-mode semantic palette from a seed color.\r\n */\r\nfunction generateLightPalette(seed: OklchColor): SemanticPalette {\r\n const h = normalizeHue(seed.h);\r\n\r\n const primary = oklch(0.52, seed.c, h);\r\n\r\n return {\r\n primary,\r\n primaryForeground: oklch(1.0, 0, h),\r\n secondary: oklch(0.96, 0.005, h),\r\n secondaryForeground: oklch(0.25, 0.015, h),\r\n accent: oklch(0.96, 0.01, h),\r\n accentForeground: oklch(0.25, 0.015, h),\r\n muted: oklch(0.96, 0.005, h),\r\n mutedForeground: oklch(0.58, 0.01, h),\r\n destructive: oklch(0.55, 0.22, 25),\r\n destructiveForeground: oklch(1.0, 0, 25),\r\n background: oklch(0.98, 0.002, h),\r\n foreground: oklch(0.20, 0.015, h),\r\n card: oklch(1.0, 0, h),\r\n cardForeground: oklch(0.20, 0.015, h),\r\n border: oklch(0.90, 0.005, h),\r\n input: oklch(0.95, 0.005, h),\r\n ring: primary,\r\n };\r\n}\r\n\r\n/**\r\n * Derive the dark-mode semantic palette from a seed color.\r\n *\r\n * Uses a layered surface system with increasing lightness:\r\n * Layer 0 (background): L=0.14\r\n * Layer 1 (card): L=0.18\r\n * Layer 2 (elevated): L=0.22 (mapped to `input`)\r\n * Layer 3 (overlay): L=0.26 (mapped to `border` at L=0.28 per rules table)\r\n */\r\nfunction generateDarkPalette(seed: OklchColor): SemanticPalette {\r\n const h = normalizeHue(seed.h);\r\n\r\n const primary = oklch(0.45, seed.c * 0.9, h);\r\n\r\n return {\r\n primary,\r\n primaryForeground: oklch(0.98, 0.005, h),\r\n secondary: oklch(0.25, 0.01, h),\r\n secondaryForeground: oklch(0.90, 0.005, h),\r\n accent: oklch(0.28, 0.015, h),\r\n accentForeground: oklch(0.90, 0.005, h),\r\n muted: oklch(0.25, 0.01, h),\r\n mutedForeground: oklch(0.72, 0.005, h),\r\n destructive: oklch(0.60, 0.24, 25),\r\n destructiveForeground: oklch(0.95, 0.01, 25),\r\n background: oklch(0.14, 0.01, h),\r\n foreground: oklch(0.95, 0.005, h),\r\n card: oklch(0.18, 0.01, h),\r\n cardForeground: oklch(0.95, 0.005, h),\r\n border: oklch(0.28, 0.01, h),\r\n input: oklch(0.22, 0.01, h),\r\n ring: primary,\r\n };\r\n}\r\n\r\n\r\n/**\r\n * Generate a complete light + dark semantic palette from a seed OKLCH color.\r\n *\r\n * The seed color's hue drives the entire palette. Lightness and chroma\r\n * are adjusted per semantic role according to the design system rules.\r\n *\r\n * @param seed - The user-chosen seed color in OKLCH space\r\n * @returns A `ThemePalette` with `light` and `dark` semantic palettes\r\n */\r\nexport function generatePalette(seed: OklchColor): ThemePalette {\r\n return {\r\n light: generateLightPalette(seed),\r\n dark: generateDarkPalette(seed),\r\n };\r\n}\r\n\r\n/**\r\n * Deep-merge partial overrides into a base palette.\r\n *\r\n * Overridden keys take the override value; all other keys are preserved\r\n * from the base. Always returns a new object (no mutation).\r\n *\r\n * @param base - The base palette to start from\r\n * @param overrides - Partial light/dark overrides to apply\r\n * @returns A new `ThemePalette` with overrides merged in\r\n */\r\nexport function mergePalette(\r\n base: ThemePalette,\r\n overrides: Partial<{\r\n light: Partial<SemanticPalette>;\r\n dark: Partial<SemanticPalette>;\r\n }>,\r\n): ThemePalette {\r\n return {\r\n light: { ...base.light, ...overrides.light },\r\n dark: { ...base.dark, ...overrides.dark },\r\n };\r\n}\r\n","/**\r\n * Preset theme definitions for @lmring/theme.\r\n *\r\n * Each preset is defined by its OKLCH hue angle. The color engine\r\n * generates a full semantic palette from the seed parameters.\r\n */\r\n\r\nimport { generatePalette } from './color-engine';\r\nimport type { ThemePalette, ThemePreset } from './types';\r\n\r\n/**\r\n * All available preset themes.\r\n *\r\n * Each preset uses a default chroma of 0.18 and lightness of 0.55,\r\n * varying only in hue to produce distinct color families.\r\n */\r\nexport const presets: ThemePreset[] = [\r\n { name: 'ocean-blue', hue: 255, chroma: 0.18, lightness: 0.55 },\r\n { name: 'violet', hue: 280, chroma: 0.18, lightness: 0.55 },\r\n { name: 'emerald', hue: 155, chroma: 0.18, lightness: 0.55 },\r\n { name: 'amber', hue: 75, chroma: 0.18, lightness: 0.55 },\r\n { name: 'rose', hue: 350, chroma: 0.18, lightness: 0.55 },\r\n { name: 'crimson', hue: 25, chroma: 0.18, lightness: 0.55 },\r\n { name: 'cyan', hue: 195, chroma: 0.18, lightness: 0.55 },\r\n { name: 'indigo', hue: 265, chroma: 0.18, lightness: 0.55 },\r\n];\r\n\r\n/**\r\n * Look up a preset by name and return its generated palette.\r\n *\r\n * @param name - Kebab-case preset name (e.g. 'ocean-blue', 'violet')\r\n * @returns The full light + dark `ThemePalette` for the preset\r\n * @throws {Error} If no preset matches the given name\r\n */\r\nexport function getPreset(name: string): ThemePalette {\r\n const preset = presets.find((p) => p.name === name);\r\n if (!preset) {\r\n throw new Error(\r\n `Unknown preset \"${name}\". Available: ${presets.map((p) => p.name).join(', ')}`,\r\n );\r\n }\r\n return generatePalette({ h: preset.hue, c: preset.chroma, l: preset.lightness });\r\n}\r\n","/**\r\n * Design tokens for @lmring/theme\r\n *\r\n * Static design tokens covering spacing, radius, shadow, typography,\r\n * line-height (leading), easing, and duration values.\r\n *\r\n * Spacing uses a 4px base grid. All numeric spacing values (excluding 0)\r\n * are positive multiples of 4.\r\n */\r\n\r\n/** Spacing scale based on 4px grid */\r\nconst spacing = {\r\n 0: '0px',\r\n 1: '4px',\r\n 2: '8px',\r\n 3: '12px',\r\n 4: '16px',\r\n 5: '20px',\r\n 6: '24px',\r\n 8: '32px',\r\n 10: '40px',\r\n 12: '48px',\r\n 16: '64px',\r\n} as const;\r\n\r\n/** Border-radius scale with 10px (0.625rem) base */\r\nconst radius = {\r\n sm: 'calc(var(--radius) - 4px)',\r\n md: 'calc(var(--radius) - 2px)',\r\n lg: 'var(--radius)',\r\n xl: 'calc(var(--radius) + 4px)',\r\n '2xl': 'calc(var(--radius) + 8px)',\r\n full: '9999px',\r\n} as const;\r\n\r\n/** Multi-layer composite shadow system (3 levels) */\r\nconst shadow = {\r\n sm: '0 1px 2px oklch(0 0 0 / 3%), 0 1px 3px oklch(0 0 0 / 2%)',\r\n md: '0 2px 4px oklch(0 0 0 / 3%), 0 4px 8px oklch(0 0 0 / 3%), 0 8px 16px oklch(0 0 0 / 2%)',\r\n lg: '0 4px 8px oklch(0 0 0 / 3%), 0 8px 16px oklch(0 0 0 / 3%), 0 16px 32px oklch(0 0 0 / 4%), 0 32px 64px oklch(0 0 0 / 2%)',\r\n} as const;\r\n\r\n/** Typography font-size scale (rem values) */\r\nconst typography = {\r\n xs: '0.75rem',\r\n sm: '0.875rem',\r\n base: '1rem',\r\n lg: '1.125rem',\r\n xl: '1.25rem',\r\n '2xl': '1.5rem',\r\n '3xl': '1.875rem',\r\n '4xl': '2.25rem',\r\n} as const;\r\n\r\n/** Line-height scale */\r\nconst leading = {\r\n tight: '1.25',\r\n snug: '1.375',\r\n normal: '1.5',\r\n relaxed: '1.625',\r\n loose: '1.75',\r\n} as const;\r\n\r\n/** CSS easing functions */\r\nconst easing = {\r\n spring: 'cubic-bezier(0.34, 1.56, 0.64, 1)',\r\n smooth: 'cubic-bezier(0.25, 0.1, 0.25, 1)',\r\n outExpo: 'cubic-bezier(0.16, 1, 0.3, 1)',\r\n} as const;\r\n\r\n/** Animation duration values */\r\nconst duration = {\r\n fast: '150ms',\r\n normal: '200ms',\r\n slow: '300ms',\r\n slower: '500ms',\r\n} as const;\r\n\r\n/** All design tokens grouped by category */\r\nexport const tokens = {\r\n spacing,\r\n radius,\r\n shadow,\r\n typography,\r\n leading,\r\n easing,\r\n duration,\r\n} as const;\r\n","/**\r\n * CSS variable generator.\r\n *\r\n * Converts a SemanticPalette into CSS custom property key-value pairs\r\n * for injection into the document root element.\r\n */\r\n\r\nimport { oklchToCss } from './color-convert';\r\nimport type { SemanticPalette } from './types';\r\n\r\n/**\r\n * Convert a camelCase string to kebab-case.\r\n *\r\n * @example camelToKebab('primaryForeground') // 'primary-foreground'\r\n */\r\nfunction camelToKebab(str: string): string {\r\n return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);\r\n}\r\n\r\n/**\r\n * Convert a SemanticPalette into a Record of CSS custom properties.\r\n *\r\n * Each key in the palette is converted from camelCase to a `--kebab-case`\r\n * CSS variable name, and each value is formatted as an `oklch(l c h)` string.\r\n *\r\n * @param palette - A semantic palette (light or dark)\r\n * @returns A record mapping CSS variable names to OKLCH CSS values\r\n *\r\n * @example\r\n * paletteToCssVars(palette)\r\n * // { '--primary': 'oklch(0.55 0.18 255)', '--primary-foreground': 'oklch(1 0 0)', ... }\r\n */\r\nexport function paletteToCssVars(palette: SemanticPalette): Record<string, string> {\r\n const vars: Record<string, string> = {};\r\n\r\n for (const [key, color] of Object.entries(palette)) {\r\n const cssVarName = `--${camelToKebab(key)}`;\r\n vars[cssVarName] = oklchToCss(color);\r\n }\r\n\r\n return vars;\r\n}\r\n","/**\r\n * Theme configuration serialization and deserialization.\r\n *\r\n * Provides pure-function helpers for persisting a {@link PersistedThemeConfig}\r\n * to/from JSON strings. Deserialization includes full validation so callers\r\n * can safely trust the returned value.\r\n */\r\n\r\nimport type { PersistedThemeConfig, OklchColor } from './types';\r\n\r\nconst VALID_MODES = new Set<PersistedThemeConfig['mode']>([\r\n 'light',\r\n 'dark',\r\n 'system',\r\n]);\r\n\r\n/** Serialize a theme config to a JSON string. */\r\nexport function serialize(config: PersistedThemeConfig): string {\r\n return JSON.stringify(config);\r\n}\r\n\r\n/**\r\n * Deserialize a raw JSON string into a validated {@link PersistedThemeConfig}.\r\n *\r\n * Returns `null` when:\r\n * - the string is not valid JSON\r\n * - any field fails validation (mode enum, OKLCH ranges, presetName type)\r\n */\r\nexport function deserialize(raw: string): PersistedThemeConfig | null {\r\n let parsed: unknown;\r\n try {\r\n parsed = JSON.parse(raw);\r\n } catch {\r\n return null;\r\n }\r\n\r\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\r\n return null;\r\n }\r\n\r\n const obj = parsed as Record<string, unknown>;\r\n\r\n // Validate mode\r\n if (!VALID_MODES.has(obj.mode as PersistedThemeConfig['mode'])) {\r\n return null;\r\n }\r\n\r\n // Validate seedColor\r\n if (!isValidOklchColor(obj.seedColor)) {\r\n return null;\r\n }\r\n\r\n // Validate presetName\r\n if (obj.presetName !== null && typeof obj.presetName !== 'string') {\r\n return null;\r\n }\r\n\r\n return {\r\n mode: obj.mode as PersistedThemeConfig['mode'],\r\n seedColor: obj.seedColor as OklchColor,\r\n presetName: obj.presetName as string | null,\r\n };\r\n}\r\n\r\nfunction isValidOklchColor(value: unknown): value is OklchColor {\r\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\r\n return false;\r\n }\r\n\r\n const color = value as Record<string, unknown>;\r\n\r\n return (\r\n typeof color.l === 'number' &&\r\n typeof color.c === 'number' &&\r\n typeof color.h === 'number' &&\r\n color.l >= 0 &&\r\n color.l <= 1 &&\r\n color.c >= 0 &&\r\n color.c <= 0.4 &&\r\n color.h >= 0 &&\r\n color.h <= 360\r\n );\r\n}\r\n"],"mappings":";;;;;;;;;AAUA,MAAM,UAAU,UAAU,QAAQ;AAElC,MAAM,YAAY;;;;;AAMlB,SAAS,eAAe,KAAmB;AACzC,KAAI,CAAC,UAAU,KAAK,IAAI,CACtB,OAAM,IAAI,MACR,uBAAuB,IAAI,sCAC5B;;;;;;;;;AAWL,SAAgB,WAAW,KAAyB;AAClD,gBAAe,IAAI;CACnB,MAAM,SAAS,QAAQ,IAAI;AAC3B,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,0BAA0B,IAAI,aAAa;AAE7D,QAAO;EACL,GAAG,OAAO;EACV,GAAG,OAAO,KAAK;EACf,GAAG,OAAO,KAAK;EAChB;;;;;;;;AASH,SAAgB,WAAW,OAA2B;AAEpD,QADY,UAAU;EAAE,MAAM;EAAS,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,CAAC;;;;;;;;AAU9E,SAAgB,WAAW,OAA2B;AACpD,QAAO,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE;;;;;;;;;;;ACtDhD,MAAM,QAAQ,UAAU,MAAM;;;;;;;AAQ9B,SAAS,UAAU,GAAmB;AACpC,QAAO,KAAK,SAAU,IAAI,UAAU,IAAI,QAAS,UAAU;;;;;;;;;;;AAY7D,SAAgB,qBAAqB,OAA2B;CAC9D,MAAM,MAAM,MAAM;EAAE,MAAM;EAAS,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,CAAC;AACxE,KAAI,CAAC,IACH,QAAO;CAGT,MAAM,IAAI,UAAU,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG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,CACnC,QAAO;AAIT,KAAI,IAAI,eAAe,QAAQ,OAAO,IAAI,eAAe,SACvD,QAAO;AAGT,QAAO;EACL,MAAM,IAAI;EACV,WAAW,IAAI;EACf,YAAY,IAAI;EACjB;;AAGH,SAAS,kBAAkB,OAAqC;AAC9D,KAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,MAAM,CACrE,QAAO;CAGT,MAAM,QAAQ;AAEd,QACE,OAAO,MAAM,MAAM,YACnB,OAAO,MAAM,MAAM,YACnB,OAAO,MAAM,MAAM,YACnB,MAAM,KAAK,KACX,MAAM,KAAK,KACX,MAAM,KAAK,KACX,MAAM,KAAK,MACX,MAAM,KAAK,KACX,MAAM,KAAK"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lmring/theme",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "LMRing theme engine, tokens, presets, and CSS variable generation utilities.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./css": "./src/theme.css",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src/theme.css",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"provenance": true,
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/llm-ring/lmring.git",
|
|
31
|
+
"directory": "packages/theme"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/llm-ring/lmring/tree/main/packages/theme",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/llm-ring/lmring/issues"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsdown",
|
|
39
|
+
"dev": "tsdown --watch",
|
|
40
|
+
"test": "vitest run"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"culori": "^4.0.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@lmring/typescript-config": "workspace:*",
|
|
47
|
+
"@lmring/vitest-config": "workspace:*",
|
|
48
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
49
|
+
"fast-check": "^4.6.0",
|
|
50
|
+
"tsdown": "0.21.4",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"vitest": "^4.1.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/theme.css
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* @lmring/theme static design tokens. */
|
|
2
|
+
|
|
3
|
+
@theme {
|
|
4
|
+
/* Spacing scale (4px grid). */
|
|
5
|
+
--spacing-0: 0px;
|
|
6
|
+
--spacing-1: 4px;
|
|
7
|
+
--spacing-2: 8px;
|
|
8
|
+
--spacing-3: 12px;
|
|
9
|
+
--spacing-4: 16px;
|
|
10
|
+
--spacing-5: 20px;
|
|
11
|
+
--spacing-6: 24px;
|
|
12
|
+
--spacing-8: 32px;
|
|
13
|
+
--spacing-10: 40px;
|
|
14
|
+
--spacing-12: 48px;
|
|
15
|
+
--spacing-16: 64px;
|
|
16
|
+
|
|
17
|
+
/* Radius scale. */
|
|
18
|
+
--radius: 0.625rem;
|
|
19
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
20
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
21
|
+
--radius-lg: var(--radius);
|
|
22
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
23
|
+
--radius-2xl: calc(var(--radius) + 8px);
|
|
24
|
+
|
|
25
|
+
/* Shadow levels. */
|
|
26
|
+
--shadow-sm: 0 1px 2px oklch(0 0 0 / 3%), 0 1px 3px oklch(0 0 0 / 2%);
|
|
27
|
+
--shadow-md:
|
|
28
|
+
0 2px 4px oklch(0 0 0 / 3%),
|
|
29
|
+
0 4px 8px oklch(0 0 0 / 3%),
|
|
30
|
+
0 8px 16px oklch(0 0 0 / 2%);
|
|
31
|
+
--shadow-lg:
|
|
32
|
+
0 4px 8px oklch(0 0 0 / 3%),
|
|
33
|
+
0 8px 16px oklch(0 0 0 / 3%),
|
|
34
|
+
0 16px 32px oklch(0 0 0 / 4%),
|
|
35
|
+
0 32px 64px oklch(0 0 0 / 2%);
|
|
36
|
+
|
|
37
|
+
/* Typography scale. */
|
|
38
|
+
--text-xs: 0.75rem;
|
|
39
|
+
--text-sm: 0.875rem;
|
|
40
|
+
--text-base: 1rem;
|
|
41
|
+
--text-lg: 1.125rem;
|
|
42
|
+
--text-xl: 1.25rem;
|
|
43
|
+
--text-2xl: 1.5rem;
|
|
44
|
+
--text-3xl: 1.875rem;
|
|
45
|
+
--text-4xl: 2.25rem;
|
|
46
|
+
|
|
47
|
+
/* Line-height scale. */
|
|
48
|
+
--leading-tight: 1.25;
|
|
49
|
+
--leading-snug: 1.375;
|
|
50
|
+
--leading-normal: 1.5;
|
|
51
|
+
--leading-relaxed: 1.625;
|
|
52
|
+
--leading-loose: 1.75;
|
|
53
|
+
|
|
54
|
+
/* Motion tokens. */
|
|
55
|
+
--ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
56
|
+
--ease-smooth: cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
57
|
+
--ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
|
|
58
|
+
|
|
59
|
+
--duration-fast: 150ms;
|
|
60
|
+
--duration-normal: 200ms;
|
|
61
|
+
--duration-slow: 300ms;
|
|
62
|
+
--duration-slower: 500ms;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:root {
|
|
66
|
+
/* Surface layer tokens for light mode. */
|
|
67
|
+
--surface: oklch(1 0 0);
|
|
68
|
+
--elevated: oklch(0.99 0.002 264);
|
|
69
|
+
--overlay: oklch(0.97 0.005 264);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.dark {
|
|
73
|
+
/* Surface layer tokens for dark mode. */
|
|
74
|
+
--surface: oklch(0.18 0.01 264);
|
|
75
|
+
--elevated: oklch(0.22 0.01 264);
|
|
76
|
+
--overlay: oklch(0.28 0.01 264);
|
|
77
|
+
|
|
78
|
+
/* Dark-mode shadow variants. */
|
|
79
|
+
--shadow-sm: 0 1px 2px oklch(0 0 0 / 20%), 0 1px 3px oklch(0 0 0 / 15%);
|
|
80
|
+
--shadow-md:
|
|
81
|
+
0 2px 4px oklch(0 0 0 / 24%),
|
|
82
|
+
0 4px 8px oklch(0 0 0 / 20%),
|
|
83
|
+
0 8px 16px oklch(0 0 0 / 16%);
|
|
84
|
+
--shadow-lg:
|
|
85
|
+
0 4px 8px oklch(0 0 0 / 28%),
|
|
86
|
+
0 8px 16px oklch(0 0 0 / 24%),
|
|
87
|
+
0 16px 32px oklch(0 0 0 / 20%),
|
|
88
|
+
0 32px 64px oklch(0 0 0 / 16%);
|
|
89
|
+
}
|