@glasshome/ui 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SPEC.md CHANGED
@@ -171,6 +171,10 @@ gets any motion of its own; a motion need none of them covers is added to
171
171
  slots).
172
172
  - All color comes from theme vars (`var(--primary)` etc.). No hex/oklch
173
173
  literals in components except neutral black/white shadow alphas.
174
+ - Text chrome (`Badge`, `CountPill`, `SectionMeta`, `SectionCard.subtitleClass`)
175
+ merges the caller's classes through `cn`, so `class="text-sm"` is the
176
+ sanctioned size door for a desk-distance surface. The default register stays
177
+ `text-xs`; no component grows a `size` prop for this.
174
178
 
175
179
  ## Extending the system
176
180
 
@@ -3,6 +3,7 @@ interface AreaPickerBaseProps {
3
3
  class?: string;
4
4
  /** false: a re-tap on the picked area keeps it instead of clearing. */
5
5
  allowClear?: boolean;
6
+ /** A read-only caller renders the real picker dimmed, never a plain text line. */
6
7
  disabled?: boolean;
7
8
  /** Id of the element naming the trigger, for forms that label it outside. */
8
9
  "aria-labelledby"?: string;
@@ -2,6 +2,7 @@ import { type Component, type ComponentProps, type JSX, type ParentComponent, ty
2
2
  import { Field, FieldDescription, FieldError, FieldLabel } from "./field.js";
3
3
  import { Input } from "./input.js";
4
4
  declare const Form: ParentComponent<ComponentProps<"form"> & {
5
+ /** Headless: the parent's validation lib owns these; label, control aria-invalid and message all react to them. */
5
6
  errors?: Record<string, string>;
6
7
  onSetError?: (name: string, error: string) => void;
7
8
  onClearError?: (name: string) => void;
@@ -5,3 +5,4 @@
5
5
  export * from "./hex.js";
6
6
  export * from "./presets.js";
7
7
  export * from "./theme-colors.js";
8
+ export { contrastRatio, parseThemeBlock } from "./theme-css.js";
@@ -220,4 +220,28 @@ function C(e) {
220
220
  return x.find((t) => t.id === e);
221
221
  }
222
222
  //#endregion
223
- export { g as DEFAULT_THEME_ID, v as FONT_MONO, _ as FONT_SANS, x as THEME_PRESETS, t as clamp, c as deriveDarkFromLight, u as ensureFullThemeColors, S as getAllPresets, C as getPreset, d as oklchToHex, r as parseOklch, s as resolveThemeColors, i as toOklch };
223
+ //#region src/tokens/theme-css.ts
224
+ function w(e, t) {
225
+ let n = e.match(RegExp(`${t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\{([^}]*)\\}`));
226
+ if (!n) throw Error(`block not found in theme.css: ${t}`);
227
+ let r = {};
228
+ for (let e of (n[1] ?? "").split("\n")) {
229
+ let [, t, n] = e.match(/^\s*(--[\w-]+):\s*(.+?);\s*$/) ?? [];
230
+ t && n && (r[t] = n);
231
+ }
232
+ return r;
233
+ }
234
+ function T(e) {
235
+ let t = d(e), [n, r, i] = [
236
+ 1,
237
+ 3,
238
+ 5
239
+ ].map((e) => Number.parseInt(t.slice(e, e + 2), 16) / 255).map((e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4);
240
+ return .2126 * n + .7152 * r + .0722 * i;
241
+ }
242
+ function E(e, t) {
243
+ let [n, r] = [T(e), T(t)];
244
+ return (Math.max(n, r) + .05) / (Math.min(n, r) + .05);
245
+ }
246
+ //#endregion
247
+ export { g as DEFAULT_THEME_ID, v as FONT_MONO, _ as FONT_SANS, x as THEME_PRESETS, t as clamp, E as contrastRatio, c as deriveDarkFromLight, u as ensureFullThemeColors, S as getAllPresets, C as getPreset, d as oklchToHex, r as parseOklch, w as parseThemeBlock, s as resolveThemeColors, i as toOklch };
@@ -0,0 +1,4 @@
1
+ /** Every custom property declared in one theme.css block (`:root`, `.dark`). */
2
+ export declare function parseThemeBlock(css: string, block: string): Record<string, string>;
3
+ /** WCAG contrast between two oklch() literals. */
4
+ export declare function contrastRatio(a: string, b: string): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/glasshome/ui#readme",
@@ -63,6 +63,7 @@
63
63
  "build": "rm -rf dist && vite build && tsc",
64
64
  "check:structural": "bun scripts/check-structural-classes.ts",
65
65
  "check:dead": "fallow dead-code --fail-on-issues",
66
+ "check:gallery": "bun scripts/check-gallery.ts",
66
67
  "check:styling": "fallow health --css",
67
68
  "check:tokens": "bun scripts/check-tokens.ts",
68
69
  "check:types": "tsc --noEmit -p tsconfig.test.json",
@@ -94,6 +95,9 @@
94
95
  "devDependencies": {
95
96
  "@arethetypeswrong/cli": "^0.18.5",
96
97
  "@biomejs/biome": "2.4.15",
98
+ "@iconify-json/lucide": "^1.2.130",
99
+ "@iconify-json/mdi": "^1.2.3",
100
+ "@iconify-json/simple-icons": "^1.2.95",
97
101
  "@solidjs/testing-library": "^0.8.10",
98
102
  "@tailwindcss/vite": "^4.1.13",
99
103
  "@types/json-schema": "^7.0.15",
@@ -0,0 +1,190 @@
1
+ import { readdirSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import {
5
+ type Identifier,
6
+ isIdentifier,
7
+ isJsxAttribute,
8
+ isJsxElement,
9
+ isJsxSelfClosingElement,
10
+ isStringLiteral,
11
+ type JsxOpeningElement,
12
+ type JsxSelfClosingElement,
13
+ type Node,
14
+ } from "typescript/unstable/ast";
15
+ import {
16
+ API,
17
+ type Checker,
18
+ SignatureKind,
19
+ SymbolFlags,
20
+ type Symbol as TsSymbol,
21
+ } from "typescript/unstable/async";
22
+ import { ALLOW } from "../dev/coverage-allow";
23
+
24
+ const pkg = resolve(dirname(fileURLToPath(import.meta.url)), "..");
25
+ const CONFIG = join(pkg, "tsconfig.test.json");
26
+ const ENTRY = join(pkg, "src/solid/index.ts");
27
+ const GROUPS = join(pkg, "dev/groups");
28
+ const SCREAMING_CASE = /^[A-Z][A-Z0-9_]*$/;
29
+
30
+ export type Component = { name: string; module: string };
31
+ export type SpecimenUse = { name: string; renders: string[] };
32
+ export type Inventory = { exports: string[]; components: Component[]; specimens: SpecimenUse[] };
33
+ export type Report = {
34
+ uncovered: string[];
35
+ unknownSpecimens: string[];
36
+ emptyReasons: string[];
37
+ staleAllows: string[];
38
+ };
39
+ type Allow = ReadonlyArray<readonly [name: string, reason: string]>;
40
+
41
+ export function judge(inventory: Inventory, allow: Allow): Report {
42
+ const moduleOf = new Map(inventory.components.map((c) => [c.name, c.module]));
43
+ const named = new Set(inventory.specimens.map((s) => s.name));
44
+ const exportNames = new Set(inventory.exports);
45
+ const renderedByOwnModule = (c: Component) =>
46
+ inventory.specimens.some(
47
+ (s) => moduleOf.get(s.name) === c.module && s.renders.includes(c.name),
48
+ );
49
+ const uncovered = inventory.components
50
+ .filter((c) => !named.has(c.name) && !renderedByOwnModule(c))
51
+ .map((c) => c.name);
52
+ const unknown = [...named].filter((name) => !exportNames.has(name));
53
+ const allowed = new Set(allow.map(([name]) => name));
54
+ const failing = new Set([...uncovered, ...unknown]);
55
+ return {
56
+ uncovered: uncovered.filter((name) => !allowed.has(name)),
57
+ unknownSpecimens: unknown.filter((name) => !allowed.has(name)),
58
+ emptyReasons: allow.filter(([, reason]) => reason.trim() === "").map(([name]) => name),
59
+ staleAllows: allow.filter(([name]) => !failing.has(name)).map(([name]) => name),
60
+ };
61
+ }
62
+
63
+ async function resolveAlias(checker: Checker, symbol: TsSymbol): Promise<TsSymbol> {
64
+ return symbol.flags & SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
65
+ }
66
+
67
+ async function returnsJsx(checker: Checker, symbol: TsSymbol): Promise<boolean> {
68
+ const type = await checker.getTypeOfSymbol(symbol);
69
+ if (!type) return false;
70
+ const signatures = await checker.getSignaturesOfType(type, SignatureKind.Call);
71
+ if (signatures.length === 0) return false;
72
+ for (const signature of signatures) {
73
+ const returned = await checker.getReturnTypeOfSignature(signature);
74
+ const alias = await returned?.getAliasSymbol();
75
+ const namespace = await alias?.getParent();
76
+ if (alias?.name !== "Element" || namespace?.name !== "JSX") return false;
77
+ }
78
+ return true;
79
+ }
80
+
81
+ function openingOf(node: Node): JsxOpeningElement | JsxSelfClosingElement | undefined {
82
+ if (isJsxElement(node)) return node.openingElement;
83
+ return isJsxSelfClosingElement(node) ? node : undefined;
84
+ }
85
+
86
+ function jsxTag(node: Node): Identifier | undefined {
87
+ const opening = openingOf(node);
88
+ return opening && isIdentifier(opening.tagName) ? opening.tagName : undefined;
89
+ }
90
+
91
+ function specimenName(node: Node): string | undefined {
92
+ const opening = openingOf(node);
93
+ if (!opening || jsxTag(node)?.text !== "Specimen") return undefined;
94
+ for (const attribute of opening.attributes.properties) {
95
+ if (!isJsxAttribute(attribute) || !isIdentifier(attribute.name)) continue;
96
+ if (attribute.name.text !== "name") continue;
97
+ return attribute.initializer && isStringLiteral(attribute.initializer)
98
+ ? attribute.initializer.text
99
+ : "{non-literal name}";
100
+ }
101
+ return "{no name}";
102
+ }
103
+
104
+ export async function collectInventory(): Promise<Inventory> {
105
+ const api = new API({ cwd: pkg });
106
+ try {
107
+ const snapshot = await api.updateSnapshot({ openProjects: [CONFIG] });
108
+ const project = snapshot.getProject(CONFIG);
109
+ if (!project) throw new Error(`typescript did not load ${CONFIG}`);
110
+ const { checker, program } = project;
111
+
112
+ const entry = await program.getSourceFile(ENTRY);
113
+ const entrySymbol = entry && (await checker.getSymbolAtLocation(entry));
114
+ if (!entrySymbol) throw new Error(`typescript did not load ${ENTRY}`);
115
+
116
+ const exports: string[] = [];
117
+ const components: Component[] = [];
118
+ const exportsByTarget = new Map<number, string[]>();
119
+ for (const exported of await checker.getExportsOfModule(entrySymbol)) {
120
+ const target = await resolveAlias(checker, exported);
121
+ if (!(target.flags & SymbolFlags.Value)) continue;
122
+ exports.push(exported.name);
123
+ if (SCREAMING_CASE.test(exported.name) || !(await returnsJsx(checker, target))) continue;
124
+ const declaration = target.valueDeclaration ?? target.declarations[0];
125
+ components.push({ name: exported.name, module: declaration?.path ?? "" });
126
+ exportsByTarget.set(target.id, [...(exportsByTarget.get(target.id) ?? []), exported.name]);
127
+ }
128
+
129
+ const specimens = new Map<string, Set<string>>();
130
+ for (const file of readdirSync(GROUPS).filter((f) => f.endsWith(".tsx"))) {
131
+ const source = await program.getSourceFile(join(GROUPS, file));
132
+ if (!source) throw new Error(`typescript did not load dev/groups/${file}`);
133
+ const tags: Array<{ specimen: string; tag: Node }> = [];
134
+ const visit = (node: Node, specimen: string | undefined) => {
135
+ const name = specimenName(node);
136
+ const inside = name ?? specimen;
137
+ if (name !== undefined && !specimens.has(name)) specimens.set(name, new Set());
138
+ const tag = name === undefined ? jsxTag(node) : undefined;
139
+ if (tag && inside) tags.push({ specimen: inside, tag });
140
+ node.forEachChild((child) => {
141
+ visit(child, inside);
142
+ });
143
+ };
144
+ visit(source, undefined);
145
+
146
+ const symbols = await checker.getSymbolAtLocation(tags.map((t) => t.tag));
147
+ for (const [i, symbol] of symbols.entries()) {
148
+ const use = tags[i];
149
+ if (!symbol || !use) continue;
150
+ const target = await resolveAlias(checker, symbol);
151
+ for (const exported of exportsByTarget.get(target.id) ?? []) {
152
+ specimens.get(use.specimen)?.add(exported);
153
+ }
154
+ }
155
+ }
156
+
157
+ return {
158
+ exports,
159
+ components,
160
+ specimens: [...specimens].map(([name, renders]) => ({ name, renders: [...renders] })),
161
+ };
162
+ } finally {
163
+ await api.close();
164
+ }
165
+ }
166
+
167
+ export async function galleryReport(allow: Allow = ALLOW): Promise<Report> {
168
+ return judge(await collectInventory(), allow);
169
+ }
170
+
171
+ if (process.argv[1] === fileURLToPath(import.meta.url)) {
172
+ const report = await galleryReport();
173
+ const failures = [
174
+ ...report.uncovered.map(
175
+ (name) => `${name}: component export with no <Specimen name="${name}">`,
176
+ ),
177
+ ...report.unknownSpecimens.map(
178
+ (name) => `<Specimen name="${name}">: not an export of src/solid`,
179
+ ),
180
+ ...report.emptyReasons.map((name) => `dev/coverage-allow.ts ${name}: empty reason`),
181
+ ...report.staleAllows.map(
182
+ (name) => `dev/coverage-allow.ts ${name}: nothing to allow any more, drop the entry`,
183
+ ),
184
+ ];
185
+ if (failures.length > 0) {
186
+ console.error(`check:gallery, ${failures.length} failing:\n${failures.join("\n")}`);
187
+ process.exit(1);
188
+ }
189
+ console.log("check:gallery: every component export has a specimen");
190
+ }
@@ -1,7 +1,7 @@
1
1
  // Fails when styles/theme.css and tokens/presets.ts (midnight-glass) drift.
2
2
  import { readFileSync } from "node:fs";
3
3
  import path from "node:path";
4
- import { DEFAULT_THEME_ID, getPreset, type ThemeColors } from "../src/tokens";
4
+ import { DEFAULT_THEME_ID, getPreset, parseThemeBlock, type ThemeColors } from "../src/tokens";
5
5
 
6
6
  const css = readFileSync(
7
7
  path.resolve(path.dirname(new URL(import.meta.url).pathname), "../src/styles/theme.css"),
@@ -23,17 +23,6 @@ const KEYS: Record<string, keyof ThemeColors> = {
23
23
  "--popover": "popover",
24
24
  };
25
25
 
26
- function cssVars(block: string): Record<string, string> {
27
- const match = css.match(new RegExp(`${block}\\s*\\{([^}]*)\\}`));
28
- if (!match) throw new Error(`block not found in theme.css: ${block}`);
29
- const vars: Record<string, string> = {};
30
- for (const line of match[1].split("\n")) {
31
- const m = line.match(/^\s*(--[\w-]+):\s*(.+?);\s*$/);
32
- if (m) vars[m[1]] = m[2];
33
- }
34
- return vars;
35
- }
36
-
37
26
  const preset = getPreset(DEFAULT_THEME_ID);
38
27
  if (!preset) throw new Error(`preset missing: ${DEFAULT_THEME_ID}`);
39
28
 
@@ -42,7 +31,7 @@ for (const [mode, block] of [
42
31
  ["light", ":root"],
43
32
  ["dark", ".dark"],
44
33
  ] as const) {
45
- const vars = cssVars(block);
34
+ const vars = parseThemeBlock(css, block);
46
35
  for (const [cssKey, tokenKey] of Object.entries(KEYS)) {
47
36
  const cssValue = vars[cssKey];
48
37
  const tokenValue = preset.colors[mode][tokenKey];
@@ -15,6 +15,7 @@ interface AreaPickerBaseProps {
15
15
  class?: string;
16
16
  /** false: a re-tap on the picked area keeps it instead of clearing. */
17
17
  allowClear?: boolean;
18
+ /** A read-only caller renders the real picker dimmed, never a plain text line. */
18
19
  disabled?: boolean;
19
20
  /** Id of the element naming the trigger, for forms that label it outside. */
20
21
  "aria-labelledby"?: string;
@@ -36,6 +36,7 @@ type CardProps = ComponentProps<"div"> &
36
36
  ornament?: "arrow" | "check";
37
37
  };
38
38
 
39
+ // The card owns the padding: every part below carries none, and no part has a margin.
39
40
  const Card: Component<CardProps> = (props) => {
40
41
  const [local, others] = splitProps(props, [
41
42
  "class",
@@ -43,6 +43,7 @@ const FormContext = createContext<FormContextValue>();
43
43
 
44
44
  const Form: ParentComponent<
45
45
  ComponentProps<"form"> & {
46
+ /** Headless: the parent's validation lib owns these; label, control aria-invalid and message all react to them. */
46
47
  errors?: Record<string, string>;
47
48
  onSetError?: (name: string, error: string) => void;
48
49
  onClearError?: (name: string) => void;
@@ -43,6 +43,7 @@ type SectionCardProps = {
43
43
  children?: JSX.Element;
44
44
  };
45
45
 
46
+ // The section owns every gap; the header, toolbar and rows inside it add none.
46
47
  export function SectionCard(props: SectionCardProps) {
47
48
  const glass = () => props.glass ?? NOOP_GLASS;
48
49
  const active = () => glass().active?.() ?? false;
@@ -103,6 +103,7 @@ function WidgetCardTile(props: InternalProps) {
103
103
  padding="md"
104
104
  class={cn("group h-full", props.class)}
105
105
  >
106
+ {/* flex-1 body: the meta stays pinned to the tile's foot whether the description is long, missing or off. */}
106
107
  <div data-slot="widget-card-body" class="flex flex-1 flex-col gap-3">
107
108
  <WidgetIdentity widget={props.widget} iconSize="md" showVersionInline={false} />
108
109
  <Show when={showDescription() && props.widget.description}>
@@ -6,3 +6,4 @@
6
6
  export * from "./hex.js";
7
7
  export * from "./presets.js";
8
8
  export * from "./theme-colors.js";
9
+ export { contrastRatio, parseThemeBlock } from "./theme-css.js";
@@ -0,0 +1,34 @@
1
+ import { oklchToHex } from "./hex.js";
2
+
3
+ /** Every custom property declared in one theme.css block (`:root`, `.dark`). */
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;
16
+ }
17
+
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;
28
+ }
29
+
30
+ /** WCAG contrast between two oklch() literals. */
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);
34
+ }