Datasets:
Download tasks/c07/repo/scripts/measure.mjs from Roy-DOU/Webdev-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c07/repo/scripts/measure.mjs
- Command line
-
hf download hf://datasets/Roy-DOU/Webdev-Bench/tasks/c07/repo/scripts/measure.mjs
-
curl -L -o measure.mjs https://huggingface.co/datasets/Roy-DOU/Webdev-Bench/resolve/main/tasks/c07/repo/scripts/measure.mjs
1.49 kB
| import { chromium } from 'playwright' | |
| const browser = await chromium.launch() | |
| const page = await browser.newPage() | |
| await page.goto('http://localhost:5173/') | |
| await page.evaluate(() => document.fonts.ready) | |
| const res = await page.evaluate(async () => { | |
| // load Jost too | |
| const style = document.createElement('style') | |
| document.head.appendChild(style) | |
| const texts = { | |
| h1a: 'Wir machen', h1b: 'dieses Internet', | |
| k1: 'Vertrauen gut,', k2: 'Logos besser', | |
| man: 'Manifest', cta: "Gehen wir's an.", | |
| lead1: 'Keine Templates, nix von der Stange: Wir entwickeln', | |
| lead2: 'vollmundige Webseiten, die Unternehmen immer von der', | |
| mtitle: 'Liberté, Égalité,', | |
| mbody: 'schaffen ein kleines Stück digitaler Freiheit, in der Inhalte für alle', | |
| ct1: 'Bautz Festival', ct2: 'David&Goliath', | |
| sub1: 'Progressive Web App für Lüdenscheids fettestes Festival', | |
| link1: 'Case ansehen', | |
| nav: 'Home Referenzen Manifest', | |
| } | |
| const ctx = document.createElement('canvas').getContext('2d') | |
| const out = {} | |
| for (const [fam, weights] of [['Poppins', [400,500,600]], ['Jost', [400,500,600]]]) { | |
| for (const w of weights) { | |
| try { await document.fonts.load(`${w} 100px ${fam}`) } catch (e) {} | |
| ctx.font = `${w} 100px ${fam}` | |
| for (const [k, t] of Object.entries(texts)) { | |
| out[`${fam}-${w}-${k}`] = Math.round(ctx.measureText(t).width) | |
| } | |
| } | |
| } | |
| return out | |
| }) | |
| console.log(JSON.stringify(res, null, 2)) | |
| await browser.close() | |