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.`);