@glasshome/ui 1.21.1 → 1.22.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.
Files changed (146) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/lib/use-is-mobile.d.ts +3 -1
  4. package/dist/solid/index.d.ts +9 -9
  5. package/dist/solid/index.js +5431 -5424
  6. package/dist/solid/sonner.d.ts +1 -0
  7. package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
  8. package/package.json +128 -126
  9. package/scripts/check-gallery.ts +142 -142
  10. package/scripts/check-pack.ts +13 -13
  11. package/scripts/check-structural-classes.ts +20 -20
  12. package/scripts/check-tokens.ts +27 -27
  13. package/scripts/check-ui-drift.mjs +103 -103
  14. package/src/index.ts +75 -80
  15. package/src/lib/alert-tones.ts +41 -41
  16. package/src/lib/anchor-placement.ts +21 -21
  17. package/src/lib/button-variants.ts +28 -28
  18. package/src/lib/card-classes.ts +9 -9
  19. package/src/lib/carousel-classes.ts +14 -14
  20. package/src/lib/glass-tone.ts +11 -11
  21. package/src/lib/input-classes.ts +6 -6
  22. package/src/lib/layers.ts +4 -4
  23. package/src/lib/logo-lockup.ts +8 -8
  24. package/src/lib/menu-classes.ts +2 -2
  25. package/src/lib/motion-classes.ts +8 -8
  26. package/src/lib/motion-window.ts +24 -24
  27. package/src/lib/overlay-classes.ts +6 -6
  28. package/src/lib/pill-classes.ts +3 -3
  29. package/src/lib/position-bar-classes.ts +1 -1
  30. package/src/lib/spotlight-geometry.ts +67 -67
  31. package/src/lib/thumb-classes.ts +2 -2
  32. package/src/lib/tier-badge.ts +16 -16
  33. package/src/lib/use-is-mobile.ts +17 -14
  34. package/src/lib/utils.ts +1 -1
  35. package/src/solid/accordion.tsx +41 -41
  36. package/src/solid/alert-dialog.tsx +95 -95
  37. package/src/solid/alert.tsx +88 -88
  38. package/src/solid/area-picker.tsx +204 -204
  39. package/src/solid/aspect-ratio.tsx +13 -13
  40. package/src/solid/avatar.tsx +27 -27
  41. package/src/solid/badge.tsx +49 -49
  42. package/src/solid/bottom-sheet/arbitration.ts +22 -22
  43. package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
  44. package/src/solid/bottom-sheet/drag-controller.ts +201 -201
  45. package/src/solid/bottom-sheet/focus-trap.ts +51 -47
  46. package/src/solid/bottom-sheet/index.ts +12 -12
  47. package/src/solid/bottom-sheet/keyboard.ts +25 -25
  48. package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
  49. package/src/solid/bottom-sheet/state-machine.ts +28 -28
  50. package/src/solid/bottom-sheet/velocity.ts +29 -29
  51. package/src/solid/breadcrumb.tsx +76 -76
  52. package/src/solid/button-group.tsx +46 -46
  53. package/src/solid/button.tsx +19 -19
  54. package/src/solid/card.tsx +67 -67
  55. package/src/solid/carousel.tsx +246 -246
  56. package/src/solid/charts.tsx +253 -253
  57. package/src/solid/checkbox.tsx +51 -51
  58. package/src/solid/collapsible.tsx +22 -22
  59. package/src/solid/color-disc.tsx +213 -213
  60. package/src/solid/color-slider.tsx +81 -81
  61. package/src/solid/color-wheel.tsx +61 -61
  62. package/src/solid/context-menu.tsx +63 -63
  63. package/src/solid/copy-button.tsx +31 -31
  64. package/src/solid/count-pill.tsx +11 -11
  65. package/src/solid/dashboard-preview.tsx +104 -104
  66. package/src/solid/data-table.tsx +228 -228
  67. package/src/solid/dialog-parts.tsx +127 -127
  68. package/src/solid/dialog.tsx +113 -113
  69. package/src/solid/dock-paging.ts +9 -9
  70. package/src/solid/dock.tsx +339 -339
  71. package/src/solid/docked-panel.tsx +35 -35
  72. package/src/solid/dropdown-menu.tsx +77 -77
  73. package/src/solid/empty.tsx +70 -70
  74. package/src/solid/entity-data.ts +38 -38
  75. package/src/solid/entity-selector.tsx +634 -634
  76. package/src/solid/field.tsx +205 -205
  77. package/src/solid/form.tsx +159 -159
  78. package/src/solid/hero-action.tsx +85 -85
  79. package/src/solid/hover-card.tsx +11 -11
  80. package/src/solid/icon-picker.tsx +401 -401
  81. package/src/solid/icon.tsx +101 -78
  82. package/src/solid/image-picker.tsx +416 -414
  83. package/src/solid/index.ts +265 -304
  84. package/src/solid/input-group.tsx +123 -123
  85. package/src/solid/input-otp.tsx +143 -143
  86. package/src/solid/input.tsx +4 -4
  87. package/src/solid/item.tsx +130 -130
  88. package/src/solid/kbd.tsx +20 -20
  89. package/src/solid/label.tsx +12 -12
  90. package/src/solid/list-reorder.ts +122 -122
  91. package/src/solid/logo.tsx +60 -60
  92. package/src/solid/media-copy.ts +21 -21
  93. package/src/solid/media-store.ts +56 -56
  94. package/src/solid/media-tile.tsx +85 -85
  95. package/src/solid/menu-parts.tsx +164 -164
  96. package/src/solid/number-field.tsx +56 -56
  97. package/src/solid/option-card.tsx +164 -164
  98. package/src/solid/ornament.tsx +43 -43
  99. package/src/solid/overlay.tsx +4 -4
  100. package/src/solid/page-header.tsx +75 -75
  101. package/src/solid/pagination.tsx +80 -80
  102. package/src/solid/password-input.tsx +51 -51
  103. package/src/solid/picker-row.tsx +83 -83
  104. package/src/solid/picker-search.tsx +65 -63
  105. package/src/solid/picker-trigger.tsx +59 -57
  106. package/src/solid/popover.tsx +54 -54
  107. package/src/solid/preview-tile.tsx +67 -67
  108. package/src/solid/progress.tsx +21 -21
  109. package/src/solid/radio-group.tsx +51 -51
  110. package/src/solid/resizable.tsx +128 -128
  111. package/src/solid/responsive-dialog.tsx +134 -134
  112. package/src/solid/schema-form.tsx +743 -743
  113. package/src/solid/scope-indicator.tsx +5 -5
  114. package/src/solid/scroll-area.tsx +16 -16
  115. package/src/solid/section-card.tsx +281 -281
  116. package/src/solid/select.tsx +101 -101
  117. package/src/solid/separator.tsx +25 -25
  118. package/src/solid/settings-row.tsx +122 -122
  119. package/src/solid/sheet.tsx +96 -96
  120. package/src/solid/skeleton.tsx +8 -8
  121. package/src/solid/slider.tsx +132 -132
  122. package/src/solid/sliding-indicator.tsx +280 -265
  123. package/src/solid/sonner.tsx +165 -164
  124. package/src/solid/spinner.tsx +12 -12
  125. package/src/solid/spotlight.tsx +140 -140
  126. package/src/solid/step-indicator.tsx +18 -18
  127. package/src/solid/swatch-picker.tsx +38 -38
  128. package/src/solid/switch.tsx +52 -52
  129. package/src/solid/table.tsx +63 -63
  130. package/src/solid/tabs.tsx +93 -93
  131. package/src/solid/textarea.tsx +8 -8
  132. package/src/solid/toggle-group.tsx +83 -83
  133. package/src/solid/toggle.tsx +33 -33
  134. package/src/solid/tooltip.tsx +16 -16
  135. package/src/solid/widget-card.tsx +90 -90
  136. package/src/solid/widget-identity.tsx +99 -99
  137. package/src/solid/widget-trust-badge.tsx +20 -20
  138. package/src/styles/globals.css +316 -319
  139. package/src/styles/theme.css +448 -448
  140. package/src/tokens/hex.ts +29 -29
  141. package/src/tokens/material.ts +75 -75
  142. package/src/tokens/presets.ts +303 -303
  143. package/src/tokens/readability.ts +32 -32
  144. package/src/tokens/theme-colors.ts +95 -95
  145. package/src/tokens/theme-css.ts +22 -22
  146. package/src/tokens/theme-recipe.ts +106 -106
