feat(ui): add accessible tooltips and enforce compact operational typography
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist",
|
||||
"styles.css"
|
||||
"styles.css",
|
||||
"typography.mjs"
|
||||
],
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
@@ -13,11 +14,13 @@
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
},
|
||||
"./styles.css": "./styles.css"
|
||||
"./styles.css": "./styles.css",
|
||||
"./typography": "./typography.mjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"prebuild": "node --test ../../scripts/operational-typography.test.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nodedc/tokens": "0.6.0"
|
||||
|
||||
+42
-13
@@ -1,7 +1,7 @@
|
||||
@import "@nodedc/tokens/tokens.css";
|
||||
@import "@nodedc/tokens/themes.css";
|
||||
|
||||
:where([data-nodedc-ui], .nodedc-ui-root) {
|
||||
:where([data-nodedc-ui], .nodedc-ui-root, .nodedc-window, .nodedc-workspace-window, .nodedc-application-panel, .nodedc-admin-panel) {
|
||||
color: var(--nodedc-text-primary);
|
||||
font-family: var(--nodedc-font-family);
|
||||
font-synthesis: none;
|
||||
@@ -9,6 +9,18 @@
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
/* Theme attributes may live on html. Set the text base on body instead, so
|
||||
rem tokens and user zoom never get multiplied by the operational base. */
|
||||
:where([data-nodedc-ui]:not(html), .nodedc-ui-root:not(html), html[data-nodedc-ui] > body, html.nodedc-ui-root > body, .nodedc-window, .nodedc-workspace-window, .nodedc-application-panel, .nodedc-admin-panel) {
|
||||
font-size: var(--nodedc-font-size-md);
|
||||
}
|
||||
|
||||
/* Semantic headings inside operational surfaces do not inherit browser h1–h6 scaling.
|
||||
Explicit canonical window/page titles retain their title token. */
|
||||
:where([data-nodedc-ui], .nodedc-ui-root, .nodedc-window, .nodedc-workspace-window, .nodedc-application-panel, .nodedc-admin-panel) :where(h1, h2, h3, h4, h5, h6) {
|
||||
font-size: var(--nodedc-font-size-md);
|
||||
}
|
||||
|
||||
:where([data-nodedc-ui], .nodedc-ui-root) *,
|
||||
:where([data-nodedc-ui], .nodedc-ui-root) *::before,
|
||||
:where([data-nodedc-ui], .nodedc-ui-root) *::after {
|
||||
@@ -1431,7 +1443,7 @@ textarea.nodedc-field__control {
|
||||
|
||||
.nodedc-user-profile-card__cover strong {
|
||||
margin-top: 0.25rem;
|
||||
font-size: 0.92rem;
|
||||
font-size: var(--nodedc-font-size-md);
|
||||
}
|
||||
|
||||
.nodedc-user-profile-card__cover > span:not(.nodedc-header__avatar) {
|
||||
@@ -1458,7 +1470,7 @@ textarea.nodedc-field__control {
|
||||
text-align: left;
|
||||
text-decoration: none;
|
||||
font: inherit;
|
||||
font-size: 0.82rem;
|
||||
font-size: var(--nodedc-font-size-md);
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -1703,7 +1715,7 @@ textarea.nodedc-field__control {
|
||||
}
|
||||
|
||||
.nodedc-application-panel__titles h1 {
|
||||
font-size: 1.15rem;
|
||||
font-size: var(--nodedc-font-size-title);
|
||||
font-weight: 780;
|
||||
line-height: 1.15;
|
||||
}
|
||||
@@ -1711,7 +1723,7 @@ textarea.nodedc-field__control {
|
||||
.nodedc-application-panel__titles p {
|
||||
max-width: 42rem;
|
||||
color: var(--nodedc-text-muted);
|
||||
font-size: 0.75rem;
|
||||
font-size: var(--nodedc-font-size-sm);
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
@@ -1847,7 +1859,7 @@ textarea.nodedc-field__control {
|
||||
|
||||
.nodedc-admin-panel__head p {
|
||||
color: var(--nodedc-text-muted);
|
||||
font-size: 0.68rem;
|
||||
font-size: var(--nodedc-font-size-sm);
|
||||
font-weight: 850;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
@@ -1855,7 +1867,7 @@ textarea.nodedc-field__control {
|
||||
|
||||
.nodedc-admin-panel__head h2 {
|
||||
margin-top: 0.55rem;
|
||||
font-size: 1.15rem;
|
||||
font-size: var(--nodedc-font-size-title);
|
||||
font-weight: 780;
|
||||
line-height: 1.1;
|
||||
}
|
||||
@@ -2008,7 +2020,7 @@ textarea.nodedc-field__control {
|
||||
}
|
||||
|
||||
.nodedc-admin-context__body strong {
|
||||
font-size: 0.92rem;
|
||||
font-size: var(--nodedc-font-size-md);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
@@ -2047,7 +2059,7 @@ textarea.nodedc-field__control {
|
||||
color: var(--nodedc-text-secondary);
|
||||
padding: 5px 0.9rem 5px calc(5px + 2.92rem + 0.86rem);
|
||||
font: inherit;
|
||||
font-size: 0.91rem;
|
||||
font-size: var(--nodedc-font-size-md);
|
||||
font-weight: 570;
|
||||
text-align: left;
|
||||
opacity: 0.66;
|
||||
@@ -4099,7 +4111,7 @@ textarea.nodedc-field__control {
|
||||
max-width: 34rem;
|
||||
margin: 0;
|
||||
color: var(--nodedc-text-secondary);
|
||||
font-size: clamp(0.8rem, 1vw, 1rem);
|
||||
font-size: var(--nodedc-font-size-sm);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@@ -4134,7 +4146,7 @@ textarea.nodedc-field__control {
|
||||
.nodedc-landing-stage__status p {
|
||||
margin: 0.15rem 0 0;
|
||||
color: var(--nodedc-text-muted);
|
||||
font-size: 0.66rem;
|
||||
font-size: var(--nodedc-font-size-sm);
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
@@ -4241,7 +4253,7 @@ textarea.nodedc-field__control {
|
||||
.nodedc-environment-media-playlist__error {
|
||||
margin: 0;
|
||||
color: var(--nodedc-text-muted);
|
||||
font-size: var(--nodedc-font-size-xs);
|
||||
font-size: var(--nodedc-font-size-sm);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
@@ -4353,7 +4365,7 @@ textarea.nodedc-field__control {
|
||||
}
|
||||
@media (max-height: 720px) and (min-width: 761px) {
|
||||
.nodedc-landing-stage__copy p {
|
||||
font-size: 0.76rem;
|
||||
font-size: var(--nodedc-font-size-sm);
|
||||
}
|
||||
}
|
||||
@media (max-height: 720px) and (min-width: 761px) {
|
||||
@@ -4676,3 +4688,20 @@ textarea.nodedc-field__control {
|
||||
|
||||
.nodedc-level-button[data-custom-fill].nodedc-button{position:relative;overflow:hidden;background-image:none}
|
||||
.nodedc-level-button__fill{position:absolute;inset:0;display:grid;place-items:center;pointer-events:none;background:var(--nodedc-level-custom);color:var(--nodedc-level-ink);clip-path:inset(0 calc(100% - var(--nodedc-level-percent)) 0 0)}
|
||||
|
||||
|
||||
.nodedc-tooltip-anchor { display: inline-flex; min-width: 0; }
|
||||
.nodedc-tooltip-anchor[tabindex] { border-radius: var(--nodedc-radius-control-compact); }
|
||||
.nodedc-tooltip-anchor[tabindex]:focus-visible { outline: 2px solid var(--nodedc-text-primary); outline-offset: 3px; }
|
||||
.nodedc-tooltip {
|
||||
position: fixed; z-index: var(--nodedc-layer-popover); box-sizing: border-box;
|
||||
width: max-content; max-width: min(280px, calc(100vw - 16px)); overflow: auto;
|
||||
padding: var(--nodedc-space-3) var(--nodedc-space-4);
|
||||
border-radius: var(--nodedc-radius-control-compact);
|
||||
background: var(--nodedc-floating-surface); color: var(--nodedc-text-primary);
|
||||
box-shadow: var(--nodedc-glass-dropdown-shadow); font-family: var(--nodedc-font-family);
|
||||
font-size: var(--nodedc-font-size-sm); font-weight: var(--nodedc-font-weight-regular); line-height: 1.4;
|
||||
animation: nodedc-tooltip-in var(--nodedc-duration-fast) var(--nodedc-ease-standard);
|
||||
}
|
||||
@keyframes nodedc-tooltip-in { from { opacity: 0; } to { opacity: 1; } }
|
||||
@media (prefers-reduced-motion: reduce) { .nodedc-tooltip { animation: none; } }
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/** Build-time typography contract. CSS parsers/TypeScript are supplied by the consumer. */
|
||||
export const operationalFontSizes = Object.freeze({xs: 11, sm: 12, md: 13, dense: 7.2});
|
||||
export const titleFontSize = 18;
|
||||
export function declarationKey({file, selector, property, value}) {
|
||||
return [file, selector.replace(/\s+/g,' ').trim(), property, value].join(' | ');
|
||||
}
|
||||
export function typographyViolation(declaration, policy={}) {
|
||||
const {property,value}=declaration,key=declarationKey(declaration);
|
||||
if(property.startsWith('--nodedc-font-size-'))return 'Do not redefine canonical size tokens in a consumer';
|
||||
if(property!=='font-size'&&property!=='font'&&!/font-size$/.test(property))return null;
|
||||
if(property==='font-size'&&/(^|[,\s])(?:html|:root)(?=$|[,\s])/.test(declaration.selector))return 'Do not resize html/rem to make operational UI smaller';
|
||||
if(policy.exceptions?.some(e=>e.key===key&&e.reason))return null;
|
||||
if(property==='font-size'&&declaration.selector.split(',').some(s=>/(?:^|[\s>+~])p$|\.nodedc-description$/.test(s.trim()))&&value!=='var(--nodedc-font-size-sm)')return 'Explanatory paragraphs use sm/12px; do not restyle Description per feature';
|
||||
if(property==='font')return value==='inherit'?null:'Use inherited typography; font shorthand can reintroduce browser/large sizes';
|
||||
if(/^var\(--nodedc-font-size-(xs|sm|md|dense)\)$/.test(value))return null;
|
||||
if(value==='var(--nodedc-font-size-title)'&&policy.titles?.includes(declaration.selector))return null;
|
||||
// Existing compact custom geometry is frozen by exact declaration, never an open size allowance.
|
||||
if(policy.compactLegacy?.includes(key)){
|
||||
const literal=/^([\d.]+)(px|rem)$/.exec(value);
|
||||
if(literal&&Number(literal[1])*(literal[2]==='rem'?16:1)<=13)return null;
|
||||
}
|
||||
return 'Use xs/sm/md tokens (11/12/13 px); title is reserved for canonical page/window titles';
|
||||
}
|
||||
export function auditStyles(postcss, text, file, policy) {
|
||||
const violations=[];
|
||||
postcss.parse(text,{from:file}).walkDecls(d=>{
|
||||
const declaration={file,selector:d.parent.selector||d.parent.name||'',property:d.prop,value:d.value};
|
||||
const reason=typographyViolation(declaration,policy);
|
||||
if(reason)violations.push(`${file}:${d.source.start.line}: ${d.parent.selector}: ${d.prop}: ${d.value}: ${reason}`);
|
||||
});
|
||||
return violations;
|
||||
}
|
||||
export function auditMarkup(ts,text,file,{allowBareParagraphs=false,inlineExceptions=[]}={}) {
|
||||
const source=ts.createSourceFile(file,text,ts.ScriptTarget.Latest,true,file.endsWith('tsx')?ts.ScriptKind.TSX:ts.ScriptKind.TS),violations=[];
|
||||
function report(n,reason){const fragment=n.getText(source);if(!inlineExceptions.some(e=>e.file===file&&e.fragment===fragment&&e.reason))violations.push(`${file}:${source.getLineAndCharacterOfPosition(n.getStart(source)).line+1}: ${reason}`);}
|
||||
function visit(n){
|
||||
if(ts.isJsxOpeningElement(n)||ts.isJsxSelfClosingElement(n)){
|
||||
if(!allowBareParagraphs&&n.tagName.getText(source)==='p'&&!n.attributes.properties.some(p=>ts.isJsxAttribute(p)&&p.name.text==='className'))report(n,'Use Description for explanatory/status copy, or an explicitly styled data paragraph');
|
||||
for(const a of n.attributes.properties)if(ts.isJsxAttribute(a)&&/^(fontSize|style)$/.test(a.name.text)&&a.initializer){
|
||||
if(a.name.text==='fontSize'||(ts.isStringLiteral(a.initializer)&&/font(?:-size)?\s*:/.test(a.initializer.text)))report(a,'Inline typography bypasses the shared contract');
|
||||
}
|
||||
}
|
||||
if(ts.isPropertyAssignment(n)&&(/^(fontSize|font|--nodedc-font-size-.+)$/.test(n.name.getText(source).replace(/['"]/g,''))))report(n,'Inline typography bypasses the shared contract');
|
||||
ts.forEachChild(n,visit);
|
||||
}visit(source);return violations;
|
||||
}
|
||||
Reference in New Issue
Block a user