import { readFileSync } from 'node:fs' import { fileURLToPath, pathToFileURL } from 'node:url' import { dirname, resolve } from 'node:path' import { JSDOM, VirtualConsole } from 'jsdom' const HERE = dirname(fileURLToPath(import.meta.url)) const GATEWAY = process.argv[2] const dist = resolve(HERE, '../../../release/web') const idx = readFileSync(dist + '/index.html', 'utf8') const jsFile = (idx.match(/src="\.\/assets\/([^"]+\.js)"/) || [])[1] const cssFile = (idx.match(/href="\.\/assets\/([^"]+\.css)"/) || [])[1] const code = readFileSync(dist + '/assets/' + jsFile, 'utf8') const css = readFileSync(dist + '/assets/' + cssFile, 'utf8') const dom = new JSDOM(idx.replace('', ''), { url: GATEWAY + '/web/index.html#workbench', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: new VirtualConsole() }) const w = dom.window w.fetch = async () => ({ ok: true, status: 200, json: async () => ({ win: '2026年', tabs: {} }), text: async () => '{}' }) try { w.eval(code) } catch (e) { console.log('EVAL_ERR ' + String(e).slice(0, 140)) } await new Promise((r) => setTimeout(r, 1200)) const d = w.document function probe(sel) { const el = d.querySelector(sel) if (!el) return sel + ' = 缺失' const cs = w.getComputedStyle(el) return sel + ' → max-width=' + (cs.maxWidth || '-') + ' marginLeft=' + (cs.marginLeft || '-') + ' marginRight=' + (cs.marginRight || '-') + ' padding=' + (cs.padding || '-') + ' width=' + (cs.width || '-') } for (const s of ['body', '#app', '.wrap', 'main#root', 'header.top', 'nav.tabs', 'footer#foot']) console.log(probe(s)) // 是否存在把 .wrap 关掉的规则(旧 CSS 里有一条 .wrap{padding:0;max-width:none} 在媒体查询里) const m = css.match(/\.wrap\s*\{[^}]*max-width:none[^}]*\}/g) console.log('CSS_WRAP_OVERRIDE ' + (m ? JSON.stringify(m).slice(0, 200) : 'none')) const mq = css.match(/@media[^{]*\{[^@]*\.wrap\s*\{[^}]*\}/) console.log('CSS_WRAP_IN_MEDIA ' + (mq ? mq[0].slice(0, 220).replace(/\s+/g, ' ') : 'none'))