@@ -4,46 +4,46 @@ import { contrastRatio } from "./theme-css.js";
4
4
  type Key = keyof ThemeColors;
5
5
 
6
6
  export interface ReadablePair {
7
- /** The color read as text, an icon or an indicator. */
8
- text: Key;
9
- surface: Key;
10
- /** 4.5 for text, 3 for icons and indicators (WCAG AA). */
11
- min: 4.5 | 3;
7
+ /** The color read as text, an icon or an indicator. */
8
+ text: Key;
9
+ surface: Key;
10
+ /** 4.5 for text, 3 for icons and indicators (WCAG AA). */
11
+ min: 4.5 | 3;
12
12
  }
13
13
 
14
14
  /* Foregrounds on the ground, cards and fills are picked black-or-white by
15
15
  * contrast, which always clears 4.5, so they are absent here. These are the
16
16
  * colors a theme author sets that are read against a surface. */
17
17
  export const READABLE_PAIRS: ReadablePair[] = [
18
- { text: "mutedForeground", surface: "background", min: 4.5 },
19
- { text: "mutedForeground", surface: "card", min: 4.5 },
20
- { text: "mutedForeground", surface: "muted", min: 4.5 },
21
- { text: "destructive", surface: "background", min: 4.5 },
22
- { text: "destructive", surface: "card", min: 4.5 },
23
- { text: "primary", surface: "background", min: 3 },
24
- { text: "primary", surface: "card", min: 3 },
25
- { text: "ring", surface: "background", min: 3 },
18
+ { text: "mutedForeground", surface: "background", min: 4.5 },
19
+ { text: "mutedForeground", surface: "card", min: 4.5 },
20
+ { text: "mutedForeground", surface: "muted", min: 4.5 },
21
+ { text: "destructive", surface: "background", min: 4.5 },
22
+ { text: "destructive", surface: "card", min: 4.5 },
23
+ { text: "primary", surface: "background", min: 3 },
24
+ { text: "primary", surface: "card", min: 3 },
25
+ { text: "ring", surface: "background", min: 3 },
26
26
  ];
