auth

Main authentication module for my projects
git clone git://git.finwo.net/app/auth
Log | Files | Refs

commit 2474ef0e6b31735854af120a050fbc5b5976d695
parent 52e82c6ab208309ba422f2a133509696c87f0ae5
Author: finwo <finwo@pm.me>
Date:   Tue, 10 Nov 2026 21:57:14 +0100

css: baseline-probe alignment gate, UA-default cell alignment, positive status-dot offset, hard px guard (T1B)

Diffstat:
Mapp/shared/style/global.css | 17+++++++----------
Mtools/css-check/align.mjs | 367++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mtools/css-check/check.mjs | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Atools/css-check/fixtures/negative-degenerate.html | 39+++++++++++++++++++++++++++++++++++++++
Atools/css-check/fixtures/negative-misaligned.html | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/css-check/fixtures/two-line-rows.html | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 510 insertions(+), 153 deletions(-)

diff --git a/app/shared/style/global.css b/app/shared/style/global.css @@ -80,7 +80,7 @@ /* radius */ --radius-0: 0; /* buttons are square by design */ --radius-sm: .25rem; /* small interactive surfaces */ - --radius-pill: 999px; /* reserved: avatars/dots, NOT chips */ + --radius-round: 50%; /* exact circles: dots, spinners, avatars */ /* control + table metrics */ --topbar-height: 3.5rem; @@ -151,7 +151,7 @@ :focus-visible { outline: 2pt solid var(--accent); - outline-offset: 2px; + outline-offset: .125rem; } .sr-only { @@ -619,7 +619,6 @@ text-transform: none; letter-spacing: normal; line-height: var(--lh-body); - vertical-align: baseline; /* default: sits on the text baseline */ white-space: nowrap; cursor: pointer; } @@ -654,7 +653,7 @@ .status-muted { color: var(--muted); } .status-dot { display: inline-block; width: .4375rem; height: .4375rem; border-radius: 50%; - background: currentColor; vertical-align: -.125em; margin-inline-end: var(--space-2); + background: currentColor; vertical-align: .125em; margin-inline-end: var(--space-2); } .spinner { width: 1.25rem; height: 1.25rem; border-radius: 50%; @@ -703,7 +702,7 @@ inline content or a block title pair, never flex or forced heights. ========================================================================== */ @layer components { - .table { width: 100%; font-size: var(--font-base); } + .table { width: 100%; font-size: var(--font-base); line-height: var(--lh-body); } /* DEFAULT (mobile): stacked cards. */ .table, .table tbody, .table tr, .table th, .table td { display: block; } @@ -723,8 +722,8 @@ .table-title { font-weight: 500; } .table-sub { display: block; margin-block-start: var(--space-1); color: var(--muted); font-size: var(--font-sm); font-family: var(--font-mono); } - .table-meta { color: var(--muted); font-size: var(--font-sm); } - .table-mono { font-family: var(--font-mono); font-size: var(--font-sm); overflow-wrap: anywhere; } + .table-meta { color: var(--muted); } + .table-mono { font-family: var(--font-mono); line-height: 1em; overflow-wrap: anywhere; } /* Cursor/interaction states apply at every size. */ .table tbody tr { cursor: default; } @@ -746,9 +745,7 @@ .table td { display: table-cell; } .table th, .table td { - /* vertical-align: middle is the HTML default for table-cell; restated once - for clarity. NEVER overridden to top. */ - vertical-align: middle; + /* middle is the HTML default for table-cell: never restated, never fought. */ text-align: left; padding: var(--cell-y) var(--cell-x); border-bottom: 1pt solid var(--line); diff --git a/tools/css-check/align.mjs b/tools/css-check/align.mjs @@ -1,16 +1,12 @@ #!/usr/bin/env node -// Tier B table-alignment proof. Renders a page in system Google Chrome -// (headless, driven over CDP with built-in fetch + WebSocket, no npm deps), -// then measures the vertical center of each table cell's first inline content -// per row. In real-table mode the spread of centers within a row must stay -// under the threshold; in stacked mode every cell must be a single full-width -// column, where centering is trivially correct. +// Table alignment gate: zero-size inline-block baseline probes, zero spread. // // node tools/css-check/align.mjs +// node tools/css-check/align.mjs --fixture tools/css-check/fixtures/negative-misaligned.html // node tools/css-check/align.mjs --url http://127.0.0.1:8080/index.html // -// Options: --url, --widths 390,1440, --themes auto,light,dark, -// --threshold 0.5, --chrome <binary> +// Options: --url, --fixture <file> (repeatable), --widths 1440,390, +// --themes auto,light,dark, --chrome <binary> import { spawn } from 'node:child_process'; import fs from 'node:fs'; @@ -18,24 +14,52 @@ import os from 'node:os'; import path from 'node:path'; import process from 'node:process'; -const REPO = path.resolve(import.meta.dirname, '..', '..'); +const FIXTURE_DIR = path.join(import.meta.dirname, 'fixtures'); function flagValue(name, dflt) { const i = process.argv.indexOf(name); return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : dflt; } +function flagAll(name) { + const out = []; + for (let i = 0; i < process.argv.length; i += 1) { + if (process.argv[i] === name && process.argv[i + 1]) out.push(process.argv[i + 1]); + } + return out; +} + const CHROME = flagValue( '--chrome', process.env.CHROME_PATH || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', ); -const TARGET_URL = flagValue( - '--url', - new URL('./fixtures/email-domains.html', import.meta.url).href, -); -const WIDTHS = flagValue('--widths', '390,1440').split(',').map(Number); +const WIDTHS = flagValue('--widths', '1440,390').split(',').map(Number); const THEMES = flagValue('--themes', 'auto,light,dark').split(','); -const THRESHOLD = Number(flagValue('--threshold', '0.5')); + +function targetList() { + const url = flagValue('--url', null); + if (url) return [{ label: url, url, negative: false }]; + const fixtures = flagAll('--fixture'); + if (fixtures.length) { + return fixtures.map((f) => { + const full = path.resolve(f); + return { + label: path.basename(full), + url: new URL(`file://${full}`).href, + negative: path.basename(full).startsWith('negative-'), + }; + }); + } + return fs + .readdirSync(FIXTURE_DIR) + .filter((f) => f.endsWith('.html')) + .sort() + .map((f) => ({ + label: f, + url: new URL(`file://${path.join(FIXTURE_DIR, f)}`).href, + negative: f.startsWith('negative-'), + })); +} const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); @@ -106,112 +130,183 @@ function connectCdp(wsUrl) { }); } -// evaluated inside the page: applies the theme and measures every table.table -const MEASURE = (theme) => ` +function measurementExpression(theme) { + return ` (function () { - var theme = ${JSON.stringify(theme)}; - if (theme === 'auto') { + if (${JSON.stringify(theme)} === 'auto') { document.documentElement.removeAttribute('data-theme'); } else { - document.documentElement.setAttribute('data-theme', theme); + document.documentElement.setAttribute('data-theme', ${JSON.stringify(theme)}); } + var Q = 64; // browser layout precision: multiples of 1/64 of a CSS pixel + function q(v) { return Math.round(v * Q); } - function baselineOf(cell) { - // a zero-size inline-block with vertical-align baseline places its border - // box top exactly on the line's baseline without affecting layout - var probe = document.createElement('span'); - probe.style.display = 'inline-block'; - probe.style.width = '0px'; - probe.style.height = '0px'; - probe.style.verticalAlign = 'baseline'; - cell.appendChild(probe); - var y = probe.getBoundingClientRect().top; - cell.removeChild(probe); - return y; + var out = { + tables: 0, rows: 0, multiCells: 0, mode: 'none', + maxSpreadGrid: 0, captions: 0, fail: [] + }; + + function hasBlockChild(cell) { + var kids = cell.children; + for (var i = 0; i < kids.length; i += 1) { + var d = window.getComputedStyle(kids[i]).display; + if (d !== 'inline' && d !== 'inline-block' && d !== 'none') return true; + } + return false; } - function contentHeight(cell) { + function lineBands(cell) { var range = document.createRange(); range.selectNodeContents(cell); var rects = range.getClientRects(); - var top = Infinity; + var sorted = []; + for (var i = 0; i < rects.length; i += 1) { + if (rects[i].height > 0) sorted.push(rects[i]); + } + sorted.sort(function (a, b) { return a.top - b.top; }); + var bands = 0; var bottom = -Infinity; - for (var q = 0; q < rects.length; q += 1) { - if (rects[q].height === 0) continue; - if (rects[q].top < top) top = rects[q].top; - if (rects[q].bottom > bottom) bottom = rects[q].bottom; + for (var j = 0; j < sorted.length; j += 1) { + if (sorted[j].top > bottom) { bands += 1; bottom = sorted[j].bottom; } + else if (sorted[j].bottom > bottom) bottom = sorted[j].bottom; } - return bottom === -Infinity ? 0 : bottom - top; + return bands; } - var result = { tables: 0, mode: 'none', rows: 0, maxSpread: 0, stackedOk: true, wrapped: 0 }; - var tables = document.querySelectorAll('table.table'); - result.tables = tables.length; - // one-line invariant: a .status or .button-inline that wraps onto two line - // fragments splits into multiple client rects; centering math cannot see it, - // so flag every wrapped chip in table mode - var firstCell = document.querySelector('table.table td'); - if (firstCell && window.getComputedStyle(firstCell).display === 'table-cell') { - var chips = document.querySelectorAll('table.table .status, table.table .button-inline'); - for (var z = 0; z < chips.length; z += 1) { - var chipRects = chips[z].getClientRects(); - var fragments = 0; - for (var y = 0; y < chipRects.length; y += 1) { - if (chipRects[y].height > 0) fragments += 1; - } - if (fragments > 1) result.wrapped += 1; + function probeBaseline(cell, where) { + var probe = document.createElement('span'); + probe.style.cssText = 'display:inline-block;width:0;height:0;'; + cell.appendChild(probe); + var rect = probe.getBoundingClientRect(); + cell.removeChild(probe); + if (rect.width !== 0 || rect.height !== 0 || !isFinite(rect.bottom)) { + out.fail.push(where + ': probe is not a zero-size inline-block'); + return null; } + return rect.bottom; } + + var tables = document.querySelectorAll('table.table'); + out.tables = tables.length; + if (!tables.length) { + out.fail.push('no table.table found on the page'); + return JSON.stringify(out); + } + var tableMode = window.matchMedia('(min-width: 40em)').matches; + out.mode = tableMode ? 'table' : 'card'; + for (var t = 0; t < tables.length; t += 1) { - var rows = tables[t].querySelectorAll('tbody tr'); - for (var r = 0; r < rows.length; r += 1) { - var cells = rows[r].querySelectorAll('td'); - if (!cells.length) continue; - result.rows += 1; - var display = window.getComputedStyle(cells[0]).display; - if (display === 'table-cell') { - result.mode = 'table'; - var centers = []; + var table = tables[t]; + var at = 'table ' + (t + 1); + var rows = table.querySelectorAll('tbody tr'); + if (!rows.length) { + out.fail.push(at + ': no tbody rows (degenerate table)'); + continue; + } + + if (tableMode) { + var thead = table.querySelector('thead'); + if (!thead || window.getComputedStyle(thead).display === 'none') { + out.fail.push(at + ': thead is not rendered in table mode'); + } + for (var r = 0; r < rows.length; r += 1) { + var cells = rows[r].querySelectorAll('td'); + var baselines = []; + var where = at + ' row ' + (r + 1); for (var c = 0; c < cells.length; c += 1) { - if (!cells[c].getBoundingClientRect().height) continue; - var lh = parseFloat(window.getComputedStyle(cells[c]).lineHeight) || 0; - var h = contentHeight(cells[c]); - // single-line cells must share one baseline; multi-line cells center - // their content box on the row centerline instead - if (lh > 0 && h <= lh * 1.5) { - centers.push(baselineOf(cells[c])); - } else { - centers.push(cells[c].getBoundingClientRect().top + cells[c].getBoundingClientRect().height / 2); + var cell = cells[c]; + var cs = window.getComputedStyle(cell); + if (cs.display === 'none') continue; + if (cs.display !== 'table-cell') { + out.fail.push(where + ' cell ' + (c + 1) + ': display is "' + cs.display + '", expected table-cell'); + } + var caption = window.getComputedStyle(cell, '::before').content; + if (cell.hasAttribute('data-label') && caption && caption !== 'none' && caption !== 'normal') { + out.fail.push(where + ' cell ' + (c + 1) + ': data-label caption still renders in table mode'); } + if (hasBlockChild(cell) || lineBands(cell) > 1) { + out.multiCells += 1; + continue; + } + var base = probeBaseline(cell, where + ' cell ' + (c + 1)); + if (base !== null) baselines.push(base); + } + out.rows += 1; + if (baselines.length < 2) { + out.fail.push(where + ': fewer than 2 measurable single-line cells (degenerate row)'); + continue; + } + var lo = Math.min.apply(null, baselines); + var hi = Math.max.apply(null, baselines); + var glo = q(lo); + var ghi = q(hi); + if (ghi - glo !== 0) { + out.fail.push(where + ': baseline spread = ' + (ghi - glo) + '/64 across ' + baselines.length + ' single-line cells'); } - if (centers.length > 1) { - var spread = Math.max.apply(null, centers) - Math.min.apply(null, centers); - if (spread > result.maxSpread) result.maxSpread = spread; + if (ghi - glo > out.maxSpreadGrid) { + out.maxSpreadGrid = ghi - glo; } - } else { - if (result.mode !== 'table') result.mode = 'stacked'; - var widest = 0; - for (var k = 0; k < cells.length; k += 1) { - var cs = window.getComputedStyle(cells[k]); - if (cs.display !== 'block') result.stackedOk = false; - var w = cells[k].getBoundingClientRect().width; - if (w > widest) widest = w; + } + } else { + var thead2 = table.querySelector('thead'); + if (thead2 && window.getComputedStyle(thead2).display !== 'none') { + out.fail.push(at + ': thead is visible in card mode'); + } + for (var r2 = 0; r2 < rows.length; r2 += 1) { + var cells2 = rows[r2].querySelectorAll('td'); + if (!cells2.length) { + out.fail.push(at + ' row ' + (r2 + 1) + ': no cells to stack'); + continue; + } + out.rows += 1; + var trDisplay = window.getComputedStyle(rows[r2]).display; + if (trDisplay !== 'block') { + out.fail.push(at + ' row ' + (r2 + 1) + ': tr display is "' + trDisplay + '", expected block'); + } + var widths = []; + var lastTop = -Infinity; + for (var c2 = 0; c2 < cells2.length; c2 += 1) { + var cell2 = cells2[c2]; + var cs2 = window.getComputedStyle(cell2); + if (cs2.display !== 'block') { + out.fail.push(at + ' row ' + (r2 + 1) + ' cell ' + (c2 + 1) + ': display is "' + cs2.display + '", expected block'); + } + var rect2 = cell2.getBoundingClientRect(); + widths.push(q(rect2.width)); + if (rect2.top < lastTop) { + out.fail.push(at + ' row ' + (r2 + 1) + ' cell ' + (c2 + 1) + ': not stacked below its sibling'); + } + lastTop = rect2.top; + var label = cell2.getAttribute('data-label'); + if (label !== null) { + var before = window.getComputedStyle(cell2, '::before'); + if (before.display === 'none' || before.content !== JSON.stringify(label)) { + out.fail.push(at + ' row ' + (r2 + 1) + ' cell ' + (c2 + 1) + ': data-label caption "' + label + '" does not render (content ' + before.content + ')'); + } else { + out.captions += 1; + } + } } - for (var j = 0; j < cells.length; j += 1) { - if (cells[j].getBoundingClientRect().width < widest - 2) result.stackedOk = false; + for (var k = 1; k < widths.length; k += 1) { + if (widths[k] !== widths[0]) { + out.fail.push(at + ' row ' + (r2 + 1) + ': cells are not one full-width column'); + break; + } } } } } - return JSON.stringify(result); + return JSON.stringify(out); })() `; +} async function main() { if (!fs.existsSync(CHROME)) { console.error(`align: chrome binary not found: ${CHROME}`); process.exit(1); } + const targets = targetList(); const userDir = fs.mkdtempSync(path.join(os.tmpdir(), 'css-check-chrome-')); const chrome = spawn( CHROME, @@ -231,67 +326,75 @@ async function main() { let exitCode = 1; try { const port = await waitForPort(userDir); - const targets = await ( - await fetch(`http://127.0.0.1:${port}/json/list`) - ).json(); - const page = targets.find((t) => t.type === 'page'); + const cdpTargets = await (await fetch(`http://127.0.0.1:${port}/json/list`)).json(); + const page = cdpTargets.find((x) => x.type === 'page'); if (!page) throw new Error('no page target'); const cdp = await connectCdp(page.webSocketDebuggerUrl); await cdp.send('Page.enable'); await cdp.send('Runtime.enable'); - console.log(`align: target ${TARGET_URL}`); - console.log(`align: threshold ${THRESHOLD}px widths=${WIDTHS.join(',')} themes=${THEMES.join(',')}`); + console.log(`align: probe gate (zero-size inline-block baseline, zero spread) widths=${WIDTHS.join(',')} themes=${THEMES.join(',')}`); let failures = 0; - for (const width of WIDTHS) { - for (const theme of THEMES) { - const scheme = theme === 'dark' ? 'dark' : theme === 'light' ? 'light' : 'no-preference'; - await cdp.send('Emulation.setDeviceMetricsOverride', { - width, - height: 900, - deviceScaleFactor: 1, - mobile: width < 500, - }); - await cdp.send('Emulation.setEmulatedMedia', { - features: [{ name: 'prefers-color-scheme', value: scheme }], - }); - const loaded = cdp.waitEvent('Page.loadEventFired'); - await cdp.send('Page.navigate', { url: TARGET_URL }); - await loaded; - await sleep(150); - const evaluated = await cdp.send('Runtime.evaluate', { - expression: MEASURE(theme), - returnByValue: true, - }); - if (evaluated.exceptionDetails) { - throw new Error(`page evaluation failed at ${width}/${theme}`); - } - const m = JSON.parse(evaluated.result.value); + for (const target of targets) { + for (const width of WIDTHS) { + for (const theme of THEMES) { + const scheme = theme === 'dark' ? 'dark' : theme === 'light' ? 'light' : 'no-preference'; + await cdp.send('Emulation.setDeviceMetricsOverride', { + width, + height: 900, + deviceScaleFactor: 1, + mobile: width < 500, + }); + await cdp.send('Emulation.setEmulatedMedia', { + features: [{ name: 'prefers-color-scheme', value: scheme }], + }); + const loaded = cdp.waitEvent('Page.loadEventFired'); + await cdp.send('Page.navigate', { url: target.url }); + await loaded; + await sleep(150); + const evaluated = await cdp.send('Runtime.evaluate', { + expression: measurementExpression(theme), + returnByValue: true, + }); + if (evaluated.exceptionDetails) { + throw new Error(`page evaluation failed for ${target.label} at ${width}/${theme}`); + } + const m = JSON.parse(evaluated.result.value); + const gateRed = m.fail.length > 0 || m.tables === 0 || m.rows === 0; - let ok = m.tables > 0 && m.rows > 0; - let detail = ''; - if (m.mode === 'table') { - ok = ok && m.maxSpread < THRESHOLD && m.wrapped === 0; - detail = `mode=table rows=${m.rows} max-center-spread=${m.maxSpread.toFixed(3)}px (limit ${THRESHOLD}px) wrapped-chips=${m.wrapped}`; - } else if (m.mode === 'stacked') { - ok = ok && m.stackedOk; - detail = `mode=stacked rows=${m.rows} single-column=${m.stackedOk ? 'yes' : 'NO'}`; - } else { - ok = false; - detail = 'no table.table rendered'; + const head = `${target.label} ${String(width).padStart(4)} ${theme.padEnd(4)}`; + const stats = + m.mode === 'table' + ? `mode=table tables=${m.tables} rows=${m.rows} multi-cells=${m.multiCells} max-baseline-spread=${m.maxSpreadGrid}/64` + : `mode=card tables=${m.tables} rows=${m.rows} captions=${m.captions}`; + + if (target.negative && m.mode === 'table') { + if (gateRed) { + console.log(` ${head} RED-AS-EXPECTED ${stats}`); + for (const f of m.fail.slice(0, 3)) console.log(` gate caught: ${f}`); + } else { + failures += 1; + console.log(` ${head} FAIL ${stats}`); + console.log(' negative-control PASSED: the baseline gate is not measuring probes'); + } + } else if (gateRed) { + failures += 1; + console.log(` ${head} FAIL ${stats}`); + for (const f of m.fail.slice(0, 5)) console.log(` ${f}`); + } else { + console.log(` ${head} PASS ${stats}`); + } } - if (!ok) failures += 1; - console.log(` ${String(width).padStart(4)}px ${theme.padEnd(4)} ${ok ? 'PASS' : 'FAIL'} ${detail}`); } } if (failures) { - console.log(`align: FAIL (${failures} combination(s) over threshold)`); + console.log(`align: FAIL (${failures} failing combination(s))`); exitCode = 1; } else { - console.log('align: PASS (all widths x themes)'); + console.log('align: PASS (all fixtures x widths x themes)'); exitCode = 0; } cdp.close(); diff --git a/tools/css-check/check.mjs b/tools/css-check/check.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -// Tier A static CSS verification for the shared framework and its consumers. +// Static CSS verification for the shared framework and its consumers. // Dependency-free plain Node. Run from anywhere: // node tools/css-check/check.mjs --scope repo // node tools/css-check/check.mjs --scope app --app admin @@ -26,8 +26,8 @@ const FRAMEWORK_CSS = 'app/shared/style/global.css'; const COMPONENT_CSS_DIR = 'app/shared/component'; const MOCKUP_DIR = 'mockup/plain'; -// files the framework contract governs: the shared framework, its consumer -// stylesheets, the mockup pages, and this harness +// source trees the framework governs: shared framework, consumers, mockups, +// and this harness const MIGRATION_PREFIXES = ['app/', `${MOCKUP_DIR}/`, 'tools/']; // every source tree checked for plain-ASCII and code-comment hygiene const SCAN_ROOTS = ['app', 'mockup', 'tools']; @@ -96,6 +96,45 @@ function stripComments(text) { return text.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/<!--[\s\S]*?-->/g, ' '); } +// blanks comments preserving byte offsets and line numbers +function blankCommentsKeepLines(text) { + return text.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' ')); +} + +function lineAt(text, index) { + let line = 1; + for (let i = 0; i < index; i += 1) if (text.charCodeAt(i) === 10) line += 1; + return line; +} + +// css files policed by the unit guards +function unitGuardFiles() { + const files = new Set(); + const dirs = new Set([COMPONENT_CSS_DIR]); + const appRoot = path.join(REPO, 'app'); + if (fs.existsSync(appRoot)) { + for (const entry of fs.readdirSync(appRoot, { withFileTypes: true })) { + if (!entry.isDirectory()) continue; + for (const sub of ['src/style', 'src/assets', 'dist']) { + dirs.add(`app/${entry.name}/${sub}`); + } + } + } + for (const d of dirs) { + const full = path.join(REPO, d); + if (fs.existsSync(full) && fs.statSync(full).isDirectory()) { + for (const f of walk(full, [])) if (f.endsWith('.css')) files.add(f); + } + } + const fw = path.join(REPO, FRAMEWORK_CSS); + if (fs.existsSync(fw)) files.add(fw); + for (const f of TRANSITION_ALLOW) { + const full = path.join(REPO, f); + if (fs.existsSync(full)) files.add(full); + } + return [...files].sort(); +} + // Minimal block parser: yields { selector, body, chain } for every style // rule, where chain is the list of enclosing at-rule preludes. function parseRules(text) { @@ -235,26 +274,55 @@ function main() { const r = rel(file); const hard = !allowed(r); for (const rule of parseRules(fs.readFileSync(file, 'utf8'))) { - if (!hasCellCompound(rule.selector)) continue; + const sel = rule.selector.replace(/\s+/g, ' '); const mentionsTable = hasTableClass(rule.selector); for (const d of decls(rule.body)) { const prop = d.prop.toLowerCase(); const value = d.value.toLowerCase(); const badDisplay = prop === 'display' && /flex|grid|inline-flex|inline-grid/.test(value); - if (badDisplay || prop === 'min-height') { - if (mentionsTable) { - report(file, 'align', `cell rule "${rule.selector}" declares ${d.prop}: ${d.value}`, hard); - } + if ((badDisplay || prop === 'min-height') && mentionsTable) { + report(file, 'align', `cell rule "${sel}" declares ${d.prop}: ${d.value}`, hard); } - if (prop === 'vertical-align' && value.replace(/!important/, '').trim() !== 'middle') { - if (mentionsTable || /(^|[\s>+~])t[hd](?![\w-])/.test(rule.selector)) { - report(file, 'align', `table cell rule "${rule.selector}" sets vertical-align: ${d.value} (only middle allowed)`, hard); + if (prop === 'vertical-align') { + if (hasCellCompound(rule.selector)) { + report(file, 'align', `"${sel}" declares ${d.prop}: ${d.value}`, hard); } } } } } + // ---- guard 1b: hard px and pt unit guards -------------------------------- + for (const file of unitGuardFiles()) { + const r = rel(file); + if (SCOPE !== 'repo') { + const prefix = `app/${APP_NAME}/`; + if (!r.startsWith(prefix) && !r.startsWith('app/shared/') && !allowed(r)) continue; + } + const hard = !allowed(r); + const text = fs.readFileSync(file, 'utf8'); + const clean = blankCommentsKeepLines(text); + const pxRe = /(?:\d+(?:\.\d+)?|\.\d+)px(?![A-Za-z0-9_-])/g; + let pxm; + while ((pxm = pxRe.exec(clean))) { + report(file, 'unit', `px unit on line ${lineAt(clean, pxm.index)}: "${pxm[0]}"`, hard); + } + for (const rule of parseRules(text)) { + for (const d of decls(rule.body)) { + if (!/(?:\d+(?:\.\d+)?|\.\d+)pt/.test(d.value)) continue; + const prop = d.prop.toLowerCase(); + const borderish = /^(?:border|outline)/.test(prop); + // 1pt hairline lengths on clip, separator, and shadow properties + const ptTokens = d.value.match(/-?(?:\d+(?:\.\d+)?|\.\d+)pt/g) || []; + const allHairline = ptTokens.every((t) => t === '1pt' || t === '-1pt'); + const hairlineGeom = /^(?:width|height|margin|box-shadow)$/.test(prop) && allHairline; + if (!borderish && !hairlineGeom) { + report(file, 'unit', `pt unit on ${d.prop}: ${d.value} (${rule.selector.replace(/\s+/g, ' ')})`, hard); + } + } + } + } + // ---- framework class inventory (for the no-copy guard) ------------------ const frameworkClasses = new Set(); const frameworkFiles = [path.join(REPO, FRAMEWORK_CSS), path.join(REPO, COMPONENT_CSS_DIR)]; diff --git a/tools/css-check/fixtures/negative-degenerate.html b/tools/css-check/fixtures/negative-degenerate.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width,initial-scale=1"> + <title>degenerate rows control fixture</title> + <link rel="stylesheet" href="../../../app/shared/style/global.css"> + </head> + <body> + <!-- negative control: row 1 has a single cell, row 2's cells are two-line; no row has two measurable cells --> + <main class="content"> + <section class="card" aria-label="Degenerate rows"> + <table class="table"> + <thead> + <tr> + <th scope="col">Name</th> + <th scope="col">Status</th> + </tr> + </thead> + <tbody> + <tr> + <td data-label="Name">only-one-cell.test</td> + </tr> + <tr> + <td data-label="Name"> + <span class="table-title">first-stack</span> + <span class="table-sub">two lines are not measurable</span> + </td> + <td data-label="Status"> + <span class="table-title">second-stack</span> + <span class="table-sub">two lines are not measurable</span> + </td> + </tr> + </tbody> + </table> + </section> + </main> + </body> +</html> diff --git a/tools/css-check/fixtures/negative-misaligned.html b/tools/css-check/fixtures/negative-misaligned.html @@ -0,0 +1,56 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width,initial-scale=1"> + <title>misaligned baseline control fixture</title> + <link rel="stylesheet" href="../../../app/shared/style/global.css"> + </head> + <body> + <!-- negative control: row 2 sets font-size on the td and vertical-align: top beside a two-line cell --> + <main class="content"> + <section class="card" aria-label="Alignment control"> + <table class="table"> + <thead> + <tr> + <th scope="col">Name</th> + <th scope="col">Status</th> + <th scope="col">Added</th> + <th scope="col">Actions</th> + </tr> + </thead> + <tbody> + <tr> + <td data-label="Name"><span class="table-mono">aligned.test</span></td> + <td data-label="Status"> + <span class="status"> + <span class="status-dot" aria-hidden="true"></span> + Verified + </span> + </td> + <td data-label="Added">2026-01-02</td> + <td data-label="Actions"> + <button class="button-inline" type="button">Edit</button> + </td> + </tr> + <tr> + <td data-label="Name" style="font-size: .75rem"><span class="table-mono">shrunk-strut.test</span></td> + <td data-label="Status"> + <span class="status"> + <span class="status-dot" aria-hidden="true"></span> + Verified + </span> + </td> + <td data-label="Added" style="vertical-align: top">2026-01-02</td> + <td data-label="Actions"> + <span class="table-title">row-height-driver</span> + <span class="table-sub">a second line makes the row taller</span> + <button class="button-inline" type="button">Edit</button> + </td> + </tr> + </tbody> + </table> + </section> + </main> + </body> +</html> diff --git a/tools/css-check/fixtures/two-line-rows.html b/tools/css-check/fixtures/two-line-rows.html @@ -0,0 +1,94 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width,initial-scale=1"> + <title>two-line primary rows fixture</title> + <link rel="stylesheet" href="../../../app/shared/style/global.css"> + </head> + <body> + <main class="content"> + <section class="card" aria-label="Clients"> + <table class="table table-fixed"> + <thead> + <tr> + <th scope="col">Client</th> + <th scope="col" style="--col-w: 16rem">Realm URL</th> + <th scope="col" style="--col-w: 14rem">Status</th> + <th scope="col" style="--col-w: 10rem">Actions</th> + </tr> + </thead> + <tbody> + <tr> + <td data-label="Client"> + <span class="table-title">acme-web</span> + <span class="table-sub">urn:ietf:params:oauth:client-Id:acme-web</span> + </td> + <td data-label="Realm URL"> + <span class="table-mono">https://acme.test/auth/realms/main</span> + </td> + <td data-label="Status"> + <span class="status"> + <span class="status-dot" aria-hidden="true"></span> + Enabled + </span> + </td> + <td data-label="Actions"> + <button class="button-inline" type="button">Edit</button> + <button class="button-inline button-inline-danger" type="button">Delete</button> + </td> + </tr> + <tr> + <td data-label="Client"> + <span class="table-title">widgets-portal</span> + <span class="table-sub">urn:ietf:params:oauth:client-Id:widgets-portal</span> + </td> + <td data-label="Realm URL"> + <span class="table-mono">https://widgets.example.org/auth/realms/public</span> + </td> + <td data-label="Status"> + <span class="status status-warn"> + <span class="status-dot" aria-hidden="true"></span> + Disabled + </span> + </td> + <td data-label="Actions"> + <button class="button-inline" type="button">Edit</button> + </td> + </tr> + <tr> + <td data-label="Client">plain single-line row control</td> + <td data-label="Realm URL"> + <span class="table-mono">https://plain.test/auth</span> + </td> + <td data-label="Status"> + <span class="status">Enabled</span> + </td> + <td data-label="Actions"> + <button class="button-inline" type="button">Edit</button> + </td> + </tr> + <tr> + <td data-label="Client"> + <span class="table-title">a-client-with-a-very-long-name-that-wraps</span> + <span class="table-sub">urn:ietf:params:oauth:client-Id:a-client-with-a-very-long-name-that-wraps</span> + </td> + <td data-label="Realm URL"> + <span class="table-mono">https://long.test/auth/realms/deep</span> + </td> + <td data-label="Status"> + <span class="status"> + <span class="status-dot" aria-hidden="true"></span> + Enabled + </span> + </td> + <td data-label="Actions"> + <button class="button-inline" type="button">Edit</button> + </td> + </tr> + </tbody> + </table> + </section> + </main> + </body> +</html>