igneum/tools/ui-mock/fold-measure.cjs

23 lines
2.1 KiB
JavaScript

// Measures where the key elements of a page end inside the viewport, on the mock, with Playwright's Chromium (build-2's
// overlap env: NODE_PATH and IGNEUM_PLAYWRIGHT_DIR from /srv/builds/_bin/overlap/env.sh). Prints one JSON line per
// viewport and page: { w, h, page, items: { id: { top, bottom, fits } } }.
// node tools/ui-mock/fold-measure.cjs <mock base url> [pages...]
const base = process.argv[2]; const pages = process.argv.slice(3).length ? process.argv.slice(3) : ['overview', 'cards', 'earnings', 'prove'];
const { chromium } = require('playwright');
const SIZES = [[1280, 800], [1440, 900], [1920, 1080]];
const KEYS = { overview: ['#totals', '#btn-toggle', '#ladder-strip', '#dag-card', '#node-card .card-head, #node-card h3, #node-card'], cards: ['#tune-card, .tune-strip', '#d-cards .gpu-line:first-child'], earnings: ['.earn', '#ladder-card .card-head'], prove: ['#page-prove .card:first-child', '#s-prove'] };
(async () => {
const dir = process.env.IGNEUM_PLAYWRIGHT_DIR; const exe = process.env.PLAYWRIGHT_CHROMIUM;
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
for (const [w, h] of SIZES) {
const page = await browser.newPage({ viewport: { width: w, height: h }, reducedMotion: 'reduce', colorScheme: 'dark' });
for (const p of pages) {
await page.goto(`${base}/t/mock/?scenario=${p === 'cards' ? 'rig' : 'live'}&page=${p}&theme=dark`, { waitUntil: 'load' });
await page.waitForTimeout(1500);
const items = await page.evaluate((keys) => { const out = {}; for (const k of keys) { const el = document.querySelector(k); if (!el) { out[k] = null; continue; } const r = el.getBoundingClientRect(); out[k] = { top: Math.round(r.top), bottom: Math.round(r.bottom), fits: r.bottom <= window.innerHeight && r.top >= 0 }; } out.scrollHeight = document.querySelector('main').scrollHeight; out.inner = window.innerHeight; return out; }, KEYS[p]);
console.log(JSON.stringify({ w, h, page: p, items }));
}
await page.close();
}
await browser.close();
})().catch((e) => { console.error(e); process.exit(1); });