| 1 | // Widget profile, step 1: which CSS/HTML features each renderer actually |
| 2 | // supports, measured rather than assumed. Every probe is a tiny widget whose |
| 3 | // feature, when supported, puts a known colour at a known pixel; it goes |
| 4 | // through the real pipeline (QuickJS sandbox → validator → renderer) in the |
| 5 |
| 6 | // -DTW_BLITZ=ON -DTW_LITEHTML=ON), and through the validator alone under Node |
| 7 | // to see whether the validator itself keeps the feature (what the product |
| 8 | // iframe/WebView would get). Output: reports/profile/probes.json and a |
| 9 | // Markdown table on stdout, pasted into docs/widget-profile-draft.md (historical; the profile is docs/profile-v1.md). |
| 10 | // |
| 11 | // corepack pnpm tsx scripts/profile/probes.ts [--only grid,flex-gap] |
| 12 |
| 13 | import { spawnSync } from 'node:child_process'; |
| 14 | import fs from 'node:fs'; |
| 15 | import path from 'node:path'; |
| 16 | import { fileURLToPath } from 'node:url'; |
| 17 | import { PNG } from 'pngjs'; |
| 18 | import { runWidget } from '@telegram/widget-sandbox/node'; |
| 19 |
| 20 | const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..'); |
| 21 | const run = path.join(root, 'packages', 'desktop', 'build', 'twidget-run'); |
| 22 | const out = path.join(root, 'reports', 'profile'); |
| 23 | const probeDir = path.join(out, 'probes'); |
| 24 | fs.mkdirSync(probeDir, { recursive: true }); |
| 25 |
| 26 | type Color = 'red' | 'blue' | 'white' | 'pink' | 'gray' | 'notwhite'; |
| 27 | interface Check { x: number; y: number; is: Color } |
| 28 | /** A region where some pixel must be (or none may be) red / non-white. */ |
| 29 | interface Region { x0: number; y0: number; x1: number; y1: number; has: 'red' | 'notwhite'; expect: boolean } |
| 30 | interface Probe { |
| 31 | key: string; |
| 32 | /** What the product (iframe / WebView) does with it; the probe's reason to exist. */ |
| 33 | feature: string; |
| 34 | html: string; |
| 35 | checks?: Check[]; |
| 36 | regions?: Region[]; |
| 37 | /** A token that must survive in the validated CSS/ops for the validator to count as "keeps" (default: feature used in a style). */ |
| 38 | keep?: RegExp; |
| 39 | } |
| 40 |
| 41 | const BASE = '<style>html,body{margin:0;padding:0;background:#fff}</style>'; |
| 42 | const box = (style: string, inner = '') => `<div style="width:100px;height:50px;background:#f00;${style}">${inner}</div>`; |
| 43 | const redPng = (() => { |
| 44 | const png = new PNG({ width: 2, height: 2 }); |
| 45 | for (let i = 0; i < 16; i += 4) { png.data[i] = 255; png.data[i + 1] = 0; png.data[i + 2] = 0; png.data[i + 3] = 255; } |
| 46 | return 'data:image/png;base64,' + PNG.sync.write(png).toString('base64'); |
| 47 | })(); |
| 48 |
| 49 | const PROBES: Probe[] = [ |
| 50 | { key: 'grid', feature: 'display: grid (two columns)', html: '<div style="display:grid;grid-template-columns:1fr 1fr"><div style="height:50px;background:#00f"></div><div style="height:50px;background:#f00"></div></div>', checks: [{ x: 225, y: 25, is: 'red' }, { x: 75, y: 25, is: 'blue' }], keep: /grid-template-columns/ }, |
| 51 | { key: 'flex-gap', feature: 'flex + gap', html: '<div style="display:flex;gap:20px"><div style="width:40px;height:40px;background:#f00"></div><div style="width:40px;height:40px;background:#f00"></div></div>', checks: [{ x: 50, y: 20, is: 'white' }, { x: 70, y: 20, is: 'red' }], keep: /gap/ }, |
| 52 | { key: 'box-shadow', feature: 'box-shadow', html: '<div style="width:50px;height:50px;background:#00f;box-shadow:100px 0 0 0 #f00"></div>', checks: [{ x: 125, y: 25, is: 'red' }], keep: /box-shadow/ }, |
| 53 | { key: 'opacity', feature: 'opacity', html: box('opacity:.5'), checks: [{ x: 50, y: 25, is: 'pink' }], keep: /opacity/ }, |
| 54 | { key: 'transform-2d', feature: 'transform: translateX', html: '<div style="width:50px;height:50px;background:#f00;transform:translateX(100px)"></div>', checks: [{ x: 125, y: 25, is: 'red' }, { x: 25, y: 25, is: 'white' }], keep: /translateX/ }, |
| 55 | { key: 'transform-3d', feature: 'transform: rotateY(180deg) + backface-visibility: hidden (card flip)', html: box('transform:rotateY(180deg);backface-visibility:hidden'), checks: [{ x: 50, y: 25, is: 'white' }], keep: /rotateY/ }, |
| 56 | { key: 'overflow-clip', feature: 'overflow: hidden clips', html: '<div style="width:100px;height:50px;overflow:hidden"><div style="width:100px;height:200px;background:#f00"></div></div>', checks: [{ x: 50, y: 100, is: 'white' }, { x: 50, y: 25, is: 'red' }], keep: /overflow/ }, |
| 57 | { key: 'overflow-auto-clip', feature: 'overflow: auto clips (scrolling itself is interactive, not probed)', html: '<div style="width:100px;height:50px;overflow:auto"><div style="width:80px;height:200px;background:#f00"></div></div>', checks: [{ x: 40, y: 100, is: 'white' }, { x: 40, y: 25, is: 'red' }], keep: /overflow/ }, |
| 58 | { key: 'border-radius-clip', feature: 'border-radius + overflow: hidden rounds children', html: '<div style="width:100px;height:100px;border-radius:50px;overflow:hidden"><div style="width:100px;height:100px;background:#f00"></div></div>', checks: [{ x: 3, y: 3, is: 'white' }, { x: 50, y: 50, is: 'red' }], keep: /border-radius/ }, |
| 59 | { key: 'svg-inline', feature: 'inline <svg> with presentation attributes', html: '<svg width="100" height="50"><rect width="100" height="50" fill="#f00"/></svg>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /"svg"/ }, |
| 60 | { key: 'svg-css', feature: 'inline <svg> styled from CSS (fill in a rule)', html: '<style>.r{fill:#f00}</style><svg width="100" height="50"><rect class="r" width="100" height="50"/></svg>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /fill/ }, |
| 61 | { key: 'img-png', feature: '<img src="data:image/png">', html: `<img src="${redPng}" style="width:100px;height:50px;display:block">`, checks: [{ x: 50, y: 25, is: 'red' }], keep: /data:image\/png/ }, |
| 62 | { key: 'img-svg', feature: '<img src="data:image/svg+xml">', html: `<img src="data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect width="10" height="10" fill="#f00"/></svg>')}" style="width:100px;height:50px;display:block">`, checks: [{ x: 50, y: 25, is: 'red' }], keep: /svg\+xml/ }, |
| 63 | { key: 'bg-image', feature: 'background-image: url(data:png)', html: box(`background:url(${redPng}) 0 0/100px 50px no-repeat`), checks: [{ x: 50, y: 25, is: 'red' }], keep: /data:image\/png/ }, |
| 64 | { key: 'canvas', feature: '<canvas> 2D (fillRect through the command stream)', html: '<canvas id="c" width="100" height="50" style="display:block"></canvas><script>var x=document.getElementById("c").getContext("2d");x.fillStyle="#f00";x.fillRect(0,0,100,50)</script>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /"canvas"/ }, |
| 65 | { key: 'input-value', feature: '<input> draws its value', html: '<input value="MMMMMMMMMM" style="width:200px;height:30px;font-size:20px;color:#000;border:0;padding:0;background:#fff;display:block">', regions: [{ x0: 2, y0: 2, x1: 120, y1: 28, has: 'notwhite', expect: true }], keep: /value/ }, |
| 66 | { key: 'select', feature: '<select> shows the selected option', html: '<select style="width:200px;height:30px;font-size:20px;color:#000;border:0;padding:0;background:#fff;display:block"><option>MMMMMMMM</option></select>', regions: [{ x0: 2, y0: 2, x1: 120, y1: 28, has: 'notwhite', expect: true }], keep: /"select"/ }, |
| 67 | { key: 'range', feature: '<input type=range> draws a track/thumb', html: '<input type="range" style="width:200px;display:block">', regions: [{ x0: 0, y0: 0, x1: 200, y1: 30, has: 'notwhite', expect: true }], keep: /range/ }, |
| 68 | { key: 'checkbox', feature: '<input type=checkbox checked> draws a mark', html: '<input type="checkbox" checked style="display:block;margin:0">', regions: [{ x0: 0, y0: 0, x1: 20, y1: 20, has: 'notwhite', expect: true }], keep: /checkbox/ }, |
| 69 | { key: 'button', feature: '<button> has a visible box', html: '<button style="width:100px;height:40px;display:block;background:#f00;border:0">b</button>', checks: [{ x: 50, y: 20, is: 'red' }], keep: /"button"/ }, |
| 70 | { key: 'aspect-ratio', feature: 'aspect-ratio', html: '<div style="width:100px;aspect-ratio:1;background:#f00"></div>', checks: [{ x: 50, y: 90, is: 'red' }], keep: /aspect-ratio/ }, |
| 71 | { key: 'clamp', feature: 'clamp() in width', html: '<div style="width:clamp(50px,200px,100px);height:50px;background:#f00"></div>', checks: [{ x: 75, y: 25, is: 'red' }, { x: 150, y: 25, is: 'white' }], keep: /clamp/ }, |
| 72 | { key: 'calc', feature: 'calc() in width', html: '<div style="width:calc(50px + 50px);height:50px;background:#f00"></div>', checks: [{ x: 75, y: 25, is: 'red' }, { x: 150, y: 25, is: 'white' }], keep: /calc/ }, |
| 73 | { key: 'var', feature: 'var(--x)', html: '<style>:root{--w:100px}</style><div style="width:var(--w);height:50px;background:#f00"></div>', checks: [{ x: 75, y: 25, is: 'red' }, { x: 150, y: 25, is: 'white' }], keep: /--w/ }, |
| 74 | { key: 'vw', feature: 'vw unit (viewport = bubble width)', html: '<div style="width:50vw;height:50px;background:#f00"></div>', checks: [{ x: 100, y: 25, is: 'red' }, { x: 200, y: 25, is: 'white' }], keep: /vw/ }, |
| 75 | { key: 'light-dark', feature: 'light-dark() colour (light theme; the validator resolves it to the theme colour, so "drops" here means "resolved")', html: '<style>:root{color-scheme:light dark}</style><div style="width:100px;height:50px;background:light-dark(#f00,#00f)"></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /light-dark/ }, |
| 76 | { key: 'color-mix', feature: 'color-mix()', html: '<div style="width:100px;height:50px;background:color-mix(in srgb,#f00,#f00)"></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /color-mix/ }, |
| 77 | { key: 'filter', feature: 'filter: grayscale(1)', html: box('filter:grayscale(1)'), checks: [{ x: 50, y: 25, is: 'gray' }], keep: /grayscale/ }, |
| 78 | { key: 'pseudo-before', feature: '::before with content', html: '<style>.b::before{content:"";display:block;width:100px;height:50px;background:#f00}</style><div class="b"></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /before/ }, |
| 79 | { key: 'nth-child', feature: ':nth-child(2)', html: '<style>.l div{height:50px}.l div:nth-child(2){background:#f00}</style><div class="l"><div></div><div></div></div>', checks: [{ x: 50, y: 75, is: 'red' }, { x: 50, y: 25, is: 'white' }], keep: /nth-child/ }, |
| 80 | { key: 'is-selector', feature: ':is()', html: '<style>:is(.a) .b{width:100px;height:50px;background:#f00}</style><div class="a"><div class="b"></div></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /:is\(/ }, |
| 81 | { key: 'has-selector', feature: ':has()', html: '<style>.a:has(.b){width:100px;height:50px;background:#f00}</style><div class="a"><span class="b"></span></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /:has\(/ }, |
| 82 | { key: 'nesting', feature: 'CSS nesting (.a { .b { } })', html: '<style>.a{.b{width:100px;height:50px;background:#f00}}</style><div class="a"><div class="b"></div></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /\.b\{/ }, |
| 83 | { key: 'supports', feature: '@supports (display: grid)', html: '<style>@supports (display:grid){.a{width:100px;height:50px;background:#f00}}</style><div class="a"></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /@supports/ }, |
| 84 | { key: 'media-width', feature: '@media (min-width: 200px) (bubble is 300 wide)', html: '<style>@media (min-width:200px){.a{width:100px;height:50px;background:#f00}}</style><div class="a"></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /min-width/ }, |
| 85 | { key: 'keyframes-forwards', feature: '@keyframes + animation 0s forwards (end state applied)', html: '<style>@keyframes a{to{background:#f00}}</style><div style="width:100px;height:50px;background:#00f;animation:a 0s forwards"></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /@keyframes/ }, |
| 86 | { key: 'position-absolute', feature: 'position: absolute inside relative', html: '<div style="position:relative;height:50px"><div style="position:absolute;left:150px;top:0;width:50px;height:50px;background:#f00"></div></div>', checks: [{ x: 175, y: 25, is: 'red' }], keep: /absolute/ }, |
| 87 | { key: 'z-index', feature: 'z-index stacking (earlier box on top)', html: '<div style="position:relative;height:50px"><div style="position:absolute;z-index:2;width:50px;height:50px;background:#f00"></div><div style="position:absolute;width:50px;height:50px;background:#00f"></div></div>', checks: [{ x: 25, y: 25, is: 'red' }], keep: /z-index/ }, |
| 88 | { key: 'visibility-hidden', feature: 'visibility: hidden', html: box('visibility:hidden'), checks: [{ x: 50, y: 25, is: 'white' }], keep: /visibility/ }, |
| 89 | { key: 'logical-margin', feature: 'margin-inline-start (logical property)', html: box('margin-inline-start:100px'), checks: [{ x: 50, y: 25, is: 'white' }, { x: 150, y: 25, is: 'red' }], keep: /margin-inline-start/ }, |
| 90 | { key: 'clip-path', feature: 'clip-path: inset()', html: box('clip-path:inset(0 50% 0 0)'), checks: [{ x: 25, y: 25, is: 'red' }, { x: 75, y: 25, is: 'white' }], keep: /clip-path/ }, |
| 91 | { key: 'linear-gradient', feature: 'linear-gradient', html: '<div style="width:200px;height:50px;background:linear-gradient(90deg,#f00 0,#f00 50%,#00f 50%,#00f 100%)"></div>', checks: [{ x: 50, y: 25, is: 'red' }, { x: 150, y: 25, is: 'blue' }], keep: /linear-gradient/ }, |
| 92 | { key: 'radial-gradient', feature: 'radial-gradient', html: '<div style="width:100px;height:100px;background:radial-gradient(circle at center,#f00 0 20%,#00f 21%)"></div>', checks: [{ x: 50, y: 50, is: 'red' }, { x: 5, y: 5, is: 'blue' }], keep: /radial-gradient/ }, |
| 93 | { key: 'conic-gradient', feature: 'conic-gradient', html: '<div style="width:100px;height:100px;background:conic-gradient(#f00 0 25%,#00f 25% 100%)"></div>', checks: [{ x: 75, y: 15, is: 'red' }, { x: 25, y: 75, is: 'blue' }], keep: /conic-gradient/ }, |
| 94 | { key: 'text-shadow', feature: 'text-shadow', html: '<div style="font:40px sans-serif;color:#fff;text-shadow:60px 0 0 #f00;width:200px;height:50px">MMMM</div>', regions: [{ x0: 60, y0: 0, x1: 200, y1: 50, has: 'red', expect: true }], keep: /text-shadow/ }, |
| 95 | { key: 'emoji', feature: 'colour emoji glyph (host font; measured on macOS)', html: '<div style="font:40px sans-serif;height:50px">🎨</div>', regions: [{ x0: 0, y0: 0, x1: 50, y1: 50, has: 'notwhite', expect: true }] }, |
| 96 | { key: 'details-open', feature: '<details open> shows its content', html: '<details open><summary style="height:20px">s</summary><div style="width:100px;height:50px;background:#f00"></div></details>', regions: [{ x0: 0, y0: 20, x1: 100, y1: 90, has: 'red', expect: true }], keep: /details/ }, |
| 97 | { key: 'details-closed', feature: '<details> (closed) hides its content', html: '<details><summary style="height:20px">s</summary><div style="width:100px;height:50px;background:#f00"></div></details>', regions: [{ x0: 0, y0: 0, x1: 100, y1: 100, has: 'red', expect: false }], keep: /details/ }, |
| 98 | { key: 'table', feature: '<table>: cells sized by CSS width/height (litehtml honours the width, ignores the height)', html: '<p style="margin:0;height:20px">t</p><table style="border-collapse:collapse;color:transparent"><tr><td style="width:100px;height:50px;background:#00f;padding:0">a</td><td style="width:100px;height:50px;background:#f00;padding:0">b</td></tr></table>', checks: [{ x: 150, y: 45, is: 'red' }], keep: /"table"/ }, |
| 99 | { key: 'table-first', feature: '<table> as the first block in <body> (same, without a preceding paragraph)', html: '<table style="border-collapse:collapse;color:transparent"><tr><td style="width:100px;height:50px;background:#00f;padding:0">a</td><td style="width:100px;height:50px;background:#f00;padding:0">b</td></tr></table>', checks: [{ x: 150, y: 25, is: 'red' }], keep: /"table"/ }, |
| 100 | { key: 'sticky', feature: 'position: sticky (lays out in flow; stickiness is interactive, not probed)', html: '<div style="height:50px"><div style="position:sticky;top:0;width:100px;height:50px;background:#f00"></div></div>', checks: [{ x: 50, y: 25, is: 'red' }], keep: /sticky/ }, |
| 101 | { key: 'pre-wrap', feature: 'white-space: pre (line break kept → second line)', html: '<div style="white-space:pre;font:20px/50px sans-serif;color:#fff"><span style="background:#00f">A</span>\n<span style="background:#f00">B</span></div>', checks: [{ x: 5, y: 75, is: 'red' }], keep: /pre/ }, |
| 102 | { key: 'word-wrap', feature: 'overflow-wrap: anywhere breaks a long word', html: '<div style="width:60px;font:20px/25px monospace;overflow-wrap:anywhere;color:#fff"><span style="background:#f00">MMMMMMMMMMMMMMMMMMMM</span></div>', regions: [{ x0: 0, y0: 30, x1: 60, y1: 50, has: 'red', expect: true }], keep: /overflow-wrap/ }, |
| 103 | ]; |
| 104 |
| 105 | function classify(r: number, g: number, b: number, a: number): Color[] { |
| 106 | if (a < 20) return ['white']; |
| 107 | const c: Color[] = []; |
| 108 | const isRed = r > 200 && g < 60 && b < 60; |
| 109 | const isBlue = b > 200 && r < 60 && g < 60; |
| 110 | const isWhite = r > 235 && g > 235 && b > 235; |
| 111 | if (isRed) c.push('red'); |
| 112 | if (isBlue) c.push('blue'); |
| 113 | if (isWhite) c.push('white'); |
| 114 | if (r > 200 && g > 90 && g < 170 && b > 90 && b < 170) c.push('pink'); |
| 115 | if (Math.abs(r - g) < 25 && Math.abs(g - b) < 25 && r < 200) c.push('gray'); |
| 116 | if (!isWhite) c.push('notwhite'); |
| 117 | return c; |
| 118 | } |
| 119 |
| 120 | interface EngineResult { pass: boolean | null; detail: string } |
| 121 |
| 122 | function judge(png: PNG | null, p: Probe): EngineResult { |
| 123 | if (!png) return { pass: null, detail: 'no raster' }; |
| 124 | const px = (x: number, y: number) => { |
| 125 | if (x >= png.width || y >= png.height) return [255, 255, 255, 0]; |
| 126 | const i = (y * png.width + x) * 4; |
| 127 | return [png.data[i], png.data[i + 1], png.data[i + 2], png.data[i + 3]]; |
| 128 | }; |
| 129 | const fails: string[] = []; |
| 130 | for (const c of p.checks ?? []) { |
| 131 | const [r, g, b, a] = px(c.x, c.y); |
| 132 | if (!classify(r, g, b, a).includes(c.is)) fails.push(`(${c.x},${c.y}) = rgba(${r},${g},${b},${a}), wanted ${c.is}`); |
| 133 | } |
| 134 | for (const rg of p.regions ?? []) { |
| 135 | let found = false; |
| 136 | for (let y = rg.y0; y < Math.min(rg.y1, png.height) && !found; y++) |
| 137 | for (let x = rg.x0; x < Math.min(rg.x1, png.width); x++) { |
| 138 | const [r, g, b, a] = px(x, y); |
| 139 | if (classify(r, g, b, a).includes(rg.has)) { found = true; break; } |
| 140 | } |
| 141 | if (found !== rg.expect) fails.push(`${rg.has} ${rg.expect ? 'missing' : 'present'} in [${rg.x0},${rg.y0}..${rg.x1},${rg.y1}]`); |
| 142 | } |
| 143 | return { pass: fails.length === 0, detail: fails.join('; ') }; |
| 144 | } |
| 145 |
| 146 | function render(engine: 'blitz' | 'litehtml', file: string, png: string): PNG | null { |
| 147 | const r = spawnSync(run, [file, `--${engine}`, '--dpr', '1', '--width', '300', '--wait-ms', '400', '--png', png], { encoding: 'utf8' }); |
| 148 | if (!fs.existsSync(png)) { console.error(`${engine} ${path.basename(file)}: no png\n${(r.stdout + r.stderr).slice(-400)}`); return null; } |
| 149 | try { return PNG.sync.read(fs.readFileSync(png)); } catch { return null; } |
| 150 | } |
| 151 |
| 152 | async function main() { |
| 153 | if (!fs.existsSync(run)) { console.error(`${run} not built: cd desktop && cmake -S . -B build -G Ninja -DTW_BLITZ=ON -DTW_LITEHTML=ON && cmake --build build`); process.exit(2); } |
| 154 | const only = process.argv.includes('--only') ? process.argv[process.argv.indexOf('--only') + 1].split(',') : null; |
| 155 | const results: { key: string; feature: string; validator: boolean; blitz: EngineResult; litehtml: EngineResult }[] = []; |
| 156 | for (const p of PROBES) { |
| 157 | if (only && !only.includes(p.key)) continue; |
| 158 | const html = BASE + p.html; |
| 159 | const file = path.join(probeDir, `${p.key}.html`); |
| 160 | fs.writeFileSync(file, html); |
| 161 | // the validator alone: does the feature survive into the render ops? |
| 162 | const res = await runWidget(html, { timerRounds: 0 }); |
| 163 | const ops = JSON.stringify(res.renderOps); |
| 164 | const validator = p.keep ? p.keep.test(ops) : true; |
| 165 | const blitz = judge(render('blitz', file, path.join(probeDir, `${p.key}.blitz.png`)), p); |
| 166 | const litehtml = judge(render('litehtml', file, path.join(probeDir, `${p.key}.litehtml.png`)), p); |
| 167 | results.push({ key: p.key, feature: p.feature, validator, blitz, litehtml }); |
| 168 | const mark = (e: EngineResult) => (e.pass === null ? '?' : e.pass ? '✅' : '❌'); |
| 169 | console.log(`${p.key.padEnd(20)} validator ${validator ? 'keeps' : 'DROPS'} blitz ${mark(blitz)} litehtml ${mark(litehtml)}${blitz.detail || litehtml.detail ? ` (${[blitz.detail && 'blitz: ' + blitz.detail, litehtml.detail && 'litehtml: ' + litehtml.detail].filter(Boolean).join(' | ')})` : ''}`); |
| 170 | } |
| 171 | // --only: refresh those rows, keep the rest of an earlier full run |
| 172 | const file = path.join(out, 'probes.json'); |
| 173 | let merged = results; |
| 174 | if (only && fs.existsSync(file)) { |
| 175 | const prev = JSON.parse(fs.readFileSync(file, 'utf8')) as typeof results; |
| 176 | const byKey = new Map(prev.map((r) => [r.key, r])); |
| 177 | for (const r of results) byKey.set(r.key, r); |
| 178 | merged = PROBES.map((p) => byKey.get(p.key)).filter((r): r is typeof results[number] => !!r); |
| 179 | } |
| 180 | results.length = 0; |
| 181 | results.push(...merged); |
| 182 | fs.writeFileSync(file, JSON.stringify(results, null, 2)); |
| 183 | const md = ['| Feature | Validator keeps | Blitz | litehtml |', '|---|---|---|---|']; |
| 184 | for (const r of results) { |
| 185 | const mark = (e: EngineResult) => (e.pass === null ? '?' : e.pass ? '✅' : '❌'); |
| 186 | md.push(`| ${r.feature} (\`${r.key}\`) | ${r.validator ? '✅' : '❌'} | ${mark(r.blitz)} | ${mark(r.litehtml)} |`); |
| 187 | } |
| 188 | fs.writeFileSync(path.join(out, 'probes.md'), md.join('\n') + '\n'); |
| 189 | console.log(`\n${results.length} probes → ${path.relative(root, out)}/probes.{json,md}`); |
| 190 | } |
| 191 |
| 192 | main().catch((e) => { console.error(e); process.exit(1); }); |
| 193 |