Add utility-first CSS layer and expand component library

This commit is contained in:
2026-11-19 22:53:02 +01:00
parent 69107b7b84
commit d87d22cf0e
17 changed files with 834 additions and 96 deletions
+25
View File
@@ -0,0 +1,25 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("..", import.meta.url));
const output = resolve(root, "dist");
const layers = {
"frost.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "utilities.css"],
"utility-layer.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "utilities.css"],
"component-layer.css": ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css"],
};
const minify = (source) => source
.replace(/\/\*[^!*][\s\S]*?\*\//g, "")
.replace(/\s+/g, " ")
.replace(/\s*([{}:;,>])\s*/g, "$1")
.trim();
await mkdir(output, { recursive: true });
for (const [name, files] of Object.entries(layers)) {
const source = (await Promise.all(files.map((file) => readFile(resolve(root, file), "utf8")))).join("\n");
await writeFile(resolve(output, name), `${source}\n`);
await writeFile(resolve(output, name.replace(".css", ".min.css")), `${minify(source)}\n`);
}
console.log(`Built ${Object.keys(layers).length} CSS entry points in dist/.`);
+26
View File
@@ -0,0 +1,26 @@
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("..", import.meta.url));
const html = await readFile(resolve(root, "examples/index.html"), "utf8");
const required = [
"frost-md:grid-cols-2",
"frost-hover:shadow",
"frost-navbar",
"frost-breadcrumbs",
"frost-tabs",
"frost-accordion",
"frost-table",
"frost-spinner",
"#theme-toggle",
"#menu-trigger",
];
const errors = required.filter((value) => !html.includes(value)).map((value) => `examples/index.html: missing demo marker ${value}`);
if (!html.includes("aria-selected") || !html.includes("aria-expanded")) errors.push("examples/index.html: interactive ARIA state markers are missing");
if (errors.length) {
console.error(errors.join("\n"));
process.exitCode = 1;
} else {
console.log(`Checked ${required.length} utility, component, and interaction markers in examples/index.html.`);
}
+38
View File
@@ -5,12 +5,16 @@ import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("..", import.meta.url));
const cssFiles = [
"frost.css",
"core.css",
"utility-layer.css",
"component-layer.css",
"tokens.css",
"base.css",
"accessibility.css",
"layout.css",
"controls.css",
"components.css",
"utilities.css",
];
const errors = [];
@@ -30,6 +34,40 @@ for (const match of entry.matchAll(/@import\s+url\("([^"]+)"\)/g)) {
catch { errors.push(`frost.css: missing import ${match[1]}`); }
}
const layerSources = {
"core.css": ["tokens.css", "base.css", "accessibility.css"],
"utility-layer.css": ["core.css", "layout.css", "utilities.css"],
"component-layer.css": ["core.css", "layout.css", "controls.css", "components.css"],
};
for (const [file, requiredImports] of Object.entries(layerSources)) {
const source = await readFile(resolve(root, file), "utf8");
for (const requiredImport of requiredImports) {
if (!source.includes(`./${requiredImport}`)) errors.push(`${file}: missing layer import ${requiredImport}`);
}
}
const utilityLayerSource = await readFile(resolve(root, "utility-layer.css"), "utf8");
const componentLayerSource = await readFile(resolve(root, "component-layer.css"), "utf8");
if (utilityLayerSource.includes("./controls.css") || utilityLayerSource.includes("./components.css")) errors.push("utility-layer.css: component layer leaked into utility entry point");
if (componentLayerSource.includes("./utilities.css")) errors.push("component-layer.css: utility layer leaked into component entry point");
const utilitySource = await readFile(resolve(root, "utilities.css"), "utf8");
for (const utility of ["frost-flex", "frost-grid", "frost-gap-4", "frost-p-4", "frost-md\\:grid-cols-2", "frost-hover\\:bg-soft"]) {
if (!utilitySource.includes(`.${utility}`)) errors.push(`utilities.css: missing public utility ${utility}`);
}
const componentsSource = await readFile(resolve(root, "components.css"), "utf8");
for (const component of ["frost-navbar", "frost-breadcrumbs", "frost-tabs", "frost-accordion", "frost-pagination", "frost-table", "frost-spinner"]) {
if (!componentsSource.includes(`.${component}`)) errors.push(`components.css: missing public component ${component}`);
}
const packageJson = JSON.parse(await readFile(resolve(root, "package.json"), "utf8"));
for (const exportPath of ["./utilities", "./components", "./tokens"]) {
if (!packageJson.exports[exportPath]) errors.push(`package.json: missing export ${exportPath}`);
}
for (const exportPath of ["./core", "./utility-layer", "./component-layer"]) {
if (!packageJson.exports[exportPath]) errors.push(`package.json: missing layer export ${exportPath}`);
}
if (errors.length) {
console.error(errors.join("\n"));
process.exitCode = 1;
+55
View File
@@ -0,0 +1,55 @@
import { writeFile } from "node:fs/promises";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("..", import.meta.url));
const spaces = ["0", "1", "2", "3", "4", "5", "6", "8", "10", "12", "16"];
const breakpoints = { md: "48rem", lg: "64rem" };
const lines = ["@layer frost.utilities {", " /* Generated by scripts/generate-utilities.mjs. Edit the generator, not this file. */"];
const add = (name, declaration) => lines.push(` .frost-${name} { ${declaration}; }`);
const addVariant = (variant, name, declaration, pseudo = "") => lines.push(` .frost-${variant}\\:${name}${pseudo} { ${declaration}; }`);
const declarations = [
["block", "display: block"], ["inline-block", "display: inline-block"], ["inline", "display: inline"], ["flex", "display: flex"], ["inline-flex", "display: inline-flex"], ["grid", "display: grid"], ["hidden", "display: none !important"], ["visible", "visibility: visible"], ["invisible", "visibility: hidden"],
["relative", "position: relative"], ["absolute", "position: absolute"], ["fixed", "position: fixed"], ["sticky", "position: sticky"], ["flex-wrap", "flex-wrap: wrap"], ["flex-nowrap", "flex-wrap: nowrap"], ["flex-row", "flex-direction: row"], ["flex-col", "flex-direction: column"], ["flex-1", "flex: 1 1 0%"], ["flex-auto", "flex: 1 1 auto"], ["flex-none", "flex: none"], ["grow", "flex-grow: 1"], ["grow-0", "flex-grow: 0"], ["shrink", "flex-shrink: 1"], ["shrink-0", "flex-shrink: 0"], ["min-w-0", "min-width: 0"], ["w-full", "width: 100%"], ["h-full", "height: 100%"], ["w-screen", "width: 100vw"], ["h-screen", "height: 100vh"], ["min-h-screen", "min-height: 100vh"],
["items-start", "align-items: flex-start"], ["items-center", "align-items: center"], ["items-end", "align-items: flex-end"], ["items-stretch", "align-items: stretch"], ["justify-start", "justify-content: flex-start"], ["justify-center", "justify-content: center"], ["justify-end", "justify-content: flex-end"], ["justify-between", "justify-content: space-between"], ["justify-around", "justify-content: space-around"], ["justify-evenly", "justify-content: space-evenly"], ["content-center", "align-content: center"], ["self-start", "align-self: flex-start"], ["self-center", "align-self: center"], ["self-end", "align-self: flex-end"], ["place-items-center", "place-items: center"], ["text-left", "text-align: left"], ["text-center", "text-align: center"], ["text-right", "text-align: right"], ["text-start", "text-align: start"], ["text-end", "text-align: end"], ["truncate", "overflow: hidden; text-overflow: ellipsis; white-space: nowrap"], ["overflow-hidden", "overflow: hidden"], ["overflow-auto", "overflow: auto"], ["overflow-x-auto", "overflow-x: auto"],
["border", "border: 1px solid var(--frost-color-border)"], ["border-strong", "border: 1px solid var(--frost-color-border-strong)"], ["border-0", "border: 0"], ["rounded-sm", "border-radius: var(--frost-radius-sm)"], ["rounded", "border-radius: var(--frost-radius-md)"], ["rounded-lg", "border-radius: var(--frost-radius-lg)"], ["rounded-xl", "border-radius: var(--frost-radius-xl)"], ["rounded-pill", "border-radius: var(--frost-radius-pill)"], ["rounded-full", "border-radius: 9999px"], ["shadow-sm", "box-shadow: var(--frost-shadow-sm)"], ["shadow", "box-shadow: var(--frost-shadow-md)"], ["shadow-lg", "box-shadow: var(--frost-shadow-lg)"], ["shadow-none", "box-shadow: none"],
["font-normal", "font-weight: 400"], ["font-medium", "font-weight: 500"], ["font-semibold", "font-weight: 650"], ["font-bold", "font-weight: 700"], ["font-mono", "font-family: var(--frost-font-mono)"], ["leading-body", "line-height: var(--frost-line-height-body)"], ["leading-heading", "line-height: var(--frost-line-height-heading)"], ["leading-none", "line-height: 1"], ["uppercase", "text-transform: uppercase"], ["lowercase", "text-transform: lowercase"], ["italic", "font-style: italic"],
["text", "color: var(--frost-color-text)"], ["text-muted", "color: var(--frost-color-text-muted)"], ["text-accent", "color: var(--frost-color-accent)"], ["text-success", "color: var(--frost-color-success)"], ["text-warning", "color: var(--frost-color-warning)"], ["text-danger", "color: var(--frost-color-danger)"], ["text-link", "color: var(--frost-color-link)"], ["bg", "background-color: var(--frost-color-bg)"], ["bg-surface", "background-color: var(--frost-color-surface)"], ["bg-soft", "background-color: var(--frost-color-surface-soft)"], ["bg-accent", "background-color: var(--frost-color-accent); color: var(--frost-color-on-accent)"], ["bg-success", "background-color: var(--frost-color-success); color: var(--frost-color-on-success)"], ["bg-warning", "background-color: var(--frost-color-warning); color: var(--frost-color-on-warning)"], ["bg-danger", "background-color: var(--frost-color-danger); color: var(--frost-color-on-danger)"],
["max-w-sm", "max-width: 24rem"], ["max-w-md", "max-width: 32rem"], ["max-w-lg", "max-width: 48rem"], ["max-w-xl", "max-width: 64rem"], ["max-w-none", "max-width: none"], ["opacity-0", "opacity: 0"], ["opacity-50", "opacity: 0.5"], ["opacity-75", "opacity: 0.75"], ["opacity-100", "opacity: 1"], ["pointer-events-none", "pointer-events: none"],
];
for (const [name, declaration] of declarations) add(name, declaration);
for (const space of spaces) {
const token = `var(--frost-space-${space})`;
for (const [prefix, property] of [["gap", "gap"], ["p", "padding"], ["px", "padding-inline"], ["py", "padding-block"], ["pt", "padding-block-start"], ["pr", "padding-inline-end"], ["pb", "padding-block-end"], ["pl", "padding-inline-start"], ["m", "margin"], ["mx", "margin-inline"], ["my", "margin-block"], ["mt", "margin-block-start"], ["mr", "margin-inline-end"], ["mb", "margin-block-end"], ["ml", "margin-inline-start"]]) add(`${prefix}-${space}`, `${property}: ${token}`);
}
add("mx-auto", "margin-inline: auto"); add("my-auto", "margin-block: auto");
add("space-y-0", "--frost-space-y: 0");
for (const space of spaces.filter((value) => value !== "0")) add(`space-y-${space}`, `--frost-space-y: var(--frost-space-${space})`);
lines.push(" .frost-space-y-0 > :not([hidden]) ~ :not([hidden]) { margin-block-start: 0; }");
for (const space of spaces.filter((value) => value !== "0")) lines.push(` .frost-space-y-${space} > :not([hidden]) ~ :not([hidden]) { margin-block-start: var(--frost-space-${space}); }`);
add("grid-cols-1", "grid-template-columns: repeat(1, minmax(0, 1fr))");
for (const count of [2, 3, 4, 5, 6, 12]) add(`grid-cols-${count}`, `grid-template-columns: repeat(${count}, minmax(0, 1fr))`);
for (const count of [1, 2, 3, 4, 5, 6, 12]) add(`col-span-${count}`, `grid-column: span ${count} / span ${count}`);
for (const value of [0, 1, 10, 20, 25, 50, 75, 100]) add(`z-${value}`, `z-index: ${value}`);
for (const [name, value] of [["xs", "0.75rem"], ["sm", "var(--frost-font-size-sm)"], ["base", "var(--frost-font-size-base)"], ["lg", "var(--frost-font-size-lg)"], ["xl", "var(--frost-font-size-xl)"], ["2xl", "var(--frost-font-size-2xl)"]]) add(`text-${name}`, `font-size: ${value}`);
add("transition", "transition: background-color var(--frost-duration-base) var(--frost-ease-standard), border-color var(--frost-duration-base) var(--frost-ease-standard), color var(--frost-duration-base) var(--frost-ease-standard), box-shadow var(--frost-duration-base) var(--frost-ease-standard), transform var(--frost-duration-fast) var(--frost-ease-out)");
add("focus-ring", "outline: var(--frost-focus-width) solid var(--frost-focus-color); outline-offset: var(--frost-focus-offset)");
for (const [variant, pseudo, name, declaration] of [["hover", ":hover", "bg-soft", "background-color: var(--frost-color-surface-soft)"], ["hover", ":hover", "bg-hover", "background-color: var(--frost-color-surface-hover)"], ["hover", ":hover", "text-accent", "color: var(--frost-color-accent-hover)"], ["hover", ":hover", "shadow", "box-shadow: var(--frost-shadow-md)"], ["focus", ":focus-visible", "ring", "outline: var(--frost-focus-width) solid var(--frost-focus-color); outline-offset: var(--frost-focus-offset)"], ["focus", ":focus", "border-accent", "border-color: var(--frost-focus-color)"], ["active", ":active", "translate-y-1", "transform: translateY(1px)"]]) addVariant(variant, name, declaration, pseudo);
lines.push(" .frost-disabled\\:opacity:disabled, .frost-disabled\\:opacity[aria-disabled=\"true\"] { opacity: 0.55; }");
for (const [variant, minWidth] of Object.entries(breakpoints)) {
lines.push(` @media (min-width: ${minWidth}) {`);
for (const [name, declaration] of declarations.filter(([name]) => ["block", "flex", "grid", "hidden", "flex-row", "flex-col", "items-center", "justify-between", "text-left", "text-center"].includes(name))) addVariant(variant, name, declaration);
for (const count of [1, 2, 3, 4, 6, 12]) addVariant(variant, `grid-cols-${count}`, `grid-template-columns: repeat(${count}, minmax(0, 1fr))`);
for (const space of ["2", "4", "6", "8", "12"]) { addVariant(variant, `p-${space}`, `padding: var(--frost-space-${space})`); addVariant(variant, `gap-${space}`, `gap: var(--frost-space-${space})`); }
lines.push(" }");
}
lines.push(" @media (prefers-reduced-motion: reduce) { .frost-motion-safe\\:transition { transition: none; } }");
lines.push(" @media (prefers-color-scheme: dark) { :root:not([data-theme=\"light\"]) .frost-dark\\:bg-surface { background-color: var(--frost-color-surface); } }");
lines.push(" :root[data-theme=\"dark\"] .frost-dark\\:bg-surface { background-color: var(--frost-color-surface); }");
lines.push("}");
await writeFile(resolve(root, "utilities.css"), `${lines.join("\n")}\n`);
console.log(`Generated utilities.css with ${declarations.length} base utilities and ${spaces.length} spacing steps.`);
+1 -1
View File
@@ -4,7 +4,7 @@ import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("..", import.meta.url));
const files = ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css"];
const files = ["tokens.css", "base.css", "accessibility.css", "layout.css", "controls.css", "components.css", "utilities.css"];
const source = (await Promise.all(files.map((file) => readFile(resolve(root, file), "utf8")))).join("\n");
const rawBytes = Buffer.byteLength(source);
const gzipBytes = gzipSync(source).byteLength;