fix(styles): 스타일이 간격·글자·층·그림자 토큰을 읽고 검사가 날 값을 거절한다
셸·페이지 템플릿·카드 CSS가 간격·글자·반경·층·그림자 토큰을 건너뛰고 날 값을 쓴다(`src/presentation/styles/theme/*.css`에서 규칙에 걸리는 선언 118개). `shell.css`·`pages.css`·`templates.css`는 `var(--space-*)`를 한 번도 쓰지 않았고, z-index 100·30·10, 카드·헤더의 손 그림자, `999px`, `min-height: 2.75rem`이 토큰과 같은 값을 다시 적었다. 필수 semantic 토큰 가운데 `--layer-navigation`·`--layer-modal`·`--opacity-scrim`· `--opacity-skeleton`·`--elevation-panel`·`--color-disabled-content`· `--color-action-pressed`를 읽는 스타일이 없었다. 그래서 파생 서비스가 밀도·층·그림자를 토큰으로 바꿔도 화면이 그대로다. 그리고 component.css의 가림막 토큰 셋이 `REQUIRED_COMPONENT_TOKENS`에 없어 UI-03 밖이었다(04-12). 고른 방법: - 날 값을 토큰으로 바꾼다. 맞는 단계가 없는 간격은 가까운 `--space-*`로 반올림했다(0.15~0.35rem → 1, 0.4~0.55 → 2, 0.65~0.85 → 3, 0.9 → 4). 큰 값 3.5rem·4rem은 `--space-14`·`--space-16`을 더했다. 글자 크기도 가까운 단계(0.8 → xs, 0.8125~0.9 → sm, 1.05 → md, 1.1 → lg, 1.35 → xl), 굵기 600·650 → semibold, 700·750·800 → bold, 줄 높이 1.5~1.6 → normal, 1.65·1.7 → relaxed. 페이지 h1은 semantic `--font-size-heading-1`· `--line-height-heading-1`(새 primitive 단계 3xl·4xl·compact)을 읽는다. - 층: skip link는 `--layer-navigation`, sticky 헤더와 sticky 폼 버튼은 `--layer-sticky`. 그림자: 카드·패널·갤러리 안내는 `--elevation-panel`, 헤더는 새 `--elevation-sticky`(`--shadow-sticky`). `.ui-panel`의 Tailwind `shadow-sm`도 `--elevation-panel`로 바꿔 카드와 같은 높이가 됐다. dialog는 `--radius-modal`, 가림막 비율은 `--opacity-scrim`을 읽고 `--dialog-backdrop-weight`는 지웠다. - 읽는 곳이 없던 semantic 토큰: skeleton 깜박임이 `--opacity-skeleton`, 꺼진 입력이 `--color-disabled-content`·`--color-disabled-surface`, 누른 primary 버튼이 새 component 토큰 `--button-primary-pressed` (`--color-action-pressed`)를 읽는다. `--layer-modal`은 native `<dialog>`가 top layer에 열려 z-index가 닿지 않으므로 이유와 함께 `SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER`에 둔다. - `check:design-system`에 셋을 더한다. UI-06: styles 아래 간격·글자·반경· z-index·그림자의 날 값을 줄 번호와 함께 거절한다. UI-03을 필수 semantic 토큰으로 넓힌다. component.css `@theme`의 토큰이 모두 계약에 있어야 한다. 계약에 `--button-primary-pressed`, `--dialog-backdrop`, `--dialog-backdrop-on-surface`를 더했다. - 버린 대안: 맞는 단계가 없는 값마다 primitive 단계를 더하기(단계가 두 배로 늘어 scale이 무의미해진다). `--layer-modal`을 dialog에 z-index로 읽히기 (top layer에서는 효과가 없는 가짜 읽기다). 위험·한계: 반올림과 패널 그림자 때문에 화면이 조금 바뀐다(간격 최대 0.15rem, 굵기 800 → 750, 패널 그림자 크기). 시각 골든은 이 커밋에서 다시 찍고 차이를 PR 본문에 적는다. 다운스트림이 styles에 날 값을 더해 두었으면 UI-06이 그 줄을 알린다. 너비·높이·위치(top 등)와 opacity는 UI-06 밖이다. 검증: 규칙 단위 시험과 check-design-system 연결 시험, 새 검사기로 고치기 전 CSS를 돌린 결과(RED), 시각 골든은 desktop에서 돌려 PR 본문에 적는다. Refs: 1112/04-08, 1112/04-12
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 = /(?<![\w.-])-?(?:\d+\.?\d*|\.\d+)(?:px|rem|em)\b/g;
|
||||
const NUMBER = /(?<![\w.(-])-?(?:\d+\.?\d*|\.\d+)(?![\w.%])/g;
|
||||
const SPACING_PROPERTY =
|
||||
/^(?:padding|margin)(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?$|^(?:row-|column-)?gap$/;
|
||||
|
||||
function handWrittenValues(property: string, value: string): string[] {
|
||||
const tokensRemoved = value.replace(/var\([^)]*\)/g, "");
|
||||
const lengths = tokensRemoved.match(LENGTH) ?? [];
|
||||
const numbers = tokensRemoved.replace(LENGTH, "").match(NUMBER) ?? [];
|
||||
if (SPACING_PROPERTY.test(property)) return lengths.filter((length) => !["1px", "-1px"].includes(length));
|
||||
if (property === "font-size") return lengths.filter((length) => !/(?<!r)em$/.test(length));
|
||||
if (property === "font-weight") return numbers;
|
||||
if (property === "line-height") return [...lengths, ...numbers].filter((item) => 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(/(?<![\w-])([a-z-]+)\s*:\s*([^;{}]+);/g)) {
|
||||
const [, property, value] = match;
|
||||
const raw = handWrittenValues(property, value);
|
||||
if (raw.length === 0) continue;
|
||||
const line = css.slice(0, match.index).split("\n").length;
|
||||
failures.push(
|
||||
`${file}:${line} ${property}: ${value.trim()} writes ${raw.join(", ")} by hand; read a token (docs/styling/design-tokens.md UI-06)`,
|
||||
);
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user