27
27
 
28
28
  export interface ReadabilityIssue extends ReadablePair {
29
- ratio: number;
29
+ ratio: number;
30
30
  }
31
31
 
32
32
  export function findUnreadable(colors: ThemeColors): ReadabilityIssue[] {
33
- return READABLE_PAIRS.flatMap((pair) => {
34
- const ratio = contrastRatio(colors[pair.text], colors[pair.surface]);
35
- return ratio >= pair.min ? [] : [{ ...pair, ratio }];
36
- });
33
+ return READABLE_PAIRS.flatMap((pair) => {
34
+ const ratio = contrastRatio(colors[pair.text], colors[pair.surface]);
35
+ return ratio >= pair.min ? [] : [{ ...pair, ratio }];
36
+ });
37
37
  }
38
38
 
39
39
  const STEP = 0.01;
40
40
 
41
41
  function surfacesOf(text: Key): ReadablePair[] {
42
- return READABLE_PAIRS.filter((pair) => pair.text === text);
42
+ return READABLE_PAIRS.filter((pair) => pair.text === text);
43
43
  }
44
44
 
45
45
  function clears(candidate: string, colors: ThemeColors, pairs: ReadablePair[]): boolean {
46
- return pairs.every((pair) => contrastRatio(candidate, colors[pair.surface]) >= pair.min);
46
+ return pairs.every((pair) => contrastRatio(candidate, colors[pair.surface]) >= pair.min);
47
47
  }
48
48
 
49
49
  /**
@@ -52,16 +52,16 @@ function clears(candidate: string, colors: ThemeColors, pairs: ReadablePair[]):
52
52
  * (one dark, one light), and only a different surface fixes that.
53
53
  */
