feat(ui): add accessible tooltips and enforce compact operational typography
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import postcss from 'postcss';
|
||||
import {readFileSync,readdirSync} from 'node:fs';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import path from 'node:path';
|
||||
import {auditStyles,typographyViolation,operationalFontSizes,titleFontSize} from '../packages/ui-core/typography.mjs';
|
||||
const root=fileURLToPath(new URL('../',import.meta.url));
|
||||
const policy=JSON.parse(readFileSync(new URL('./typography-policy.json',import.meta.url),'utf8'));
|
||||
function walk(dir){return readdirSync(dir,{withFileTypes:true}).flatMap(e=>['dist','node_modules','tokens'].includes(e.name)?[]:e.isDirectory()?walk(path.join(dir,e.name)):[path.join(dir,e.name)]);}
|
||||
test('all shared CSS uses compact operational roles and canonical title exceptions',()=>{
|
||||
const violations=[];for(const file of walk(path.join(root,'packages')).filter(f=>f.endsWith('.css')))violations.push(...auditStyles(postcss,readFileSync(file,'utf8'),path.relative(root,file),policy));assert.deepEqual(violations,[]);
|
||||
});
|
||||
test('UI roots and portaled windows establish their own 13px typography, independent of host body',()=>{
|
||||
const css=postcss.parse(readFileSync(path.join(root,'packages/ui-core/styles.css'),'utf8'));
|
||||
for(const scope of ['.nodedc-ui-root','.nodedc-window','.nodedc-workspace-window','.nodedc-application-panel','.nodedc-admin-panel']){
|
||||
let base=false,headings=false;css.walkRules(rule=>{if(rule.selector.includes(scope)){if(!rule.selector.includes(' :where(')&&rule.nodes.some(d=>d.prop==='font-size'&&d.value==='var(--nodedc-font-size-md)'))base=true;if(rule.selector.includes(':where(h1, h2, h3, h4, h5, h6)')&&rule.nodes.some(d=>d.prop==='font-size'&&d.value==='var(--nodedc-font-size-md)'))headings=true;}});assert.ok(base,scope+' independent base');assert.ok(headings,scope+' semantic heading reset');
|
||||
}
|
||||
});
|
||||
test('token values cannot silently make all operational consumers larger',()=>{
|
||||
const css=postcss.parse(readFileSync(path.join(root,'packages/tokens/tokens.css'),'utf8'));
|
||||
for(const [role,px] of Object.entries({...operationalFontSizes,title:titleFontSize})){
|
||||
const values=[];css.walkDecls('--nodedc-font-size-'+role,d=>values.push(d.value));assert.ok(values.length,role);for(const value of values)assert.equal(parseFloat(value)*16,px,role);
|
||||
}
|
||||
});
|
||||
test('title role never grants large typography to a data field or nested card',()=>{
|
||||
assert.equal(typographyViolation({file:'example.css',selector:'.nodedc-window__title',property:'font-size',value:'var(--nodedc-font-size-title)'},policy),null);
|
||||
for(const selector of ['.value','.settings-card h2','.nodedc-window__body'])assert.ok(typographyViolation({file:'example.css',selector,property:'font-size',value:'var(--nodedc-font-size-title)'},policy));
|
||||
assert.ok(typographyViolation({file:'example.css',selector:'.value',property:'font-size',value:'16px'},{compactLegacy:['example.css | .value | font-size | 16px']}));
|
||||
});
|
||||
|
||||
test('theme attributes on html cannot shrink the rem coordinate system',()=>{
|
||||
const css=postcss.parse(readFileSync(path.join(root,'packages/ui-core/styles.css'),'utf8'));
|
||||
css.walkRules(rule=>{
|
||||
if(rule.nodes.some(d=>d.prop==='font-size')&&rule.selector.startsWith(':where([data-nodedc-ui]')&&!rule.selector.includes(' :where(')){
|
||||
assert.ok(rule.selector.includes('[data-nodedc-ui]:not(html)'));
|
||||
assert.ok(rule.selector.includes('.nodedc-ui-root:not(html)'));
|
||||
assert.ok(rule.selector.includes('html[data-nodedc-ui] > body'));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"compactLegacy": [
|
||||
"packages/ui-core/styles.css | .nodedc-admin-context__body small | font-size | 0.72rem",
|
||||
"packages/ui-core/styles.css | .nodedc-admin-panel__group-label | font-size | 0.68rem",
|
||||
"packages/ui-core/styles.css | .nodedc-application-panel__titles span | font-size | 0.68rem",
|
||||
"packages/ui-core/styles.css | .nodedc-application-side-panel__description | font-size | 0.72rem",
|
||||
"packages/ui-core/styles.css | .nodedc-environment-settings__quick-actions span | font-size | 0.68rem",
|
||||
"packages/ui-core/styles.css | .nodedc-environment-settings__surface > span | font-size | 0.74rem",
|
||||
"packages/ui-core/styles.css | .nodedc-feature-settings__group | font-size | 0.66rem",
|
||||
"packages/ui-core/styles.css | .nodedc-header__avatar | font-size | 0.72rem",
|
||||
"packages/ui-core/styles.css | .nodedc-landing-stage__footer | font-size | 0.57rem",
|
||||
"packages/ui-core/styles.css | .nodedc-media-field__kind | font-size | 0.62rem",
|
||||
"packages/ui-core/styles.css | .nodedc-media-file__button | font-size | 0.78rem",
|
||||
"packages/ui-core/styles.css | .nodedc-media-file__name | font-size | 0.78rem",
|
||||
"packages/ui-core/styles.css | .nodedc-media-source-button | font-size | 0.68rem",
|
||||
"packages/ui-core/styles.css | .nodedc-media-url | font-size | 0.78rem",
|
||||
"packages/ui-core/styles.css | .nodedc-settings-card__titles > span | font-size | 0.66rem",
|
||||
"packages/ui-core/styles.css | .nodedc-share-access__avatar | font-size | 0.68rem",
|
||||
"packages/ui-core/styles.css | .nodedc-share-access__summary-avatar | font-size | 0.62rem",
|
||||
"packages/ui-core/styles.css | .nodedc-share-access__summary-count | font-size | 0.68rem",
|
||||
"packages/ui-core/styles.css | .nodedc-user-profile-card__cover > span:not(.nodedc-header__avatar) | font-size | 0.78rem"
|
||||
],
|
||||
"titles": [
|
||||
".nodedc-application-panel__titles h1",
|
||||
".nodedc-admin-panel__head h2",
|
||||
".nodedc-window__title"
|
||||
],
|
||||
"exceptions": [
|
||||
{
|
||||
"key": "packages/ui-core/styles.css | .nodedc-description, .nodedc-settings-card__titles p, .nodedc-settings-card__body :where(p:not([class])) | font-size | var(--nodedc-description-font-size, var(--nodedc-font-size-sm))",
|
||||
"reason": "Canonical Description fallback, compact sm token."
|
||||
},
|
||||
{
|
||||
"key": "packages/ui-core/styles.css | .nodedc-range-scale__limit | font-size | calc(var(--nodedc-font-size-xs) * 0.9)",
|
||||
"reason": "Existing compact viewport label multiplier below sm/xs."
|
||||
},
|
||||
{
|
||||
"key": "packages/ui-core/styles.css | .nodedc-landing-stage__copy h1 | font-size | clamp(3rem, 7vw, 7.6rem)",
|
||||
"reason": "Cover display heading only; never an operational value or message."
|
||||
},
|
||||
{
|
||||
"key": "packages/ui-core/styles.css | .nodedc-landing-stage__copy h1 | font-size | clamp(2.7rem, 7vw, 5.6rem)",
|
||||
"reason": "Cover display heading only; never an operational value or message."
|
||||
},
|
||||
{
|
||||
"key": "packages/ui-core/styles.css | .nodedc-landing-stage__copy h1 | font-size | clamp(2.8rem, 14vw, 5rem)",
|
||||
"reason": "Cover display heading only; never an operational value or message."
|
||||
},
|
||||
{
|
||||
"key": "packages/ui-core/styles.css | .nodedc-landing-stage__copy h1 | font-size | clamp(2.7rem, 6vw, 5rem)",
|
||||
"reason": "Cover display heading only; never an operational value or message."
|
||||
},
|
||||
{
|
||||
"key": "packages/ui-core/styles.css | .nodedc-navigation-cube text | font | 600 9px var(--nodedc-font-family)",
|
||||
"reason": "SVG viewBox coordinate text, not a CSS-screen text size."
|
||||
}
|
||||
],
|
||||
"inlineExceptions": []
|
||||
}
|
||||
Reference in New Issue
Block a user