diff --git a/docs/styling/design-tokens.md b/docs/styling/design-tokens.md index 08881e07..77ad3482 100644 --- a/docs/styling/design-tokens.md +++ b/docs/styling/design-tokens.md @@ -23,8 +23,20 @@ component별 값에 연결한다. - UI-02: `color-mix()`는 `oklab`에서 섞는다. 색상(hue) 기반 색 공간에서는 섞지 않는다. - UI-03: 모든 component 토큰은 어떤 스타일이든 하나에서 읽힌다. + `component.css`의 `@theme`에 정의한 토큰은 모두 `token-contract.ts`의 + `REQUIRED_COMPONENT_TOKENS`에 있어야 한다. 필수 semantic 토큰도 스타일 + 하나가 읽어야 한다. 예외는 `SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER`에 + 이유와 함께 적는다(지금 `--layer-modal` 하나: native ``는 top + layer에 열려 z-index가 닿지 않는다). - UI-05: `--font-sans`는 generic family로 시작하거나, repository가 `@font-face`로 함께 배포하는 글꼴로 시작한다. +- UI-06: `src/` 아래 토큰 파일 밖의 스타일은 간격(padding·margin·gap), + 글자 크기·굵기·줄 높이, 모서리 반경, z-index, 그림자를 손으로 쓰지 않고 + 토큰(`var(--space-*)`, `--font-size-*`, `--font-weight-*`, + `--line-height-*`, `--radius-*`, `--layer-*`, `--elevation-*`)을 읽는다. + `0`, `auto`, 키워드, `%`, viewport 단위, margin·padding의 1px 선, 부모 + 글자에 대한 `em`, `line-height: 1`, `z-index` 0·-1은 된다. 맞는 단계가 없으면 + `primitive.css`에 단계를 더한다. - UI-07: `semantic.css`는 색 값을 직접 쓰지 않는다. 색은 `primitive.css` 팔레트에 이름을 두고 `var()`로 읽는다. 토큰끼리 섞는 `color-mix()`는 된다. 그래서 팔레트만 고쳐도 status 색, focus, 어두운 테마가 따라온다. diff --git a/scripts/check-design-system.ts b/scripts/check-design-system.ts index 74b677b1..75f2247c 100644 --- a/scripts/check-design-system.ts +++ b/scripts/check-design-system.ts @@ -9,12 +9,15 @@ import { REQUIRED_COMPONENT_TOKENS, REQUIRED_PRIMITIVE_TOKENS, REQUIRED_SEMANTIC_TOKENS, + SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER, } from "../src/presentation/design-system/tokens/token-contract.ts"; import { firstFontFamilyFailures, focusContrastFailures, hueMixFailures, rawSemanticColourFailures, + rawStyleValueFailures, + undeclaredComponentTokenFailures, unreadTokenFailures, } from "./lib/design-system-rules.ts"; import { readCustomProperties } from "./lib/oklch-contrast.ts"; @@ -64,6 +67,7 @@ for (const { file, source } of cssSources) { } } failures.push(...hueMixFailures({ file, source })); + if (styleFiles.includes(file)) failures.push(...rawStyleValueFailures({ file, source })); } const semanticSource = await readFile(tokenFiles.semantic, "utf8"); @@ -110,6 +114,17 @@ failures.push( REQUIRED_COMPONENT_TOKENS, cssSources.filter(({ file }) => file !== tokenFiles.component), ), + ...unreadTokenFailures( + REQUIRED_SEMANTIC_TOKENS.filter( + (token) => !SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER.includes(token), + ), + cssSources.filter(({ file }) => file !== tokenFiles.semantic), + "semantic", + ), + ...undeclaredComponentTokenFailures( + { file: tokenFiles.component, source: await readFile(tokenFiles.component, "utf8") }, + REQUIRED_COMPONENT_TOKENS, + ), ...firstFontFamilyFailures( lightProperties.get("--font-sans") ?? "", cssSources, diff --git a/scripts/lib/design-system-rules.ts b/scripts/lib/design-system-rules.ts index dd7f02c1..ef203ce5 100644 --- a/scripts/lib/design-system-rules.ts +++ b/scripts/lib/design-system-rules.ts @@ -9,11 +9,12 @@ export interface CssSource { readonly source: string; } -// Comments keep old code around, and the browser never draws it. +// Comments keep old code around, and the browser never draws it. They turn +// into spaces, newlines kept, so a reported line number stays the file's. // Limit: a "/*" inside a quoted string would start a false comment. No // CSS here has one; switch to a CSS tokenizer if that changes. function withoutComments(css: string): string { - return css.replace(/\/\*[\s\S]*?\*\//g, ""); + return css.replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, " ")); } // UI-01. The focus ring is drawn 3px away from its control, so the colour @@ -79,6 +80,7 @@ export function hueMixFailures({ file, source }: CssSource): string[] { export function unreadTokenFailures( tokens: readonly string[], styles: readonly CssSource[], + layer: "component" | "semantic" = "component", ): string[] { const read = new Set( styles.flatMap(({ source }) => @@ -88,7 +90,26 @@ export function unreadTokenFailures( ); return tokens .filter((token) => !read.has(token)) - .map((token) => `component token ${token} is defined but no style reads it`); + .map((token) => `${layer} token ${token} is defined but no style reads it`); +} + +// UI-03 (contract). A component token outside REQUIRED_COMPONENT_TOKENS is +// outside UI-03 too: the reader check only walks the contract list, so a +// token defined in component.css and read by nothing passed (1112/04-12). +// Only the @theme block counts: the forced-colors block redefines semantic +// roles, not component tokens. +export function undeclaredComponentTokenFailures( + { file, source }: CssSource, + contract: readonly string[], +): string[] { + const theme = /@theme\s*\{([\s\S]*?)\n\}/.exec(withoutComments(source))?.[1] ?? ""; + return [...theme.matchAll(/(--[a-z0-9-]+)\s*:/g)] + .map((match) => match[1]) + .filter((token) => !contract.includes(token)) + .map( + (token) => + `${file} defines ${token}, which REQUIRED_COMPONENT_TOKENS in token-contract.ts does not list`, + ); } // UI-05. --font-sans named Inter first, but nothing loads Inter, so most @@ -142,3 +163,43 @@ export function rawSemanticColourFailures({ file, source }: CssSource): string[] `${file} ${match[1]} is the raw colour ${match[2].trim()}; name it in primitive.css and read it with var()`, ); } + +// UI-06. A style that writes a spacing, type, radius, layer or shadow value +// by hand does not move when the token does: changing --space-*, --layer-*, +// --elevation-panel or --radius-modal left the shell, the page templates and +// the cards as they were (1112/04-08). Allowed: a token read (var()), 0, +// auto, keywords, %, viewport units, a 1px hairline in margin or padding, +// line-height 1, z-index 0 or -1, and em sizes relative to the parent font. +const LENGTH = /(? !["1px", "-1px"].includes(length)); + if (property === "font-size") return lengths.filter((length) => !/(? item !== "1"); + if (/^border(?:-[a-z]+)*-radius$/.test(property)) return lengths; + if (property === "z-index") return numbers.filter((item) => !["0", "-1"].includes(item)); + if (property === "box-shadow") return [...lengths, ...numbers]; + return []; +} + +export function rawStyleValueFailures({ file, source }: CssSource): string[] { + const css = withoutComments(source); + const failures: string[] = []; + for (const match of css.matchAll(/(?` opened with `showModal()` sits + * in the browser's top layer, above every z-index, so the template's dialogs + * and drawer have no `z-index`; `--layer-modal` orders a product's own modal + * surface that is not a ``. + */ +export const SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER: readonly string[] = Object.freeze([ + "--layer-modal", +]); + export const REQUIRED_COMPONENT_TOKENS = Object.freeze([ "--button-primary-background", "--button-primary-content", "--button-primary-hover", + "--button-primary-pressed", "--field-border", "--field-border-invalid", "--dialog-elevation", + "--dialog-backdrop", + "--dialog-backdrop-on-surface", "--navigation-active-background", "--drawer-width", "--toast-width", diff --git a/src/presentation/styles/theme/base.css b/src/presentation/styles/theme/base.css index e9b3d5dc..ceebbae5 100644 --- a/src/presentation/styles/theme/base.css +++ b/src/presentation/styles/theme/base.css @@ -48,8 +48,8 @@ } h1 { - font-size: clamp(2rem, 5vw, 3.5rem); - line-height: 1.05; + font-size: var(--font-size-heading-1); + line-height: var(--line-height-heading-1); letter-spacing: -0.04em; } diff --git a/src/presentation/styles/theme/pages.css b/src/presentation/styles/theme/pages.css index b8225f82..55d9d293 100644 --- a/src/presentation/styles/theme/pages.css +++ b/src/presentation/styles/theme/pages.css @@ -2,14 +2,14 @@ .readiness-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); - gap: 1rem; + gap: var(--space-4); } .readiness-grid p, .starter-actions p { margin-block-end: 0; color: var(--color-content-muted); - line-height: 1.65; + line-height: var(--line-height-relaxed); } .starter-actions { @@ -17,23 +17,23 @@ flex-wrap: wrap; align-items: center; justify-content: space-between; - gap: 1.5rem; + gap: var(--space-6); } .button-row { display: flex; flex-wrap: wrap; - gap: 0.75rem; + gap: var(--space-3); } .route-loading { - padding-block-start: 4rem; + padding-block-start: var(--space-16); } .gallery-section { display: grid; - gap: 1rem; - padding-block: 0.5rem; + gap: var(--space-4); + padding-block: var(--space-2); } .gallery-section__header { @@ -46,14 +46,14 @@ } .gallery-section__header p { - margin-block-start: 0.4rem; + margin-block-start: var(--space-2); color: var(--color-content-muted); - line-height: 1.6; + line-height: var(--line-height-normal); } .component-grid { display: grid; - gap: 1rem; + gap: var(--space-4); } .component-grid--two { @@ -67,45 +67,45 @@ .component-stack, .example-form { display: grid; - gap: 1rem; + gap: var(--space-4); } .platform-metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); - gap: 1rem; + gap: var(--space-4); margin-block: 0; } .platform-metric { display: grid; - gap: 0.25rem; - padding: 0.85rem 1rem; + gap: var(--space-1); + padding: var(--space-3) var(--space-4); border: 1px solid var(--color-border); border-radius: var(--radius-surface); background: var(--color-panel); } .platform-metric dt { - font-size: 0.8125rem; + font-size: var(--font-size-sm); color: var(--color-content-muted); } .platform-metric dd { display: grid; - gap: 0.15rem; + gap: var(--space-1); margin-inline-start: 0; } .platform-metric__value { - font-weight: 600; + font-weight: var(--font-weight-semibold); overflow-wrap: anywhere; } .platform-metric__hint, .platform-operation__path { display: block; - font-size: 0.8125rem; + font-size: var(--font-size-sm); color: var(--color-content-muted); overflow-wrap: anywhere; } @@ -113,22 +113,22 @@ .badge-row { display: flex; flex-wrap: wrap; - gap: 0.5rem; + gap: var(--space-2); } .token-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); - gap: 0.75rem; + gap: var(--space-3); } .token-swatch { display: grid; - gap: 0.45rem; + gap: var(--space-2); min-width: 0; border: 1px solid var(--color-border); border-radius: var(--radius-control); - padding: 0.75rem; + padding: var(--space-3); background: var(--color-panel); } @@ -141,7 +141,7 @@ .token-swatch code { overflow: hidden; color: var(--color-content-muted); - font-size: 0.75rem; + font-size: var(--font-size-xs); text-overflow: ellipsis; white-space: nowrap; } @@ -152,13 +152,13 @@ max-width: 100%; box-sizing: border-box; border: 1px solid var(--color-surface-muted); - border-radius: 999px; - padding: 0.65rem 1rem; + border-radius: var(--radius-full); + padding: var(--space-3) var(--space-4); color: var(--color-content); background: var(--color-panel); - box-shadow: 0 8px 28px color-mix(in oklab, var(--color-content) 10%, transparent); - font-size: 0.875rem; - font-weight: 650; + box-shadow: var(--elevation-panel); + font-size: var(--font-size-sm); + font-weight: var(--font-weight-semibold); } .state-surface { @@ -170,24 +170,24 @@ justify-content: center; border: 1px solid var(--color-surface-muted); border-radius: var(--radius-surface); - padding: 1.25rem; + padding: var(--space-5); background: var(--color-surface); } .state-surface :is(h2, h3, h4), .state-surface p { - margin-block-end: 0.75rem; + margin-block-end: var(--space-3); } .state-surface > p:not(.state-surface__eyebrow) { color: var(--color-content-muted); - line-height: 1.55; + line-height: var(--line-height-normal); } .state-surface__eyebrow { color: var(--color-action-hover); - font-size: 0.75rem; - font-weight: 800; + font-size: var(--font-size-xs); + font-weight: var(--font-weight-bold); letter-spacing: 0.04em; } @@ -203,7 +203,7 @@ } .state-surface--loading { - gap: 0.75rem; + gap: var(--space-3); } .state-surface--loading .ui-skeleton { @@ -212,7 +212,7 @@ .state-preview-content { border-radius: var(--radius-control); - padding: 1rem; + padding: var(--space-4); background: var(--color-surface); } } diff --git a/src/presentation/styles/theme/primitives.css b/src/presentation/styles/theme/primitives.css index 191b9512..2a7a8f19 100644 --- a/src/presentation/styles/theme/primitives.css +++ b/src/presentation/styles/theme/primitives.css @@ -6,7 +6,8 @@ } .ui-panel { - @apply rounded-surface p-6 shadow-sm; + @apply rounded-surface p-6; + box-shadow: var(--elevation-panel); border: 1px solid var(--color-border); background: var(--color-panel); } @@ -14,7 +15,7 @@ .ui-button { @apply rounded-control px-4 py-2 font-semibold; display: inline-flex; - min-height: 2.75rem; + min-height: var(--size-control-md); align-items: center; justify-content: center; border: 0; @@ -38,6 +39,10 @@ cursor: progress; } + .ui-button--primary:active:not(:disabled, [aria-disabled="true"]) { + background: var(--button-primary-pressed); + } + .ui-button--secondary { border: 1px solid var(--color-surface-muted); color: var(--color-content); @@ -70,8 +75,8 @@ .ui-button--compact { min-height: var(--size-control-sm); - padding: 0.4rem 0.75rem; - font-size: 0.85rem; + padding: var(--space-2) var(--space-3); + font-size: var(--font-size-sm); } .ui-icon-button { @@ -123,7 +128,14 @@ } .ui-skeleton { - @apply h-24 animate-pulse rounded-surface bg-surface-muted; + @apply h-24 rounded-surface bg-surface-muted; + animation: ui-skeleton-pulse 2s var(--easing-standard) infinite; + } + + @keyframes ui-skeleton-pulse { + 50% { + opacity: var(--opacity-skeleton); + } } .ui-empty, @@ -133,18 +145,18 @@ .ui-field { display: grid; - gap: 0.45rem; + gap: var(--space-2); } .ui-field__label { - font-weight: 750; + font-weight: var(--font-weight-bold); } .ui-field__description, .ui-field__error { margin: 0; - font-size: 0.875rem; - line-height: 1.5; + font-size: var(--font-size-sm); + line-height: var(--line-height-normal); } .ui-field__description { @@ -153,20 +165,26 @@ .ui-field__error { color: var(--color-danger); - font-weight: 650; + font-weight: var(--font-weight-semibold); } .ui-field__input { width: 100%; - min-height: 2.75rem; + min-height: var(--size-control-md); box-sizing: border-box; border: 1px solid var(--field-border); border-radius: var(--radius-control); - padding: 0.65rem 0.8rem; + padding: var(--space-3) var(--space-3); color: var(--color-content); background: var(--color-panel); } + .ui-field__input:disabled { + color: var(--color-disabled-content); + background: var(--color-disabled-surface); + cursor: not-allowed; + } + .ui-field__input[aria-invalid="true"] { border-color: var(--field-border-invalid); } @@ -245,7 +263,7 @@ display: block; width: 1rem; height: 1rem; - margin: 0.2rem; + margin: var(--space-1); border-radius: var(--radius-full); background: var(--color-content-muted); content: ""; @@ -278,12 +296,12 @@ display: flex; min-width: 0; flex-direction: column; - gap: 1.25rem; + gap: var(--space-5); border: 1px solid var(--color-border); border-radius: var(--radius-surface); - padding: 1.25rem; + padding: var(--space-5); background: var(--color-panel); - box-shadow: 0 8px 28px color-mix(in oklab, var(--color-content) 6%, transparent); + box-shadow: var(--elevation-panel); } .ui-card__header :is(h2, h3, h4), @@ -292,9 +310,9 @@ } .ui-card__header p { - margin-block-start: 0.4rem; + margin-block-start: var(--space-2); color: var(--color-content-muted); - line-height: 1.55; + line-height: var(--line-height-normal); } .ui-card__content { @@ -302,7 +320,7 @@ } .ui-card__footer { - padding-block-start: 1rem; + padding-block-start: var(--space-4); border-top: 1px solid var(--color-surface-muted); } @@ -310,10 +328,10 @@ display: flex; align-items: flex-start; justify-content: space-between; - gap: 1rem; + gap: var(--space-4); border: 1px solid var(--color-surface-muted); border-radius: var(--radius-control); - padding: 1rem; + padding: var(--space-4); background: var(--color-surface); } @@ -339,7 +357,7 @@ .ui-alert__content, .ui-alert__content p { - margin-block: 0.35rem 0; + margin-block: var(--space-1) 0; color: var(--color-content-muted); } @@ -354,7 +372,7 @@ border-radius: var(--radius-control); color: var(--color-content); background: transparent; - font-size: 1.35rem; + font-size: var(--font-size-xl); cursor: pointer; } @@ -372,12 +390,12 @@ .ui-badge { display: inline-flex; - border-radius: 999px; - padding: 0.3rem 0.65rem; + border-radius: var(--radius-full); + padding: var(--space-1) var(--space-3); color: var(--color-content); background: var(--color-surface-muted); - font-size: 0.8rem; - font-weight: 750; + font-size: var(--font-size-xs); + font-weight: var(--font-weight-bold); } .ui-badge--info { @@ -406,7 +424,7 @@ box-sizing: border-box; overflow: auto; border: 0; - border-radius: var(--radius-surface); + border-radius: var(--radius-modal); padding: 0; color: var(--color-content); background: var(--color-panel); @@ -713,36 +731,36 @@ } .ui-dialog__surface { - padding: 1.5rem; + padding: var(--space-6); } .ui-dialog__header { display: flex; align-items: flex-start; justify-content: space-between; - gap: 1rem; + gap: var(--space-4); } .ui-dialog__header h2 { - margin-block-end: 0.35rem; + margin-block-end: var(--space-1); } .ui-dialog__header p, .ui-dialog__content p { color: var(--color-content-muted); - line-height: 1.6; + line-height: var(--line-height-normal); } .ui-dialog__content { - padding-block: 1rem; + padding-block: var(--space-4); } .ui-dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; - gap: 0.75rem; - padding-block-start: 1rem; + gap: var(--space-3); + padding-block-start: var(--space-4); border-top: 1px solid var(--color-surface-muted); } } diff --git a/src/presentation/styles/theme/responsive.css b/src/presentation/styles/theme/responsive.css index c635c8d7..80208105 100644 --- a/src/presentation/styles/theme/responsive.css +++ b/src/presentation/styles/theme/responsive.css @@ -7,7 +7,7 @@ } .app-shell__header { - padding-inline: 0.75rem; + padding-inline: var(--space-3); } .app-shell__menu-button.ui-icon-button { diff --git a/src/presentation/styles/theme/shell.css b/src/presentation/styles/theme/shell.css index 52744993..b7eb4620 100644 --- a/src/presentation/styles/theme/shell.css +++ b/src/presentation/styles/theme/shell.css @@ -13,10 +13,10 @@ .skip-link { position: fixed; - z-index: 100; - top: 0.75rem; - left: 0.75rem; - padding: 0.75rem 1rem; + z-index: var(--layer-navigation); + top: var(--space-3); + left: var(--space-3); + padding: var(--space-3) var(--space-4); border-radius: var(--radius-control); color: var(--color-panel); background: var(--color-content); @@ -44,23 +44,23 @@ .app-shell__header { position: sticky; - z-index: 30; + z-index: var(--layer-sticky); top: 0; grid-area: header; display: flex; align-items: center; - gap: 1rem; + gap: var(--space-4); min-width: 0; - padding: 0.75rem 1.25rem; + padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--color-surface-muted); background: color-mix(in oklab, var(--color-panel) 92%, var(--color-surface)); - box-shadow: 0 1px 8px color-mix(in oklab, var(--color-content) 8%, transparent); + box-shadow: var(--elevation-sticky); } .app-shell__brand { overflow: hidden; - font-size: 1.05rem; - font-weight: 800; + font-size: var(--font-size-md); + font-weight: var(--font-weight-bold); text-decoration: none; text-overflow: ellipsis; white-space: nowrap; @@ -68,25 +68,25 @@ /* 08-01. The narrow header drops these; the menu drawer carries them. */ .app-shell__drawer-brand { - margin: 0 0 0.75rem; - font-weight: 800; + margin: 0 0 var(--space-3); + font-weight: var(--font-weight-bold); } .app-shell__drawer-preferences { display: grid; - gap: 0.75rem; - margin-top: 1rem; - padding-top: 1rem; + gap: var(--space-3); + margin-top: var(--space-4); + padding-top: var(--space-4); border-top: 1px solid var(--color-border); } .app-shell__menu-button { display: none; align-items: center; - gap: 0.4rem; + gap: var(--space-2); border: 1px solid var(--color-surface-muted); border-radius: var(--radius-control); - padding: 0.55rem 0.75rem; + padding: var(--space-2) var(--space-3); color: var(--color-content); background: var(--color-panel); cursor: pointer; @@ -95,7 +95,7 @@ .app-shell__session { display: flex; align-items: center; - gap: 0.75rem; + gap: var(--space-3); margin-inline-start: auto; } @@ -120,7 +120,7 @@ .theme-selector .ui-field__input, .locale-selector .ui-field__input { min-height: var(--size-control-sm); - padding: 0.35rem 2rem 0.35rem 0.65rem; + padding: var(--space-1) var(--space-8) var(--space-1) var(--space-3); cursor: pointer; } @@ -128,7 +128,7 @@ position: absolute; top: calc(100% + 0.25rem); right: 1rem; - padding: 0.5rem; + padding: var(--space-2); color: var(--color-danger); background: var(--color-panel); } @@ -137,12 +137,12 @@ display: inline-flex; width: fit-content; align-items: center; - border-radius: 999px; - padding: 0.3rem 0.65rem; + border-radius: var(--radius-full); + padding: var(--space-1) var(--space-3); color: var(--color-content-muted); background: var(--color-surface-muted); - font-size: 0.8rem; - font-weight: 700; + font-size: var(--font-size-xs); + font-weight: var(--font-weight-bold); } .session-status[data-state="authenticated"] { @@ -159,7 +159,7 @@ top: 4.5rem; grid-area: sidebar; height: calc(100vh - 4.5rem); - padding: 1.25rem 0.75rem; + padding: var(--space-5) var(--space-3); border-right: 1px solid var(--color-border); background: var(--color-panel); } @@ -167,7 +167,7 @@ .app-navigation { display: flex; flex-direction: column; - gap: 0.25rem; + gap: var(--space-1); margin: 0; padding: 0; list-style: none; @@ -176,9 +176,9 @@ .app-navigation__link { display: block; border-radius: var(--radius-control); - padding: 0.75rem 0.9rem; + padding: var(--space-3) var(--space-4); color: var(--color-content-muted); - font-weight: 650; + font-weight: var(--font-weight-semibold); text-decoration: none; } @@ -190,7 +190,7 @@ .app-navigation__link.is-active { color: var(--color-action-hover); background: var(--navigation-active-background); - font-weight: 800; + font-weight: var(--font-weight-bold); } .app-shell__content { diff --git a/src/presentation/styles/theme/templates.css b/src/presentation/styles/theme/templates.css index 7623f816..d2d0f33a 100644 --- a/src/presentation/styles/theme/templates.css +++ b/src/presentation/styles/theme/templates.css @@ -1,7 +1,7 @@ @layer components { .page-header { max-width: 50rem; - padding-block: clamp(1rem, 5vw, 3.5rem) 0.5rem; + padding-block: clamp(var(--space-4), 5vw, var(--space-14)) var(--space-2); } /* 1112/05-02. Pointer navigation only: a keyboard user keeps the @@ -11,10 +11,10 @@ } .page-header__eyebrow { - margin-block-end: 0.75rem; + margin-block-end: var(--space-3); color: var(--color-action); - font-size: 0.8rem; - font-weight: 800; + font-size: var(--font-size-xs); + font-weight: var(--font-weight-bold); letter-spacing: 0.08em; text-transform: uppercase; } @@ -22,13 +22,13 @@ .page-header__description { max-width: 45rem; color: var(--color-content-muted); - font-size: 1.05rem; - line-height: 1.7; + font-size: var(--font-size-md); + line-height: var(--line-height-relaxed); } .page-template { display: grid; - gap: 1.25rem; + gap: var(--space-5); min-width: 0; } @@ -39,9 +39,9 @@ } .page-template__breadcrumb { - padding-block-start: 1rem; + padding-block-start: var(--space-4); color: var(--color-content-muted); - font-size: 0.9rem; + font-size: var(--font-size-sm); } .page-template__heading { @@ -49,7 +49,7 @@ min-width: 0; grid-template-columns: minmax(0, 1fr) auto; align-items: end; - gap: 1rem; + gap: var(--space-4); } .page-template__heading .page-header { @@ -65,13 +65,13 @@ flex-wrap: wrap; align-items: center; justify-content: flex-end; - gap: 0.75rem; + gap: var(--space-3); } .page-template__layout { display: grid; min-width: 0; - gap: 1.5rem; + gap: var(--space-6); } .page-template__layout[data-has-aside="true"] { @@ -92,7 +92,7 @@ .form-error-summary { border: 1px solid var(--color-border); border-radius: var(--radius-surface); - padding: 1rem; + padding: var(--space-4); background: var(--color-panel); } @@ -102,7 +102,7 @@ display: flex; flex-wrap: wrap; align-items: end; - gap: 0.75rem; + gap: var(--space-3); } .collection-page__result-count { @@ -114,17 +114,17 @@ .form-page__fields, .form-page__error-summary { display: grid; - gap: 1rem; + gap: var(--space-4); } .collection-page__pagination { - margin-block-start: 1.25rem; + margin-block-start: var(--space-5); } .detail-page__danger { - margin-block-start: 2rem; + margin-block-start: var(--space-8); border-top: 1px solid var(--color-danger-border); - padding-block-start: 1rem; + padding-block-start: var(--space-4); } .form-error-summary { @@ -133,7 +133,7 @@ } .form-error-summary :is(h2, h3, h4) { - font-size: 1.1rem; + font-size: var(--font-size-lg); } .form-error-summary p, @@ -142,21 +142,21 @@ } .form-actions { - padding-block-start: 1rem; + padding-block-start: var(--space-4); border-top: 1px solid var(--color-border); } .form-actions--sticky { position: sticky; - z-index: 10; + z-index: var(--layer-sticky); bottom: 0; - padding: 0.75rem; + padding: var(--space-3); background: color-mix(in oklab, var(--color-panel) 94%, transparent); } .status-page { max-width: 48rem; - padding-block: 2rem; + padding-block: var(--space-8); } .status-page__actions { diff --git a/tests/unit/design-system-rules.test.ts b/tests/unit/design-system-rules.test.ts index 926a463d..75504130 100644 --- a/tests/unit/design-system-rules.test.ts +++ b/tests/unit/design-system-rules.test.ts @@ -11,8 +11,15 @@ import { focusContrastFailures, hueMixFailures, rawSemanticColourFailures, + rawStyleValueFailures, + undeclaredComponentTokenFailures, unreadTokenFailures, } from "../../scripts/lib/design-system-rules.ts"; +import { + REQUIRED_COMPONENT_TOKENS, + REQUIRED_SEMANTIC_TOKENS, + SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER, +} from "../../src/presentation/design-system/tokens/token-contract.ts"; import { childProcessTimeout } from "../helpers/child-process-timeout.ts"; const css = (source: string) => ({ file: "probe.css", source }); @@ -144,6 +151,83 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => { }); }); + // 1112/04-08. A style that writes the value by hand ignores the token. + describe("UI-06 styles read spacing, type, radius, layer and shadow tokens", () => { + it.each([ + ["padding: 0.75rem 1rem", "0.75rem, 1rem"], + ["margin-block-start: 0.4rem", "0.4rem"], + ["gap: 12px", "12px"], + ["font-size: 0.8rem", "0.8rem"], + ["font-weight: 800", "800"], + ["line-height: 1.6", "1.6"], + ["border-radius: 999px", "999px"], + ["z-index: 30", "30"], + ["box-shadow: 0 1px 8px var(--color-border)", "1px, 8px, 0"], + ])("fails %s", (declaration, raw) => { + const [property] = declaration.split(":"); + expect(rawStyleValueFailures(css(`.a {\n ${declaration};\n}`))).toEqual([ + `probe.css:2 ${property}: ${declaration.slice(property.length + 1).trim()} writes ${raw} by hand; read a token (docs/styling/design-tokens.md UI-06)`, + ]); + }); + + it("passes token reads, zero, keywords, hairlines, relative and viewport values", () => { + expect( + rawStyleValueFailures( + css(`.a { + padding: var(--space-3) var(--space-4); + margin: -1px; + margin-inline: calc(var(--spacing-page) * -1); + padding-block: clamp(var(--space-4), 5vw, var(--space-14)) 0; + gap: 0; + font-size: 0.9em; + font-weight: var(--font-weight-bold); + line-height: 1; + border-radius: 50%; + z-index: var(--layer-sticky); + box-shadow: none; + width: 2rem; + }`), + ), + ).toEqual([]); + }); + + it("reports the file's own line after a comment of several lines", () => { + expect(rawStyleValueFailures(css("/* one\n two\n padding: 1rem; */\n.a { padding: 1rem; }"))).toEqual([ + "probe.css:4 padding: 1rem writes 1rem by hand; read a token (docs/styling/design-tokens.md UI-06)", + ]); + }); + }); + + describe("UI-03 for the required semantic tokens", () => { + it("names the semantic layer in the message", () => { + expect(unreadTokenFailures(["--layer-navigation"], [css(".a { z-index: 1; }")], "semantic")).toEqual([ + "semantic token --layer-navigation is defined but no style reads it", + ]); + }); + + it("leaves out only --layer-modal, which the top layer makes unreadable", () => { + expect(SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER).toEqual(["--layer-modal"]); + expect(REQUIRED_SEMANTIC_TOKENS).toContain("--layer-modal"); + }); + }); + + // 1112/04-12. Every component token is in the contract UI-03 walks. + describe("component tokens and the contract", () => { + it("fails a component token the contract does not list", () => { + const component = css(`@theme {\n --button-primary-background: x;\n --dialog-backdrop-weight: 55%;\n}\n\n@media (forced-colors: active) {\n :root {\n --color-border: CanvasText;\n }\n}`); + expect(undeclaredComponentTokenFailures(component, ["--button-primary-background"])).toEqual([ + "probe.css defines --dialog-backdrop-weight, which REQUIRED_COMPONENT_TOKENS in token-contract.ts does not list", + ]); + }); + + it("passes the repository's component tokens", async () => { + const file = "src/presentation/design-system/tokens/component.css"; + expect( + undeclaredComponentTokenFailures({ file, source: await readFile(file, "utf8") }, REQUIRED_COMPONENT_TOKENS), + ).toEqual([]); + }); + }); + describe("UI-05 first font family", () => { it("fails a named font that nothing loads", () => { expect(firstFontFamilyFailures("Inter, system-ui, sans-serif", [])).toEqual([ @@ -201,6 +285,12 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => { await edit(semantic, "--font-sans: ", "--font-sans: Inter, "); await edit(semantic, "--color-danger-surface: var(--palette-red-50);", "--color-danger-surface: oklch(0.96 0.035 25);"); await edit("src/presentation/styles/theme/primitives.css", "var(--drawer-width)", "20rem"); + await edit("src/presentation/styles/theme/shell.css", "z-index: var(--layer-navigation);", "z-index: 50;"); + await edit( + "src/presentation/design-system/tokens/component.css", + " --drawer-width:", + " --probe-unlisted: 1px;\n --drawer-width:", + ); await writeFile( path.join(root, "src/presentation/styles/theme/probe.css"), ".probe { color: color-mix(in oklch, red, blue); }\n", @@ -219,6 +309,9 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => { /^src\/presentation\/styles\/theme\/probe\.css mixes colours in oklch; use oklab$/, /^component token --drawer-width is defined but no style reads it$/, /^--font-sans starts with "Inter", which is neither a generic family, loaded by @font-face, nor listed in PRODUCT_LOADED_FONT_FAMILIES$/, + /^src\/presentation\/styles\/theme\/shell\.css:\d+ z-index: 50 writes 50 by hand; read a token \(docs\/styling\/design-tokens\.md UI-06\)$/, + /^semantic token --layer-navigation is defined but no style reads it$/, + /^src\/presentation\/design-system\/tokens\/component\.css defines --probe-unlisted, which REQUIRED_COMPONENT_TOKENS in token-contract\.ts does not list$/, /^src\/presentation\/design-system\/tokens\/semantic\.css --color-danger-surface is the raw colour oklch\(0\.96 0\.035 25\); name it in primitive\.css and read it with var\(\)$/, ]; expect(failures.filter((failure) => !rules.some((rule) => rule.test(failure)))).toEqual([]); diff --git a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-compact-pseudo-drawer-chromium-visual-linux.png b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-compact-pseudo-drawer-chromium-visual-linux.png index 84f5e939..6203586d 100644 Binary files a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-compact-pseudo-drawer-chromium-visual-linux.png and b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-compact-pseudo-drawer-chromium-visual-linux.png differ diff --git a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-wide-light-chromium-visual-linux.png b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-wide-light-chromium-visual-linux.png index 221a44b5..c5ba90b0 100644 Binary files a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-wide-light-chromium-visual-linux.png and b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/app-shell-wide-light-chromium-visual-linux.png differ diff --git a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/design-system-gallery-dark-chromium-visual-linux.png b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/design-system-gallery-dark-chromium-visual-linux.png index 3484f89d..5244e0fe 100644 Binary files a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/design-system-gallery-dark-chromium-visual-linux.png and b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/design-system-gallery-dark-chromium-visual-linux.png differ diff --git a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/platform-overview-light-chromium-visual-linux.png b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/platform-overview-light-chromium-visual-linux.png index beb8e3d4..3da618f0 100644 Binary files a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/platform-overview-light-chromium-visual-linux.png and b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/platform-overview-light-chromium-visual-linux.png differ diff --git a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/state-surfaces-light-chromium-visual-linux.png b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/state-surfaces-light-chromium-visual-linux.png index 382c7646..be5422ee 100644 Binary files a/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/state-surfaces-light-chromium-visual-linux.png and b/tests/visual/__snapshots__/platform.visual.spec.ts-snapshots/state-surfaces-light-chromium-visual-linux.png differ