54
54
  export function fixReadable(colors: ThemeColors, text: Key): string | null {
55
- const parsed = parseOklch(colors[text]);
56
- if (!parsed) return null;
57
- const pairs = surfacesOf(text);
58
- for (let distance = STEP; distance <= 1; distance += STEP) {
59
- for (const direction of [-1, 1]) {
60
- const l = parsed.l + direction * distance;
61
- if (l < 0 || l > 1) continue;
62
- const candidate = toOklch(clamp(Number(l.toFixed(4)), 0, 1), parsed.c, parsed.h);
63
- if (clears(candidate, colors, pairs)) return candidate;
64
- }
65
- }
66
- return null;
55
+ const parsed = parseOklch(colors[text]);
56
+ if (!parsed) return null;
57
+ const pairs = surfacesOf(text);
58
+ for (let distance = STEP; distance <= 1; distance += STEP) {
59
+ for (const direction of [-1, 1]) {
60
+ const l = parsed.l + direction * distance;
61
+ if (l < 0 || l > 1) continue;
62
+ const candidate = toOklch(clamp(Number(l.toFixed(4)), 0, 1), parsed.c, parsed.h);
63
+ if (clears(candidate, colors, pairs)) return candidate;
64
+ }
65
+ }
66
+ return null;
67
67
  }
@@ -4,90 +4,90 @@
4
4
  */
5
5
 
6
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;
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
19
  }
20
20
 
21
21
  export interface ThemeColorsConfig {
22
- light: ThemeColors;
23
- dark: ThemeColors;
22
+ light: ThemeColors;
23
+ dark: ThemeColors;
24
24
  }
25
25
 
26
26
  export interface BackgroundLayer {
27
- type: "solid" | "static" | "custom";
28
- id: string;
29
- fit?: "cover" | "contain" | "tile";
30
- /** 0 to 1: how far the wallpaper fades toward `--background`. */
31
- overlay?: number;
32
- /** 0 to 20, in px. */
33
- blur?: number;
34
- /** 0 to 1: how dark the corners fall. */
35
- vignette?: number;
27
+ type: "solid" | "static" | "custom";
28
+ id: string;
29
+ fit?: "cover" | "contain" | "tile";
30
+ /** 0 to 1: how far the wallpaper fades toward `--background`. */
31
+ overlay?: number;
32
+ /** 0 to 20, in px. */
33
+ blur?: number;
34
+ /** 0 to 1: how dark the corners fall. */
35
+ vignette?: number;
36
36
  }
37
37
 
38
38
  /** The picture alone; visibility and softness belong to the theme, the same in both modes. */
39
39
  export type BackgroundImage = Pick<BackgroundLayer, "type" | "id" | "fit">;
40
40
 
41
41
  export interface BackgroundConfig extends BackgroundLayer {
42
- themed: boolean;
43
- url?: string;
44
- /** Shown in dark mode instead of the top-level picture. */
45
- dark?: BackgroundImage;
42
+ themed: boolean;
43
+ url?: string;
44
+ /** Shown in dark mode instead of the top-level picture. */
45
+ dark?: BackgroundImage;
46
46
  }
47
47
 
48
48
  /** The 6 base colors used as input for resolving a full ThemeColors */
49
49
  export type ThemeBaseColors = Pick<
50
- ThemeColors,
51
- "primary" | "accent" | "secondary" | "border" | "card" | "background"
50
+ ThemeColors,
51
+ "primary" | "accent" | "secondary" | "border" | "card" | "background"
52
52
  >;
53
53
 
54
54
  const OKLCH_REGEX =
55
- /^oklch\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))\s*\)$/i;
55
+ /^oklch\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))\s*\)$/i;
56
56
 
57
57
  export function clamp(value: number, min: number, max: number) {
58
- return Math.min(Math.max(value, min), max);
58
+ return Math.min(Math.max(value, min), max);
59
59
  }
60
60
 
61
61
  function formatNumber(value: number) {
62
- if (Number.isInteger(value)) return String(value);
63
- return String(Number(value.toFixed(6)));
62
+ if (Number.isInteger(value)) return String(value);
63
+ return String(Number(value.toFixed(6)));
64
64
  }
65
65
 
66
66
  export function parseOklch(input: string): { l: number; c: number; h: number } | null {
67
- const match = OKLCH_REGEX.exec(input.trim());
68
- if (!match) return null;
69
- return {
70
- l: Number(match[1]),
71
- c: Number(match[2]),
72
- h: Number(match[3]),
73
- };
67
+ const match = OKLCH_REGEX.exec(input.trim());
68
+ if (!match) return null;
69
+ return {
70
+ l: Number(match[1]),
71
+ c: Number(match[2]),
72
+ h: Number(match[3]),
73
+ };
74
74
  }
75
75
 
