gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit88e1d14d88e1d14d|||PR layouts#9: address Kunibert findings (3-pane 768px, :where invalid focus, placeholder & glow contrast)Atlas88e1d14d/tests/hc-look.mjs

15.7 KB

  1. // tests/hc-look.mjs — gate for layouts#9 lines 1–21 (HyperConductor look): fails on 4099e64, passes on the fix.
  2. // node tests/hc-look.mjs (uses LAYOUTS_GATE_PORT / LAYOUTS_GATE_CHROME)
  3. import { spawn } from 'node:child_process';
  4. import { existsSync } from 'node:fs';
  5. import { dirname, join, resolve } from 'node:path';
  6. import { fileURLToPath } from 'node:url';
  7. import { launchBrowser } from './cdp.mjs';
  8. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  9. const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');
  10. const PORT = Number(process.env.LAYOUTS_GATE_PORT || 8760);
  11. const [CH_FROM, CH_TO] = (process.env.LAYOUTS_GATE_CHROME || '8761-8764').split('-').map(Number);
  12. const BASE = `http://127.0.0.1:${PORT}`;
  13. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  14. let failures = 0, passes = 0;
  15. function check(label, ok, detail = '') {
  16. console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);
  17. if (ok) passes++; else failures++;
  18. }
  19. let log = '', server = null, browser = null;
  20. async function startServer() {
  21. server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], {
  22. cwd: APP,
  23. env: { ...process.env, LAYOUTS_PORT: String(PORT), LAYOUTS_WATCH: '0' },
  24. stdio: ['ignore', 'pipe', 'pipe'],
  25. });
  26. server.stdout.on('data', d => log += d);
  27. server.stderr.on('data', d => log += d);
  28. for (let i = 0; ; i++) {
  29. try { if ((await fetch(BASE + '/')).ok) break; } catch {}
  30. if (i > 1600) throw new Error('server did not come up\n' + log);
  31. await sleep(250);
  32. }
  33. }
  34. async function stop() {
  35. if (browser) { try { await browser.close(); } catch {} browser = null; }
  36. if (server) {
  37. try { server.kill('SIGTERM'); } catch {}
  38. await new Promise(r => {
  39. if (server.exitCode !== null || server.signalCode !== null) return r();
  40. server.once('exit', r);
  41. setTimeout(r, 3000);
  42. });
  43. server = null;
  44. }
  45. }
  46. const lum = (c) => {
  47. const v = c.map(x => { x /= 255; return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4); });
  48. return 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2];
  49. };
  50. const ratio = (a, b) => { const x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); };
  51. const rgbOf = (s) => (String(s).match(/rgba?\(([^)]+)\)/) || [0, '0,0,0'])[1].split(',').slice(0, 3).map(Number);
  52. const eqColor = (a, b) => {
  53. const pa = (String(a).match(/rgba?\(([^)]+)\)/) || [0, ''])[1].split(',').map(Number);
  54. const pb = (String(b).match(/rgba?\(([^)]+)\)/) || [0, ''])[1].split(',').map(Number);
  55. if (pa.length < 3 || pb.length < 3) return false;
  56. const alphaA = pa.length > 3 ? pa[3] : 1;
  57. const alphaB = pb.length > 3 ? pb[3] : 1;
  58. return Math.abs(pa[0] - pb[0]) <= 1 && Math.abs(pa[1] - pb[1]) <= 1 && Math.abs(pa[2] - pb[2]) <= 1 && Math.abs(alphaA - alphaB) <= 0.02;
  59. };
  60. async function main() {
  61. await startServer();
  62. browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  63. const page = await browser.newPage();
  64. const ev = (e) => page.evaluate(e);
  65. const size = (w, h = w < 600 ? 844 : 800) => page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 });
  66. const open = async (path) => {
  67. await page.goto(BASE + path, { timeout: 45000 });
  68. await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label: 'hydrated ' + path });
  69. await sleep(300);
  70. };
  71. const hover = async (sel) => {
  72. const box = await page.box(sel);
  73. await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: Math.round(box.x), y: Math.round(box.y), buttons: 0 });
  74. await sleep(100);
  75. };
  76. const kTab = async () => {
  77. await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 });
  78. await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 });
  79. await sleep(40);
  80. };
  81. const tabTo = async (sel, max = 80) => {
  82. for (let i = 0; i < max; i++) {
  83. if (await ev(`(() => { const a = document.activeElement; return !!a && a.matches(${JSON.stringify(sel)}); })()`)) return true;
  84. await kTab();
  85. }
  86. return await ev(`(() => { const a = document.activeElement; return !!a && a.matches(${JSON.stringify(sel)}); })()`);
  87. };
  88. const checkCoreStyles = async (w) => {
  89. await size(w, w === 390 ? 844 : 800);
  90. await open('/elements');
  91. const base = await ev(`(() => {
  92. const cs = (q, pseudo) => getComputedStyle(document.querySelector(q), pseudo || null);
  93. const hdr = cs('application-header');
  94. const h1 = cs('elements-page h1');
  95. const body = getComputedStyle(document.body);
  96. const inp = cs('#el-title');
  97. const sel = cs('#el-kind');
  98. const txt = cs('#el-notes');
  99. const btn = cs('elements-page p.row button:not(.primary):not(.danger):not(:disabled)');
  100. const dng = cs('elements-page p.row button.danger');
  101. const brand = cs('application-header > a.brand');
  102. const sb = cs('#sidebar');
  103. const sbh2 = cs('#sidebar h2');
  104. const sba = cs('#sidebar nav a');
  105. const sbcur = cs('#sidebar nav a[aria-current="page"]');
  106. return {
  107. darker: hdr.backgroundColor,
  108. lighter: h1.color,
  109. bodyColor: body.color,
  110. inpBg: inp.backgroundColor, inpColor: inp.color, inpPad: inp.paddingTop + ' ' + inp.paddingLeft,
  111. selBg: sel.backgroundColor, selColor: sel.color, selPad: sel.paddingTop + ' ' + sel.paddingLeft,
  112. txtBg: txt.backgroundColor, txtColor: txt.color, txtPad: txt.paddingTop + ' ' + txt.paddingLeft,
  113. btnBg: btn.backgroundColor, btnColor: btn.color, btnWeight: btn.fontWeight, btnPad: btn.paddingTop + ' ' + btn.paddingLeft,
  114. dngBg: dng.backgroundColor, dngColor: dng.color,
  115. brandWeight: brand.fontWeight, brandSize: brand.fontSize,
  116. sbBg: sb.backgroundColor, sbW: sb.width, sbPad: sb.paddingTop, sbGap: sb.rowGap,
  117. sbh2Transform: sbh2.textTransform,
  118. sbaPad: sba.paddingTop + ' ' + sba.paddingLeft,
  119. sbcurColor: sbcur.color, sbcurBg: sbcur.backgroundColor, sbcurRadius: sbcur.borderTopLeftRadius,
  120. };
  121. })()`);
  122. check(`${w} darker token rgb(20, 25, 30)`, base.darker === 'rgb(20, 25, 30)', base.darker);
  123. check(`${w} lighter token rgb(220, 225, 230)`, base.lighter === 'rgb(220, 225, 230)', base.lighter);
  124. check(`${w} body text colour = lighter`, base.bodyColor === 'rgb(220, 225, 230)', base.bodyColor);
  125. check(`${w} fields background rgba(255, 255, 255, .12)`, eqColor(base.inpBg, 'rgba(255, 255, 255, 0.12)') && eqColor(base.selBg, 'rgba(255, 255, 255, 0.12)') && eqColor(base.txtBg, 'rgba(255, 255, 255, 0.12)'), JSON.stringify([base.inpBg, base.selBg, base.txtBg]));
  126. check(`${w} fields text colour = lighter`, base.inpColor === 'rgb(220, 225, 230)' && base.selColor === 'rgb(220, 225, 230)' && base.txtColor === 'rgb(220, 225, 230)', JSON.stringify([base.inpColor, base.selColor, base.txtColor]));
  127. check(`${w} fields padding (.3rem .5rem input/select, .5rem textarea)`, base.inpPad === '4.8px 8px' && base.selPad === '4.8px 8px' && base.txtPad === '8px 8px', JSON.stringify([base.inpPad, base.selPad, base.txtPad]));
  128. // Field focus: shadow rgba(86, 155, 212, .65), outline none; invalid field keeps red outline
  129. const fieldFocus = {};
  130. for (const id of ['el-title', 'el-kind', 'el-notes']) {
  131. await page.focus('#' + id);
  132. await sleep(50);
  133. fieldFocus[id] = await ev(`(() => { const c = getComputedStyle(document.querySelector('#${id}')); return { shadow: c.boxShadow, outline: c.outlineStyle }; })()`);
  134. }
  135. const focusOk = (f) => f && f.outline === 'none' && /rgba?\(86,\s*155,\s*212,\s*0\.65/.test(f.shadow) && /2px/.test(f.shadow);
  136. check(`${w} field focus: 2px rgba(86, 155, 212, .65) shadow, no outline`, focusOk(fieldFocus['el-title']) && focusOk(fieldFocus['el-kind']) && focusOk(fieldFocus['el-notes']), JSON.stringify(fieldFocus));
  137. await page.focus('#el-mail');
  138. await sleep(50);
  139. const invFocus = await ev(`(() => { const c = getComputedStyle(document.querySelector('#el-mail')); return { outline: c.outlineStyle, color: c.outlineColor }; })()`);
  140. check(`${w} invalid field keeps danger outline when focused`, invFocus.outline === 'solid' && invFocus.color === 'rgb(244, 71, 71)', JSON.stringify(invFocus));
  141. // Button default = #569bd4 (colorAction), dark text, weight 400, padding .5rem
  142. check(`${w} button default: #569bd4 bg, dark text, weight 400, padding .5rem`, base.btnBg === 'rgb(86, 155, 212)' && base.btnColor === 'rgb(25, 30, 35)' && base.btnWeight === '400' && base.btnPad === '8px 8px', JSON.stringify({ bg: base.btnBg, col: base.btnColor, wt: base.btnWeight, pad: base.btnPad }));
  143. check(`${w} button.danger readable (>= 4.5:1)`, ratio(rgbOf(base.dngColor), rgbOf(base.dngBg)) >= 4.5, JSON.stringify({ col: base.dngColor, bg: base.dngBg }));
  144. // Button focus-visible ring: 2px #569bd4AA, 0px offset
  145. const reachedBtn = await tabTo('elements-page p.row button:not(.primary):not(.danger):not(:disabled)');
  146. const btnRing = await ev(`(() => { const c = getComputedStyle(document.activeElement); return { style: c.outlineStyle, w: c.outlineWidth, col: c.outlineColor, off: c.outlineOffset }; })()`);
  147. check(`${w} button focus-visible ring: 2px #569bd4AA outline, 0 offset`, reachedBtn && btnRing.style === 'solid' && btnRing.w === '2px' && eqColor(btnRing.col, 'rgba(86, 155, 212, 0.667)') && btnRing.off === '0px', JSON.stringify(btnRing));
  148. // Checkbox focus-visible ring: 2px #569bd4AA outline, no boxShadow
  149. const reachedChk = await tabTo('elements-page input[type="checkbox"]');
  150. const chkRing = await ev(`(() => { const c = getComputedStyle(document.activeElement); return { style: c.outlineStyle, w: c.outlineWidth, col: c.outlineColor, shadow: c.boxShadow }; })()`);
  151. check(`${w} checkbox focus-visible ring: 2px #569bd4AA outline, no boxShadow`, reachedChk && chkRing.style === 'solid' && chkRing.w === '2px' && eqColor(chkRing.col, 'rgba(86, 155, 212, 0.667)') && chkRing.shadow === 'none', JSON.stringify(chkRing));
  152. // Link hover: no underline
  153. await hover('elements-page section a');
  154. const linkDeco = await ev(`getComputedStyle(document.querySelector('elements-page section a')).textDecorationLine`);
  155. check(`${w} link hover: no underline`, linkDeco === 'none', linkDeco);
  156. // Brand in bar: weight 100, 1.4rem (22.4px)
  157. check(`${w} brand in header: weight 100, 1.4rem`, base.brandWeight === '100' && base.brandSize === '22.4px', JSON.stringify({ w: base.brandWeight, s: base.brandSize }));
  158. if (w === 1280) {
  159. // Purple accent must NOT change default button colorAction
  160. await page.click('accent-switcher button[value="purple"]');
  161. await sleep(150);
  162. const btnWithPurple = await ev(`getComputedStyle(document.querySelector('elements-page p.row button:not(.primary):not(.danger):not(:disabled)')).backgroundColor`);
  163. const priWithPurple = await ev(`getComputedStyle(document.querySelector('elements-page p.row button.primary')).backgroundColor`);
  164. await page.click('accent-switcher button.reset');
  165. await sleep(150);
  166. check('1280 default button stays #569bd4 (colorAction, not app accent) when accent is purple', btnWithPurple === 'rgb(86, 155, 212)' && priWithPurple === 'rgb(197, 134, 192)', JSON.stringify({ btnWithPurple, priWithPurple }));
  167. // Sidebar at desktop
  168. check('1280 sidebar: darker bg, 16rem, padding 1rem, gap .5rem', base.sbBg === 'rgb(20, 25, 30)' && base.sbW === '256px' && base.sbPad === '16px' && base.sbGap === '8px', JSON.stringify({ bg: base.sbBg, w: base.sbW, pad: base.sbPad, gap: base.sbGap }));
  169. check('1280 sidebar h2: no uppercase', base.sbh2Transform === 'none', base.sbh2Transform);
  170. check('1280 sidebar links: padding .25rem .5rem', base.sbaPad === '4px 8px', base.sbaPad);
  171. await hover('#sidebar nav a[href="/"]');
  172. const sbHoverBg = await ev(`getComputedStyle(document.querySelector('#sidebar nav a[href="/"]')).backgroundColor`);
  173. check('1280 sidebar link hover: no hover background', sbHoverBg === 'rgba(0, 0, 0, 0)', sbHoverBg);
  174. check('1280 sidebar active item: white on rgba(86, 155, 212, .22), radiusSmall', base.sbcurColor === 'rgb(255, 255, 255)' && eqColor(base.sbcurBg, 'rgba(86, 155, 212, 0.22)') && base.sbcurRadius === '5px', JSON.stringify({ col: base.sbcurColor, bg: base.sbcurBg, r: base.sbcurRadius }));
  175. } else {
  176. // Phone sidebar popover: below 3.25rem bar, darker bg, 16rem, padding 1rem, gap .5rem, backdrop rgba(0,0,0,.45)
  177. await page.click('application-header .menu-toggle');
  178. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar open 390' });
  179. await sleep(200);
  180. const pop = await ev(`(() => {
  181. const el = document.querySelector('#sidebar');
  182. const r = el.getBoundingClientRect();
  183. const cs = getComputedStyle(el);
  184. const bd = getComputedStyle(el, '::backdrop');
  185. const a = getComputedStyle(document.querySelector('#sidebar nav a'));
  186. const cur = getComputedStyle(document.querySelector('#sidebar main-menu a.current'));
  187. return {
  188. x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height),
  189. bg: cs.backgroundColor, pad: cs.paddingTop, gap: cs.rowGap,
  190. bdBg: bd.backgroundColor, bdOp: bd.opacity,
  191. aPad: a.paddingTop + ' ' + a.paddingLeft,
  192. curCol: cur.color, curBg: cur.backgroundColor, curRad: cur.borderTopLeftRadius,
  193. };
  194. })()`);
  195. check('390 sidebar popover: darker bg, 16rem, left below 3.25rem bar, padding 1rem, gap .5rem', pop.x === 0 && pop.y === 52 && pop.w === 256 && pop.bg === 'rgb(20, 25, 30)' && pop.pad === '16px' && pop.gap === '8px', JSON.stringify(pop));
  196. check('390 sidebar backdrop: rgba(0, 0, 0, .45)', eqColor(pop.bdBg, 'rgba(0, 0, 0, 0.45)') && Number(pop.bdOp) === 1, JSON.stringify({ bdBg: pop.bdBg, bdOp: pop.bdOp }));
  197. check('390 sidebar active menu link: white on rgba(86, 155, 212, .22), radiusSmall', pop.curCol === 'rgb(255, 255, 255)' && eqColor(pop.curBg, 'rgba(86, 155, 212, 0.22)') && pop.curRad === '5px', JSON.stringify(pop));
  198. await ev(`document.querySelector('#sidebar').hidePopover()`);
  199. }
  200. };
  201. await checkCoreStyles(390);
  202. await checkCoreStyles(1280);
  203. // Breakpoint at 800 px (768px breakpoint means 800px is desktop layout)
  204. await size(800, 1280);
  205. await open('/elements');
  206. const bp1 = await ev(`(() => {
  207. const s = (q) => { const el = document.querySelector(q); const c = getComputedStyle(el); const r = el.getBoundingClientRect(); return { disp: c.display, pos: c.position, w: Math.round(r.width) }; };
  208. return { sb: s('#sidebar'), toggle: s('application-header .menu-toggle'), menu: s('application-header main-menu'), main: s('content-first > main') };
  209. })()`);
  210. check('800 content-first: desktop layout (sidebar beside main, no toggle, main-menu in header)', bp1.sb.disp !== 'none' && (bp1.sb.pos === 'sticky' || bp1.sb.pos === 'static') && bp1.sb.w === 256 && bp1.toggle.disp === 'none' && bp1.menu.disp !== 'none', JSON.stringify(bp1));
  211. await open('/shells/list-first/trip');
  212. const bp2 = await ev(`(() => {
  213. const a = document.querySelector('list-first > aside').getBoundingClientRect();
  214. const m = document.querySelector('list-first > main').getBoundingClientRect();
  215. return { aw: Math.round(a.width), mw: Math.round(m.width), sideBySide: m.left >= a.right - 1 };
  216. })()`);
  217. check('800 list-first: aside and main side by side', bp2.aw > 0 && bp2.mw > 0 && bp2.sideBySide, JSON.stringify(bp2));
  218. await open('/shells/three-pane/m2');
  219. const bp3 = await ev(`(() => {
  220. const s = document.querySelector('#sidebar').getBoundingClientRect();
  221. const a = document.querySelector('three-pane > aside').getBoundingClientRect();
  222. const m = document.querySelector('three-pane > main').getBoundingClientRect();
  223. return { sw: Math.round(s.width), aw: Math.round(a.width), mw: Math.round(m.width) };
  224. })()`);
  225. check('800 three-pane: sidebar, aside and main all visible without squeezing main', bp3.sw > 0 && bp3.aw > 0 && bp3.mw >= 300, JSON.stringify(bp3));
  226. }
  227. try {
  228. await main();
  229. } catch (e) {
  230. failures++;
  231. console.log('FAIL (aborted) ' + (e && e.stack || e));
  232. } finally {
  233. await stop();
  234. }
  235. console.log(`\n${passes} passed, ${failures} failed`);
  236. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • 88e1d14d|||PR layouts#9: address Kunibert findings (3-pane 768px, :where invalid focus, placeholder & glow contrast)Atlas
  • 8c875a78|||PR layouts#9: match HyperConductor look (lines 1-21)Atlas
  • 4099e64aMerge branch 'font-segoe-ui' into mainAtlas
  • e14fb795|||PR Theme font: Segoe UI first (his choice 2026-11-19)Atlas
  • 44071d2cMerge branch 'hl-standard-5' into mainAtlas
  • 5ea64202|||PR Gate: count the new-tab check's console errors tooAtlas
  • 2752ceddMerge branch 'hl-standard-4' into mainAtlas
  • ac552b81|||PR Gate: keyboard (Tab/Enter/Space) and Back/Forward/reload/new-tab checks (HL-STANDARD F5, F21)Atlas
  • 8cddcaa9Merge branch 'hl-standard-2' into mainAtlas
  • 2b480a64|||PR Type the route parameter of main-menu build (HL-STANDARD L10)Atlas
  • ab54a39dMerge branch 'hl-standard' into mainAtlas
  • 04d36fcf|||PR Type function parameters and drop unneeded let (HL-STANDARD L2, L10)Atlas
  • 220c8fa4Merge branch 'readme-audit' into mainAtlas
  • b78fb85a|||PR README matches the codemre
  • 9f351699Preserve comments and nest supported selectors without changing rendered outputmre
  • 97110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre
  • ce4a0baeKeep caller slot styles whole so minimal shell apps startmre
  • 12cd3992Re-vendor complete Hybriel plugins and runtime to day44mre
  • b05c20feBackup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 8d9ed0b8Re-vendor complete Hybriel plugins and runtime to day39mre