@wrikka/theme 0.0.0-stage → 0.1.3

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.
@@ -0,0 +1,850 @@
1
+ // src/theme/color-math.ts
2
+ const TRIPLET$1 = /^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/;
3
+ const HEX = /^#([0-9a-f]{6})$/i;
4
+ const isHslTriplet = (value) => TRIPLET$1.test(value.trim());
5
+ /** Parse an "h s% l%" triplet into sRGB components in the 0–1 range. */
6
+ function hslTripletToRgb(triplet) {
7
+ const match = triplet.trim().match(TRIPLET$1);
8
+ if (!match) return void 0;
9
+ const h = Number(match[1]);
10
+ const s = Number(match[2]) / 100;
11
+ const l = Number(match[3]) / 100;
12
+ const k = (n) => (n + h / 30) % 12;
13
+ const a = s * Math.min(l, 1 - l);
14
+ const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
15
+ return [
16
+ f(0),
17
+ f(8),
18
+ f(4)
19
+ ];
20
+ }
21
+ /** Parse a six-digit hex color into sRGB components in the 0–1 range. */
22
+ function hexToRgb(hex) {
23
+ const match = hex.trim().match(HEX);
24
+ if (!match) return void 0;
25
+ const value = Number.parseInt(match[1], 16);
26
+ return [
27
+ (value >> 16 & 255) / 255,
28
+ (value >> 8 & 255) / 255,
29
+ (value & 255) / 255
30
+ ];
31
+ }
32
+ /** Convert a six-digit hex color into the "h s% l%" triplet theme.css uses. */
33
+ function hexToHslTriplet(hex) {
34
+ const rgb = hexToRgb(hex);
35
+ return rgb ? rgbToHslTriplet(rgb) : void 0;
36
+ }
37
+ function rgbToHslTriplet(rgb) {
38
+ const [r, g, b] = rgb;
39
+ const max = Math.max(r, g, b);
40
+ const min = Math.min(r, g, b);
41
+ const lightness = (max + min) / 2;
42
+ if (max === min) return `0 0% ${round(lightness * 100)}%`;
43
+ const delta = max - min;
44
+ const saturation = lightness > .5 ? delta / (2 - max - min) : delta / (max + min);
45
+ return `${round((max === r ? (g - b) / delta + (g < b ? 6 : 0) : max === g ? (b - r) / delta + 2 : (r - g) / delta + 4) * 60)} ${round(saturation * 100)}% ${round(lightness * 100)}%`;
46
+ }
47
+ /** WCAG 2.1 relative luminance. */
48
+ function relativeLuminance([r, g, b]) {
49
+ const channel = (value) => value <= .03928 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4;
50
+ return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
51
+ }
52
+ /** WCAG 2.1 contrast ratio between two sRGB colors (1–21). */
53
+ function contrastRatio(a, b) {
54
+ const first = relativeLuminance(a);
55
+ const second = relativeLuminance(b);
56
+ return (Math.max(first, second) + .05) / (Math.min(first, second) + .05);
57
+ }
58
+ /** Contrast between two "h s% l%" triplets; undefined when either fails to parse. */
59
+ function tripletContrast(a, b) {
60
+ const first = hslTripletToRgb(a);
61
+ const second = hslTripletToRgb(b);
62
+ return first && second ? contrastRatio(first, second) : void 0;
63
+ }
64
+ function round(value) {
65
+ return Number(value.toFixed(1));
66
+ }
67
+
68
+ // src/theme/hsl.ts
69
+ const TRIPLET = /^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/;
70
+ /**
71
+ * Soft surfaces keep the family hue and scale saturation/lightness instead of
72
+ * mixing in sRGB: a red mixed into a slate surface lands on magenta, which is
73
+ * not the family any more.
74
+ */
75
+ const SOFT = {
76
+ light: {
77
+ saturation: .85,
78
+ lightness: 93
79
+ },
80
+ dark: {
81
+ saturation: .6,
82
+ lightness: 15
83
+ }
84
+ };
85
+ function hsl(h, s, l) {
86
+ return `${h} ${s}% ${l}%`;
87
+ }
88
+ /** Shift the lightness channel of an "h s% l%" string, clamped to 0–100. */
89
+ function adjustLightness(hslValue, delta) {
90
+ const match = hslValue.match(TRIPLET);
91
+ if (!match) return hslValue;
92
+ const [h, s, l] = match.slice(1).map(Number);
93
+ return `${h} ${s}% ${Math.max(0, Math.min(100, l + delta))}%`;
94
+ }
95
+ /** Low-emphasis surface of a family color, tuned per mode. */
96
+ function softTriplet(value, mode) {
97
+ const match = value.match(TRIPLET);
98
+ if (!match) return value;
99
+ const [h, s] = match.slice(1).map(Number);
100
+ const { saturation, lightness } = SOFT[mode];
101
+ return hsl(h, Math.round(s * saturation), lightness);
102
+ }
103
+ /** Readable text color for a family, for use on its `soft` surface. */
104
+ function inkTriplet(value, mode) {
105
+ const match = value.match(TRIPLET);
106
+ if (!match) return value;
107
+ const [h, s, l] = match.slice(1).map(Number);
108
+ return mode === "dark" ? hsl(h, Math.min(s, 90), Math.max(l, 72)) : hsl(h, Math.min(s, 84), Math.min(l, 27));
109
+ }
110
+ /** Emphasised fill of a family color (darker in both modes). */
111
+ function deepTriplet(value) {
112
+ const match = value.match(TRIPLET);
113
+ if (!match) return value;
114
+ const [h, s, l] = match.slice(1).map(Number);
115
+ return hsl(h, s, Math.round(l * .55 + 3.6));
116
+ }
117
+ /** Translucent brand levels applied over any surface: `hsl(var(--color-primary) / var(--su-alpha-<level>))`. */
118
+ function alphaVars(mode) {
119
+ return mode === "dark" ? {
120
+ "--su-alpha-tint": "0.10",
121
+ "--su-alpha-tint-strong": "0.14",
122
+ "--su-alpha-faint": "0.07",
123
+ "--su-alpha-wash": "0.12"
124
+ } : {
125
+ "--su-alpha-tint": "0.08",
126
+ "--su-alpha-tint-strong": "0.12",
127
+ "--su-alpha-faint": "0.05",
128
+ "--su-alpha-wash": "0.10"
129
+ };
130
+ }
131
+
132
+ // src/theme/brand.ts
133
+ /**
134
+ * Brand ramp — one brand color in, the full primary token set out.
135
+ *
136
+ * Use it when a product has a single brand color and the primary/hover/active
137
+ * shades plus a readable foreground should follow automatically, instead of
138
+ * hand-picking a ThemeColor preset:
139
+ *
140
+ * brandVars("#7c3aed") // light ramp
141
+ * brandVars("#7c3aed", "dark") // dark ramp
142
+ * brandVars({ light: "#cf4727", dark: "#ff6b47" })
143
+ * presetSolidUI({ brand: "#7c3aed" })
144
+ */
145
+ const INK = "222 47% 11%";
146
+ const WHITE = "0 0% 100%";
147
+ /** Accept a six-digit hex color or an "h s% l%" triplet; returns the triplet form. */
148
+ function normalizeBrand(brand) {
149
+ const value = brand.trim();
150
+ if (isHslTriplet(value)) return value.replace(/\s+/g, " ");
151
+ return hexToHslTriplet(value);
152
+ }
153
+ /** Pick whichever of ink/white reads better on the given fill (WCAG contrast). */
154
+ function readableForeground(triplet) {
155
+ const fill = hslTripletToRgb(triplet);
156
+ if (!fill) return WHITE;
157
+ const ink = hslTripletToRgb(INK);
158
+ const white = hslTripletToRgb(WHITE);
159
+ return contrastRatio(fill, ink) >= contrastRatio(fill, white) ? INK : WHITE;
160
+ }
161
+ /** Resolve the color a mode should use; a plain string applies to both modes. */
162
+ function brandForMode(brand, mode = "light") {
163
+ return typeof brand === "string" ? brand : brand[mode];
164
+ }
165
+ /**
166
+ * Build the primary ramp for a brand color.
167
+ * Hover/active follow the same lightness direction as the built-in palettes:
168
+ * lighter in light mode, darker in dark mode.
169
+ */
170
+ function brandRamp(brand, mode = "light") {
171
+ const input = brandForMode(brand, mode);
172
+ const primary = normalizeBrand(input);
173
+ if (!primary) throw new TypeError(`brandRamp: expected a hex color or "h s% l%" triplet, got "${input}"`);
174
+ const shift = mode === "dark" ? -5 : 5;
175
+ return {
176
+ brand: primary,
177
+ primary,
178
+ primaryForeground: readableForeground(primary),
179
+ primaryHover: adjustLightness(primary, shift),
180
+ primaryActive: adjustLightness(primary, shift * 2),
181
+ ring: primary
182
+ };
183
+ }
184
+ /** CSS custom properties consumed by theme.css / the UnoCSS preset. */
185
+ function brandVars(brand, mode = "light") {
186
+ const ramp = brandRamp(brand, mode);
187
+ return {
188
+ "--su-brand": ramp.brand,
189
+ "--color-primary": ramp.primary,
190
+ "--color-primary-foreground": ramp.primaryForeground,
191
+ "--color-primary-hover": ramp.primaryHover,
192
+ "--color-primary-active": ramp.primaryActive,
193
+ "--color-ring": ramp.ring,
194
+ "--color-primary-soft": softTriplet(ramp.primary, mode),
195
+ "--color-primary-soft-foreground": inkTriplet(ramp.primary, mode),
196
+ "--color-primary-ink": inkTriplet(ramp.primary, mode),
197
+ "--color-primary-deep": deepTriplet(ramp.primary)
198
+ };
199
+ }
200
+
201
+ // src/theme/colors/blue-family.ts
202
+ const blueFamilySchemes = {
203
+ slate: {
204
+ light: {
205
+ primary: hsl(215, 25, 27),
206
+ primaryForeground: hsl(0, 0, 100),
207
+ secondary: hsl(215, 25, 95),
208
+ secondaryForeground: hsl(215, 25, 10),
209
+ accent: hsl(215, 25, 90),
210
+ accentForeground: hsl(215, 35, 25),
211
+ ring: hsl(215, 25, 27),
212
+ info: hsl(215, 90, 55),
213
+ success: hsl(142, 70, 45),
214
+ warning: hsl(38, 90, 55),
215
+ destructive: hsl(0, 84, 60)
216
+ },
217
+ dark: {
218
+ primary: hsl(215, 30, 80),
219
+ primaryForeground: hsl(215, 30, 10),
220
+ secondary: hsl(215, 30, 20),
221
+ secondaryForeground: hsl(215, 30, 95),
222
+ accent: hsl(215, 30, 20),
223
+ accentForeground: hsl(215, 40, 90),
224
+ ring: hsl(215, 60, 75),
225
+ info: hsl(215, 90, 65),
226
+ success: hsl(142, 70, 55),
227
+ warning: hsl(38, 90, 60),
228
+ destructive: hsl(0, 90, 65)
229
+ }
230
+ },
231
+ blue: {
232
+ light: {
233
+ primary: hsl(221, 83, 53),
234
+ primaryForeground: hsl(0, 0, 100),
235
+ secondary: hsl(221, 70, 95),
236
+ secondaryForeground: hsl(221, 83, 20),
237
+ accent: hsl(221, 83, 90),
238
+ accentForeground: hsl(221, 83, 25),
239
+ ring: hsl(221, 83, 53),
240
+ info: hsl(221, 90, 55),
241
+ success: hsl(142, 70, 45),
242
+ warning: hsl(38, 90, 55),
243
+ destructive: hsl(0, 84, 60)
244
+ },
245
+ dark: {
246
+ primary: hsl(221, 90, 63),
247
+ primaryForeground: hsl(221, 90, 10),
248
+ secondary: hsl(221, 40, 20),
249
+ secondaryForeground: hsl(221, 90, 95),
250
+ accent: hsl(221, 60, 20),
251
+ accentForeground: hsl(221, 90, 90),
252
+ ring: hsl(221, 90, 63),
253
+ info: hsl(221, 90, 65),
254
+ success: hsl(142, 70, 55),
255
+ warning: hsl(38, 90, 60),
256
+ destructive: hsl(0, 90, 65)
257
+ }
258
+ },
259
+ indigo: {
260
+ light: {
261
+ primary: hsl(243, 75, 59),
262
+ primaryForeground: hsl(0, 0, 100),
263
+ secondary: hsl(243, 70, 95),
264
+ secondaryForeground: hsl(243, 75, 20),
265
+ accent: hsl(243, 75, 90),
266
+ accentForeground: hsl(243, 80, 25),
267
+ ring: hsl(243, 75, 59),
268
+ info: hsl(243, 90, 55),
269
+ success: hsl(142, 70, 45),
270
+ warning: hsl(38, 90, 55),
271
+ destructive: hsl(0, 84, 60)
272
+ },
273
+ dark: {
274
+ primary: hsl(243, 90, 70),
275
+ primaryForeground: hsl(243, 90, 10),
276
+ secondary: hsl(243, 40, 20),
277
+ secondaryForeground: hsl(243, 90, 95),
278
+ accent: hsl(243, 60, 20),
279
+ accentForeground: hsl(243, 90, 90),
280
+ ring: hsl(243, 90, 70),
281
+ info: hsl(243, 90, 65),
282
+ success: hsl(142, 70, 55),
283
+ warning: hsl(38, 90, 60),
284
+ destructive: hsl(0, 90, 65)
285
+ }
286
+ },
287
+ violet: {
288
+ light: {
289
+ primary: hsl(258, 90, 66),
290
+ primaryForeground: hsl(0, 0, 100),
291
+ secondary: hsl(258, 70, 95),
292
+ secondaryForeground: hsl(258, 90, 20),
293
+ accent: hsl(258, 90, 90),
294
+ accentForeground: hsl(258, 90, 25),
295
+ ring: hsl(258, 90, 66),
296
+ info: hsl(258, 90, 55),
297
+ success: hsl(142, 70, 45),
298
+ warning: hsl(38, 90, 55),
299
+ destructive: hsl(0, 84, 60)
300
+ },
301
+ dark: {
302
+ primary: hsl(258, 95, 75),
303
+ primaryForeground: hsl(258, 95, 10),
304
+ secondary: hsl(258, 40, 20),
305
+ secondaryForeground: hsl(258, 95, 95),
306
+ accent: hsl(258, 60, 20),
307
+ accentForeground: hsl(258, 95, 90),
308
+ ring: hsl(258, 95, 75),
309
+ info: hsl(258, 90, 65),
310
+ success: hsl(142, 70, 55),
311
+ warning: hsl(38, 90, 60),
312
+ destructive: hsl(0, 90, 65)
313
+ }
314
+ }
315
+ };
316
+
317
+ // src/theme/colors/cool.ts
318
+ const coolSchemes = {
319
+ green: {
320
+ light: {
321
+ primary: hsl(142, 76, 36),
322
+ primaryForeground: hsl(0, 0, 100),
323
+ secondary: hsl(142, 70, 95),
324
+ secondaryForeground: hsl(142, 76, 20),
325
+ accent: hsl(142, 76, 90),
326
+ accentForeground: hsl(142, 76, 25),
327
+ ring: hsl(142, 76, 36),
328
+ info: hsl(215, 90, 55),
329
+ success: hsl(142, 76, 45),
330
+ warning: hsl(38, 90, 55),
331
+ destructive: hsl(0, 84, 60)
332
+ },
333
+ dark: {
334
+ primary: hsl(142, 90, 55),
335
+ primaryForeground: hsl(142, 90, 10),
336
+ secondary: hsl(142, 40, 20),
337
+ secondaryForeground: hsl(142, 90, 95),
338
+ accent: hsl(142, 60, 20),
339
+ accentForeground: hsl(142, 90, 90),
340
+ ring: hsl(142, 90, 55),
341
+ info: hsl(215, 90, 65),
342
+ success: hsl(142, 90, 60),
343
+ warning: hsl(38, 90, 60),
344
+ destructive: hsl(0, 90, 65)
345
+ }
346
+ },
347
+ teal: {
348
+ light: {
349
+ primary: hsl(168, 76, 36),
350
+ primaryForeground: hsl(0, 0, 100),
351
+ secondary: hsl(168, 70, 95),
352
+ secondaryForeground: hsl(168, 76, 20),
353
+ accent: hsl(168, 76, 90),
354
+ accentForeground: hsl(168, 76, 25),
355
+ ring: hsl(168, 76, 36),
356
+ info: hsl(215, 90, 55),
357
+ success: hsl(142, 70, 45),
358
+ warning: hsl(38, 90, 55),
359
+ destructive: hsl(0, 84, 60)
360
+ },
361
+ dark: {
362
+ primary: hsl(168, 90, 55),
363
+ primaryForeground: hsl(168, 90, 10),
364
+ secondary: hsl(168, 40, 20),
365
+ secondaryForeground: hsl(168, 90, 95),
366
+ accent: hsl(168, 60, 20),
367
+ accentForeground: hsl(168, 90, 90),
368
+ ring: hsl(168, 90, 55),
369
+ info: hsl(215, 90, 65),
370
+ success: hsl(142, 70, 55),
371
+ warning: hsl(38, 90, 60),
372
+ destructive: hsl(0, 90, 65)
373
+ }
374
+ },
375
+ cyan: {
376
+ light: {
377
+ primary: hsl(189, 94, 43),
378
+ primaryForeground: hsl(0, 0, 100),
379
+ secondary: hsl(189, 80, 95),
380
+ secondaryForeground: hsl(189, 94, 20),
381
+ accent: hsl(189, 94, 90),
382
+ accentForeground: hsl(189, 94, 25),
383
+ ring: hsl(189, 94, 43),
384
+ info: hsl(189, 94, 55),
385
+ success: hsl(142, 70, 45),
386
+ warning: hsl(38, 90, 55),
387
+ destructive: hsl(0, 84, 60)
388
+ },
389
+ dark: {
390
+ primary: hsl(189, 100, 55),
391
+ primaryForeground: hsl(189, 100, 10),
392
+ secondary: hsl(189, 50, 20),
393
+ secondaryForeground: hsl(189, 100, 95),
394
+ accent: hsl(189, 70, 20),
395
+ accentForeground: hsl(189, 100, 90),
396
+ ring: hsl(189, 100, 55),
397
+ info: hsl(189, 100, 65),
398
+ success: hsl(142, 70, 55),
399
+ warning: hsl(38, 90, 60),
400
+ destructive: hsl(0, 90, 65)
401
+ }
402
+ }
403
+ };
404
+
405
+ // src/theme/colors/warm.ts
406
+ const warmSchemes = {
407
+ rose: {
408
+ light: {
409
+ primary: hsl(340, 82, 52),
410
+ primaryForeground: hsl(0, 0, 100),
411
+ secondary: hsl(340, 70, 95),
412
+ secondaryForeground: hsl(340, 82, 20),
413
+ accent: hsl(340, 82, 90),
414
+ accentForeground: hsl(340, 82, 25),
415
+ ring: hsl(340, 82, 52),
416
+ info: hsl(215, 90, 55),
417
+ success: hsl(142, 70, 45),
418
+ warning: hsl(38, 90, 55),
419
+ destructive: hsl(0, 84, 60)
420
+ },
421
+ dark: {
422
+ primary: hsl(340, 95, 70),
423
+ primaryForeground: hsl(340, 95, 10),
424
+ secondary: hsl(340, 40, 20),
425
+ secondaryForeground: hsl(340, 95, 95),
426
+ accent: hsl(340, 60, 20),
427
+ accentForeground: hsl(340, 95, 90),
428
+ ring: hsl(340, 95, 70),
429
+ info: hsl(215, 90, 65),
430
+ success: hsl(142, 70, 55),
431
+ warning: hsl(38, 90, 60),
432
+ destructive: hsl(0, 90, 65)
433
+ }
434
+ },
435
+ pink: {
436
+ light: {
437
+ primary: hsl(330, 81, 60),
438
+ primaryForeground: hsl(0, 0, 100),
439
+ secondary: hsl(330, 70, 95),
440
+ secondaryForeground: hsl(330, 81, 20),
441
+ accent: hsl(330, 81, 90),
442
+ accentForeground: hsl(330, 81, 25),
443
+ ring: hsl(330, 81, 60),
444
+ info: hsl(215, 90, 55),
445
+ success: hsl(142, 70, 45),
446
+ warning: hsl(38, 90, 55),
447
+ destructive: hsl(0, 84, 60)
448
+ },
449
+ dark: {
450
+ primary: hsl(330, 95, 75),
451
+ primaryForeground: hsl(330, 95, 10),
452
+ secondary: hsl(330, 40, 20),
453
+ secondaryForeground: hsl(330, 95, 95),
454
+ accent: hsl(330, 60, 20),
455
+ accentForeground: hsl(330, 95, 90),
456
+ ring: hsl(330, 95, 75),
457
+ info: hsl(215, 90, 65),
458
+ success: hsl(142, 70, 55),
459
+ warning: hsl(38, 90, 60),
460
+ destructive: hsl(0, 90, 65)
461
+ }
462
+ },
463
+ red: {
464
+ light: {
465
+ primary: hsl(0, 84, 60),
466
+ primaryForeground: hsl(0, 0, 100),
467
+ secondary: hsl(0, 70, 95),
468
+ secondaryForeground: hsl(0, 84, 20),
469
+ accent: hsl(0, 84, 90),
470
+ accentForeground: hsl(0, 84, 25),
471
+ ring: hsl(0, 84, 60),
472
+ info: hsl(215, 90, 55),
473
+ success: hsl(142, 70, 45),
474
+ warning: hsl(38, 90, 55),
475
+ destructive: hsl(0, 84, 60)
476
+ },
477
+ dark: {
478
+ primary: hsl(0, 95, 70),
479
+ primaryForeground: hsl(0, 95, 10),
480
+ secondary: hsl(0, 40, 20),
481
+ secondaryForeground: hsl(0, 95, 95),
482
+ accent: hsl(0, 60, 20),
483
+ accentForeground: hsl(0, 95, 90),
484
+ ring: hsl(0, 95, 70),
485
+ info: hsl(215, 90, 65),
486
+ success: hsl(142, 70, 55),
487
+ warning: hsl(38, 90, 60),
488
+ destructive: hsl(0, 95, 70)
489
+ }
490
+ },
491
+ orange: {
492
+ light: {
493
+ primary: hsl(24, 95, 53),
494
+ primaryForeground: hsl(0, 0, 100),
495
+ secondary: hsl(24, 80, 95),
496
+ secondaryForeground: hsl(24, 95, 20),
497
+ accent: hsl(24, 95, 90),
498
+ accentForeground: hsl(24, 95, 25),
499
+ ring: hsl(24, 95, 53),
500
+ info: hsl(215, 90, 55),
501
+ success: hsl(142, 70, 45),
502
+ warning: hsl(38, 90, 55),
503
+ destructive: hsl(0, 84, 60)
504
+ },
505
+ dark: {
506
+ primary: hsl(24, 100, 60),
507
+ primaryForeground: hsl(24, 100, 10),
508
+ secondary: hsl(24, 50, 20),
509
+ secondaryForeground: hsl(24, 100, 95),
510
+ accent: hsl(24, 70, 20),
511
+ accentForeground: hsl(24, 100, 90),
512
+ ring: hsl(24, 100, 60),
513
+ info: hsl(215, 90, 65),
514
+ success: hsl(142, 70, 55),
515
+ warning: hsl(38, 90, 60),
516
+ destructive: hsl(0, 90, 65)
517
+ }
518
+ },
519
+ amber: {
520
+ light: {
521
+ primary: hsl(38, 92, 50),
522
+ primaryForeground: hsl(0, 0, 100),
523
+ secondary: hsl(38, 80, 95),
524
+ secondaryForeground: hsl(38, 92, 20),
525
+ accent: hsl(38, 92, 90),
526
+ accentForeground: hsl(38, 92, 25),
527
+ ring: hsl(38, 92, 50),
528
+ info: hsl(215, 90, 55),
529
+ success: hsl(142, 70, 45),
530
+ warning: hsl(38, 92, 55),
531
+ destructive: hsl(0, 84, 60)
532
+ },
533
+ dark: {
534
+ primary: hsl(38, 100, 60),
535
+ primaryForeground: hsl(38, 100, 10),
536
+ secondary: hsl(38, 50, 20),
537
+ secondaryForeground: hsl(38, 100, 95),
538
+ accent: hsl(38, 70, 20),
539
+ accentForeground: hsl(38, 100, 90),
540
+ ring: hsl(38, 100, 60),
541
+ info: hsl(215, 90, 65),
542
+ success: hsl(142, 70, 55),
543
+ warning: hsl(38, 100, 60),
544
+ destructive: hsl(0, 90, 65)
545
+ }
546
+ },
547
+ yellow: {
548
+ light: {
549
+ primary: hsl(48, 96, 53),
550
+ primaryForeground: hsl(0, 0, 0),
551
+ secondary: hsl(48, 80, 95),
552
+ secondaryForeground: hsl(48, 96, 20),
553
+ accent: hsl(48, 96, 90),
554
+ accentForeground: hsl(48, 96, 25),
555
+ ring: hsl(48, 96, 53),
556
+ info: hsl(215, 90, 55),
557
+ success: hsl(142, 70, 45),
558
+ warning: hsl(38, 90, 55),
559
+ destructive: hsl(0, 84, 60)
560
+ },
561
+ dark: {
562
+ primary: hsl(48, 100, 65),
563
+ primaryForeground: hsl(48, 100, 10),
564
+ secondary: hsl(48, 60, 20),
565
+ secondaryForeground: hsl(48, 100, 95),
566
+ accent: hsl(48, 80, 20),
567
+ accentForeground: hsl(48, 100, 90),
568
+ ring: hsl(48, 100, 65),
569
+ info: hsl(215, 90, 65),
570
+ success: hsl(142, 70, 55),
571
+ warning: hsl(38, 90, 60),
572
+ destructive: hsl(0, 90, 65)
573
+ }
574
+ }
575
+ };
576
+
577
+ // src/theme/colors.ts
578
+ const colorSchemes = {
579
+ ...blueFamilySchemes,
580
+ ...warmSchemes,
581
+ ...coolSchemes
582
+ };
583
+
584
+ // src/theme/scales.ts
585
+ const fontStacks = {
586
+ sans: "system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Noto Sans Thai\", \"IBM Plex Sans Thai\", \"Helvetica Neue\", Arial, sans-serif",
587
+ serif: "Georgia, Cambria, \"Times New Roman\", Times, serif",
588
+ mono: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace",
589
+ thai: "\"Noto Sans Thai\", \"IBM Plex Sans Thai\", \"Sarabun\", system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif"
590
+ };
591
+ /**
592
+ * Line heights per font. Thai stacks carry stacked vowels and tone marks above
593
+ * and below the baseline, so they need more air than a Latin-only face at the
594
+ * same size.
595
+ */
596
+ const leadingScales = {
597
+ sans: {
598
+ none: "1",
599
+ tight: "1.25",
600
+ normal: "1.5",
601
+ relaxed: "1.75"
602
+ },
603
+ serif: {
604
+ none: "1",
605
+ tight: "1.25",
606
+ normal: "1.5",
607
+ relaxed: "1.75"
608
+ },
609
+ mono: {
610
+ none: "1",
611
+ tight: "1.25",
612
+ normal: "1.5",
613
+ relaxed: "1.75"
614
+ },
615
+ thai: {
616
+ none: "1",
617
+ tight: "1.4",
618
+ normal: "1.6",
619
+ relaxed: "1.85"
620
+ }
621
+ };
622
+ const spaceScales = {
623
+ compact: {
624
+ "0": "0",
625
+ "1": "0.125rem",
626
+ "2": "0.25rem",
627
+ "3": "0.375rem",
628
+ "4": "0.5rem",
629
+ "5": "0.625rem",
630
+ "6": "0.75rem",
631
+ "7": "0.875rem",
632
+ "8": "1rem",
633
+ "10": "1.25rem",
634
+ "12": "1.5rem",
635
+ "16": "2rem"
636
+ },
637
+ normal: {
638
+ "0": "0",
639
+ "1": "0.25rem",
640
+ "2": "0.5rem",
641
+ "3": "0.75rem",
642
+ "4": "1rem",
643
+ "5": "1.25rem",
644
+ "6": "1.5rem",
645
+ "7": "1.75rem",
646
+ "8": "2rem",
647
+ "10": "2.5rem",
648
+ "12": "3rem",
649
+ "16": "4rem"
650
+ },
651
+ spacious: {
652
+ "0": "0",
653
+ "1": "0.5rem",
654
+ "2": "0.75rem",
655
+ "3": "1rem",
656
+ "4": "1.25rem",
657
+ "5": "1.5rem",
658
+ "6": "1.75rem",
659
+ "7": "2rem",
660
+ "8": "2.5rem",
661
+ "10": "3rem",
662
+ "12": "4rem",
663
+ "16": "6rem"
664
+ },
665
+ touch: {
666
+ "0": "0",
667
+ "1": "0.25rem",
668
+ "2": "0.5rem",
669
+ "3": "0.75rem",
670
+ "4": "1rem",
671
+ "5": "1.25rem",
672
+ "6": "1.5rem",
673
+ "7": "1.75rem",
674
+ "8": "2rem",
675
+ "10": "2.5rem",
676
+ "12": "3rem",
677
+ "16": "4rem"
678
+ }
679
+ };
680
+ const densityScales = {
681
+ compact: {
682
+ controlSm: "1.5rem",
683
+ controlMd: "1.75rem",
684
+ controlLg: "2rem",
685
+ row: "1.75rem",
686
+ gutter: "0.5rem"
687
+ },
688
+ normal: {
689
+ controlSm: "1.75rem",
690
+ controlMd: "2rem",
691
+ controlLg: "2.25rem",
692
+ row: "2rem",
693
+ gutter: "0.75rem"
694
+ },
695
+ spacious: {
696
+ controlSm: "2rem",
697
+ controlMd: "2.25rem",
698
+ controlLg: "2.5rem",
699
+ row: "2.25rem",
700
+ gutter: "1rem"
701
+ },
702
+ touch: {
703
+ controlSm: "2.75rem",
704
+ controlMd: "3rem",
705
+ controlLg: "3.25rem",
706
+ row: "3rem",
707
+ gutter: "0.75rem"
708
+ }
709
+ };
710
+ const radiusScales = {
711
+ none: {
712
+ DEFAULT: "0",
713
+ sm: "0",
714
+ md: "0",
715
+ lg: "0",
716
+ xl: "0"
717
+ },
718
+ small: {
719
+ DEFAULT: "0.25rem",
720
+ sm: "0.125rem",
721
+ md: "0.25rem",
722
+ lg: "0.375rem",
723
+ xl: "0.5rem"
724
+ },
725
+ medium: {
726
+ DEFAULT: "0.5rem",
727
+ sm: "0.25rem",
728
+ md: "0.5rem",
729
+ lg: "0.75rem",
730
+ xl: "1rem"
731
+ },
732
+ large: {
733
+ DEFAULT: "0.75rem",
734
+ sm: "0.5rem",
735
+ md: "0.75rem",
736
+ lg: "1rem",
737
+ xl: "1.5rem"
738
+ },
739
+ rounded: {
740
+ DEFAULT: "0.875rem",
741
+ sm: "0.625rem",
742
+ md: "0.875rem",
743
+ lg: "1.25rem",
744
+ xl: "1.75rem"
745
+ }
746
+ };
747
+
748
+ // src/theme/css-vars.ts
749
+ const SOFT_FAMILIES = [
750
+ "primary",
751
+ "destructive",
752
+ "success",
753
+ "warning",
754
+ "info"
755
+ ];
756
+ /** Soft/ink/deep surfaces for the families that carry them; neutral accent has no family. */
757
+ function softVars(colorSet, mode) {
758
+ const vars = {};
759
+ for (const family of SOFT_FAMILIES) {
760
+ const fill = colorSet[family];
761
+ vars[`--color-${family}-soft`] = softTriplet(fill, mode);
762
+ vars[`--color-${family}-soft-foreground`] = inkTriplet(fill, mode);
763
+ }
764
+ vars["--color-primary-ink"] = inkTriplet(colorSet.primary, mode);
765
+ vars["--color-primary-deep"] = deepTriplet(colorSet.primary);
766
+ return vars;
767
+ }
768
+ /** Same lightness adjustments applyThemeState uses at runtime. */
769
+ function varsForMode(colorSet, mode) {
770
+ const baseForeground = mode === "dark" ? "222 47% 11%" : "0 0% 100%";
771
+ const primaryShift = mode === "dark" ? -5 : 5;
772
+ const surfaceShift = mode === "dark" ? 5 : -5;
773
+ return {
774
+ "--color-primary": colorSet.primary,
775
+ "--color-primary-foreground": colorSet.primaryForeground,
776
+ "--color-primary-hover": adjustLightness(colorSet.primary, primaryShift),
777
+ "--color-primary-active": adjustLightness(colorSet.primary, primaryShift * 2),
778
+ "--color-secondary": colorSet.secondary,
779
+ "--color-secondary-foreground": colorSet.secondaryForeground,
780
+ "--color-secondary-hover": adjustLightness(colorSet.secondary, surfaceShift),
781
+ "--color-secondary-active": adjustLightness(colorSet.secondary, surfaceShift * 2),
782
+ "--color-accent": colorSet.accent,
783
+ "--color-accent-foreground": colorSet.accentForeground,
784
+ "--color-accent-hover": adjustLightness(colorSet.accent, surfaceShift),
785
+ "--color-accent-active": adjustLightness(colorSet.accent, surfaceShift * 2),
786
+ "--color-ring": colorSet.ring,
787
+ "--color-info": colorSet.info,
788
+ "--color-info-foreground": baseForeground,
789
+ "--color-success": colorSet.success,
790
+ "--color-success-foreground": baseForeground,
791
+ "--color-warning": colorSet.warning,
792
+ "--color-warning-foreground": baseForeground,
793
+ "--color-destructive": colorSet.destructive,
794
+ "--color-destructive-foreground": baseForeground,
795
+ "--color-destructive-hover": adjustLightness(colorSet.destructive, primaryShift),
796
+ "--color-destructive-active": adjustLightness(colorSet.destructive, primaryShift * 2),
797
+ ...softVars(colorSet, mode),
798
+ ...alphaVars(mode)
799
+ };
800
+ }
801
+ function varsForState(state) {
802
+ const vars = { "--su-font-sans": fontStacks[state.font] };
803
+ for (const [key, value] of Object.entries(leadingScales[state.font])) vars[`--su-leading-${key}`] = value;
804
+ for (const [key, value] of Object.entries(spaceScales[state.space])) vars[`--su-space-${key}`] = value;
805
+ const density = densityScales[state.space];
806
+ vars["--su-control-h-sm"] = density.controlSm;
807
+ vars["--su-control-h-md"] = density.controlMd;
808
+ vars["--su-control-h-lg"] = density.controlLg;
809
+ vars["--su-row-h"] = density.row;
810
+ vars["--su-gutter"] = density.gutter;
811
+ const radius = radiusScales[state.radius];
812
+ vars["--su-radius"] = radius.DEFAULT;
813
+ vars["--su-radius-sm"] = radius.sm;
814
+ vars["--su-radius-md"] = radius.md;
815
+ vars["--su-radius-lg"] = radius.lg;
816
+ vars["--su-radius-xl"] = radius.xl;
817
+ vars["--su-radius-full"] = "9999px";
818
+ return vars;
819
+ }
820
+ const block = (selector, vars) => `${selector} {\n${Object.entries(vars).map(([k, v]) => `\t${k}: ${v};`).join("\n")}\n}`;
821
+ /**
822
+ * Emit a complete theme.css for a ThemeState — light vars on :root, dark vars
823
+ * under [data-theme="dark"], plus the font/space/radius tokens on :root.
824
+ */
825
+ function cssVarsForTheme(state, color) {
826
+ const resolved = color ?? (state.color === "auto" ? "blue" : state.color);
827
+ const scheme = colorSchemes[resolved];
828
+ return [
829
+ `/* solid-ui theme — color:${resolved} font:${state.font} space:${state.space} radius:${state.radius} */`,
830
+ block(":root", {
831
+ ...varsForMode(scheme.light, "light"),
832
+ ...varsForState(state)
833
+ }),
834
+ block("[data-theme=\"dark\"]", varsForMode(scheme.dark, "dark")),
835
+ ""
836
+ ].join("\n");
837
+ }
838
+ /**
839
+ * Brand override layer: the full primary ramp for both modes, meant to be
840
+ * emitted after cssVarsForTheme so it wins on cascade order.
841
+ */
842
+ function brandCssVars(brand) {
843
+ return [
844
+ block(":root", brandVars(brand, "light")),
845
+ block("[data-theme=\"dark\"]", brandVars(brand, "dark")),
846
+ ""
847
+ ].join("\n");
848
+ }
849
+
850
+ export { tripletContrast as A, contrastRatio as C, isHslTriplet as D, hslTripletToRgb as E, relativeLuminance as O, softTriplet as S, hexToRgb as T, adjustLightness as _, varsForState as a, hsl as b, leadingScales as c, colorSchemes as d, brandForMode as f, readableForeground as g, normalizeBrand as h, varsForMode as i, rgbToHslTriplet as k, radiusScales as l, brandVars as m, cssVarsForTheme as n, densityScales as o, brandRamp as p, softVars as r, fontStacks as s, brandCssVars as t, spaceScales as u, alphaVars as v, hexToHslTriplet as w, inkTriplet as x, deepTriplet as y };