76
76
  export function toOklch(l: number, c: number, h: number): string {
77
- return `oklch(${formatNumber(l)} ${formatNumber(c)} ${formatNumber(h)})`;
77
+ return `oklch(${formatNumber(l)} ${formatNumber(c)} ${formatNumber(h)})`;
78
78
  }
79
79
 
80
80
  function adjustLightness(oklch: string, delta: number): string {
81
- const parsed = parseOklch(oklch);
82
- if (!parsed) return oklch;
83
- const l = clamp(parsed.l + delta, 0, 1);
84
- return toOklch(l, parsed.c, parsed.h);
81
+ const parsed = parseOklch(oklch);
82
+ if (!parsed) return oklch;
83
+ const l = clamp(parsed.l + delta, 0, 1);
84
+ return toOklch(l, parsed.c, parsed.h);
85
85
  }
86
86
 
87
87
  function invertLightness(oklch: string, targetL: number): string {
88
- const parsed = parseOklch(oklch);
89
- if (!parsed) return oklch;
90
- return toOklch(clamp(targetL, 0, 1), clamp(parsed.c * 0.8, 0, 0.4), parsed.h);
88
+ const parsed = parseOklch(oklch);
89
+ if (!parsed) return oklch;
90
+ return toOklch(clamp(targetL, 0, 1), clamp(parsed.c * 0.8, 0, 0.4), parsed.h);
91
91
  }
92
92
 
93
93
  /**
@@ -95,49 +95,49 @@ function invertLightness(oklch: string, targetL: number): string {
95
95
  * Used for presets and for backwards-compat with old DB data.
96
96
  */
97
97
  export function resolveThemeColors(base: ThemeBaseColors, mode: "light" | "dark"): ThemeColors {
98
- return {
99
- ...base,
100
- popover: base.card,
101
- muted:
102
- mode === "light"
103
- ? adjustLightness(base.background, -0.015)
104
- : adjustLightness(base.background, 0.1),
105
- mutedForeground: mode === "light" ? "oklch(0.44 0 0)" : "oklch(0.71 0 0)",
106
- input:
107
- mode === "light" ? adjustLightness(base.border, 0.01) : adjustLightness(base.border, 0.04),
108
- ring: base.accent,
109
- /* Fixed per mode, not derived: destructive is read as text and as a filled
110
- * surface with white on it, so both ends are contrast-tuned against the
111
- * theme's ground rather than against whatever accent the preset picked. */
112
- destructive: mode === "light" ? "oklch(0.54 0.19 23.0704)" : "oklch(0.7106 0.1661 22.2162)",
113
- };
98
+ return {
99
+ ...base,
100
+ popover: base.card,
101
+ muted:
102
+ mode === "light"
103
+ ? adjustLightness(base.background, -0.015)
104
+ : adjustLightness(base.background, 0.1),
105
+ mutedForeground: mode === "light" ? "oklch(0.44 0 0)" : "oklch(0.71 0 0)",
106
+ input:
107
+ mode === "light" ? adjustLightness(base.border, 0.01) : adjustLightness(base.border, 0.04),
108
+ ring: base.accent,
109
+ /* Fixed per mode, not derived: destructive is read as text and as a filled
110
+ * surface with white on it, so both ends are contrast-tuned against the
111
+ * theme's ground rather than against whatever accent the preset picked. */
112
+ destructive: mode === "light" ? "oklch(0.54 0.19 23.0704)" : "oklch(0.7106 0.1661 22.2162)",
113
+ };
114
114
  }
115
115
 
116
116
  export function deriveDarkFromLight(light: ThemeBaseColors): ThemeColors {
117
- const darkBase: ThemeBaseColors = {
118
- primary: adjustLightness(light.primary, 0.15),
119
- accent: adjustLightness(light.accent, 0.1),
120
- secondary: invertLightness(light.secondary, 0.14),
121
- border: invertLightness(light.border, 0.26),
122
- card: invertLightness(light.card, 0.17),
123
- background: invertLightness(light.background, 0.12),
124
- };
125
- return resolveThemeColors(darkBase, "dark");
117
+ const darkBase: ThemeBaseColors = {
118
+ primary: adjustLightness(light.primary, 0.15),
119
+ accent: adjustLightness(light.accent, 0.1),
120
+ secondary: invertLightness(light.secondary, 0.14),
121
+ border: invertLightness(light.border, 0.26),
122
+ card: invertLightness(light.card, 0.17),
123
+ background: invertLightness(light.background, 0.12),
124
+ };
125
+ return resolveThemeColors(darkBase, "dark");
126
126
  }
127
127
 
128
128
  const THEME_COLOR_KEYS: (keyof ThemeColors)[] = [
129
- "primary",
130
- "accent",
131
- "secondary",
132
- "border",
133
- "card",
134
- "background",
135
- "muted",
136
- "mutedForeground",
137
- "input",
138
- "ring",
139
- "destructive",
140
- "popover",
129
+ "primary",
130
+ "accent",
131
+ "secondary",
132
+ "border",
133
+ "card",
134
+ "background",
135
+ "muted",
136
+ "mutedForeground",
137
+ "input",
138
+ "ring",
139
+ "destructive",
140
+ "popover",
141
141
  ];
142
142
 
143
143
  /**
@@ -145,15 +145,15 @@ const THEME_COLOR_KEYS: (keyof ThemeColors)[] = [
145
145
  * Existing values are preserved; missing ones are resolved from the base colors.
146
146
  */
147
147
  export function ensureFullThemeColors(
148
- partial: ThemeBaseColors & Partial<ThemeColors>,
149
- mode: "light" | "dark",
148
+ partial: ThemeBaseColors & Partial<ThemeColors>,
149
+ mode: "light" | "dark",
150
150
  ): ThemeColors {
151
- const resolved = resolveThemeColors(partial, mode);
152
- const result = { ...resolved };
153
- for (const key of THEME_COLOR_KEYS) {
154
- if (partial[key]) {
155
- result[key] = partial[key];
156
- }
157
- }
158
- return result;
151
+ const resolved = resolveThemeColors(partial, mode);
152
+ const result = { ...resolved };
153
+ for (const key of THEME_COLOR_KEYS) {
154
+ if (partial[key]) {
155
+ result[key] = partial[key];
156
+ }
157
+ }
158
+ return result;
159
159
  }
@@ -2,33 +2,33 @@ import { oklchToHex } from "./hex.js";
2
2
 
3
3
  /** Every custom property declared in one theme.css block (`:root`, `.dark`). */
4
4
  export function parseThemeBlock(css: string, block: string): Record<string, string> {
5
- const match = css.match(
6
- new RegExp(`${block.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\{([^}]*)\\}`),
7
- );
8
- if (!match) throw new Error(`block not found in theme.css: ${block}`);
9
- const vars: Record<string, string> = {};
10
- for (const line of (match[1] ?? "").split("\n")) {
11
- const m = line.match(/^\s*(--[\w-]+):\s*(.+?);\s*$/);
12
- const [, name, value] = m ?? [];
13
- if (name && value) vars[name] = value;
14
- }
15
- return vars;
5
+ const match = css.match(
6
+ new RegExp(`${block.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\{([^}]*)\\}`),
7
+ );
8
+ if (!match) throw new Error(`block not found in theme.css: ${block}`);
9
+ const vars: Record<string, string> = {};
10
+ for (const line of (match[1] ?? "").split("\n")) {
11
+ const m = line.match(/^\s*(--[\w-]+):\s*(.+?);\s*$/);
12
+ const [, name, value] = m ?? [];
13
+ if (name && value) vars[name] = value;
14
+ }
15
+ return vars;
16
16
  }
17
17
 
18
18
  function luminance(oklch: string): number {
19
- const hex = oklchToHex(oklch);
20
- const [r, g, b] = [1, 3, 5]
21
- .map((i) => Number.parseInt(hex.slice(i, i + 2), 16) / 255)
22
- .map((c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4)) as [
23
- number,
24
- number,
25
- number,
26
- ];
27
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
19
+ const hex = oklchToHex(oklch);
20
+ const [r, g, b] = [1, 3, 5]
21
+ .map((i) => Number.parseInt(hex.slice(i, i + 2), 16) / 255)
22
+ .map((c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4)) as [
23
+ number,
24
+ number,
25
+ number,
26
+ ];
27
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
28
28
  }
29
29
 
30
30
  /** WCAG contrast between two oklch() literals. */
31
31
  export function contrastRatio(a: string, b: string): number {
32
- const [x, y] = [luminance(a), luminance(b)];
33
- return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
32
+ const [x, y] = [luminance(a), luminance(b)];
33
+ return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
34
34
  }