diff --git a/scripts/ui/census-icons.py b/scripts/ui/census-icons.py new file mode 100644 index 0000000..75a7244 --- /dev/null +++ b/scripts/ui/census-icons.py @@ -0,0 +1,170 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +"""图标可读名称普查(只读,**不进退出码**):页面上每一只 `.anticon` 与它所在控件的名称来源。 + +常驻闸门只回答「有没有缺陷」(`semanticcheck.GLYPH` 数外泄、`classaudit` 数出口形状), +回答不了「这一族缺陷原来有多大、现在缩到多小」。这条脚本量三组数: + + A 组 字形码对辅助技术可见的图标(按字形聚合)——S-2 改前 900 只 / 改后 80 只; + 两条口径分开数:**包围盒口径**(有尺寸 ≠ AT 读得到)与 **AT 可读口径** + (再排除 `visibility:hidden` 的祖先)。S-2 立项时两者差 6 只: + rc-tabs 的「…」在 1440 下是 `visibility:hidden`,包围盒有值但读屏念不到, + 真实溢出只在窄视口出现(`reports/ui_evidence/nex-s2/PROBE3.txt`)。 + 常驻闸 `semanticcheck.GLYPH` 从一开始就按 AT 可读口径判(`semanticcheck.py:227`), + 这条普查脚本原来只按包围盒——补上 `vis` 之后两者口径一致,别再拿裸数当结论。 + B 组 **「图标是宿主唯一语义」**:宿主既没有 `aria-label` 也没有 `title`、又没有文字, + 去掉图标这个控件就没名字 → 这一组才是必须显式具名的位置(S-2 改后 0 条); + D 组 控件的可读名称里混进了字形 token(`aria-label` / `title` / 正文文本撞表)—— + 这一组包含假阳性(正文里真写着 `/api/meta`),所以只打印、不立案。 + +用法(跑完把 stdout 存进证据目录,两份 JSON 是逐条取证): + NEX_BASE=http://127.0.0.1:5199 NEX_CENSUS_OUT=reports/ui_evidence/nex-s2 \ + .venv/bin/python scripts/ui/census-icons.py +环境变量:`NEX_WIDTH`(默认 1440)、`NEX_THEME`(默认 both)、`NEX_CENSUS_OUT`(默认 /tmp/nex_census)。 +""" +import json, os, pathlib, re, sys +from collections import Counter +from playwright.sync_api import sync_playwright + +BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5199") +WIDTH = int(os.environ.get("NEX_WIDTH", "1440")) +THEMES = ["dark", "light"] if os.environ.get("NEX_THEME", "both") == "both" else [os.environ["NEX_THEME"]] +OUT = os.environ.get("NEX_CENSUS_OUT", "/tmp/nex_census") +ROOT = str(pathlib.Path(__file__).resolve().parents[2]) + +src = open(ROOT + "/frontend/src/components/icons/index.ts", encoding="utf8").read() +pairs = [] +for glyph, alias in re.findall(r"export\s*\{\s*(\w+)\s+as\s+(Icon\w+)\s*\}", src): + pairs.append((glyph, alias)) +for alias, glyph in re.findall(r"export\s+const\s+(Icon\w+)\s*=\s*decorative\(\s*(\w+)\s*,", src): + pairs.append((glyph, alias)) + +GLYPHS = {} +for glyph_component, alias in pairs: + token = re.sub(r"(Outlined|Filled|TwoTone)$", "", glyph_component) + token = re.sub(r"(? { + const out = []; + const txt = (n) => (n || '').replace(/\s+/g, ' ').trim(); + const INTERACTIVE = 'a,button,input,select,textarea,[role=button],[role=link],[role=checkbox],[role=radio],[role=switch],[role=combobox],[role=tab],[role=menuitem],[role=option],[role=searchbox]'; + for (const el of document.querySelectorAll('.anticon')) { + const r = el.getBoundingClientRect(); + if (!r.width || !r.height) continue; + const host = el.closest(INTERACTIVE); + let hiddenAncestor = false, anc = el.parentElement; + while (anc) { if (anc.getAttribute && anc.getAttribute('aria-hidden') === 'true') { hiddenAncestor = true; break } anc = anc.parentElement; } + let textHost = host ? txt(host.innerText || '') : ''; + if (!host) { + let p = el.parentElement, depth = 0; + while (p && depth < 5) { const t = txt(p.innerText || ''); if (t) { textHost = t; break } p = p.parentElement; depth++; } + } + out.push({ + cls: txt(el.className), label: el.getAttribute('aria-label') || '', role: el.getAttribute('role') || '', + hidden: el.getAttribute('aria-hidden') || '', hiddenAncestor, + // visibility 是继承来的:祖先 visibility:hidden 时包围盒照样有值,AT 却读不到 + // (页签溢出那颗就是这么被算进改前 42 只的)——所以另外记一笔计算后的 visibility。 + vis: getComputedStyle(el).visibility, + box: [Math.round(r.x), Math.round(r.y), Math.round(r.width), Math.round(r.height)], + host: host ? (host.tagName.toLowerCase() + (host.className ? '.' + txt(host.className).split(' ').slice(0, 3).join('.') : '')) : '', + hostLabel: host ? (host.getAttribute('aria-label') || '') : '', + hostTitle: host ? (host.getAttribute('title') || '') : '', + hostText: textHost.slice(0, 60), + hostIconOnly: host ? !txt(host.innerText || '') : false, + }); + } + return out; +}""" + +NAMES_JS = r"""() => { + const out = []; + const txt = (n) => (n || '').replace(/\s+/g, ' ').trim(); + const sel = 'a,button,[role=button],[role=link],[role=switch],[role=checkbox],[role=radio],[role=tab],[role=menuitem],[role=combobox]'; + for (const el of document.querySelectorAll(sel)) { + const r = el.getBoundingClientRect(); + if (!r.width || !r.height) continue; + out.push({ tag: el.tagName.toLowerCase(), cls: txt(el.className).slice(0, 90), + aria: el.getAttribute('aria-label') || '', title: el.getAttribute('title') || '', + text: txt(el.innerText || '').slice(0, 60), + axName: (el.getAttribute('aria-label') || el.getAttribute('title') || txt(el.innerText || '')).slice(0, 60) }); + } + return out; +}""" + + +def main(): + os.makedirs(OUT, exist_ok=True) + records, ctl_names = [], [] + with sync_playwright() as pw: + browser = pw.chromium.launch() + page = browser.new_page(viewport={"width": WIDTH, "height": 1000}) + for theme in THEMES: + page.add_init_script("try{localStorage.setItem('nex-the','%s')}catch(e){}" % theme) + page.goto(BASE + "/login", wait_until="networkidle") + if page.locator("#login-user").count(): + page.fill("#login-user", "admin"); page.fill("#login-pass", "admin1234") + page.click("button[type=submit]"); page.wait_for_timeout(1500) + pid = page.evaluate("""async () => { const r = await fetch('/api/projects').then(x=>x.json()).catch(()=>null); + const l = Array.isArray(r) ? r : (r && (r.items||r.projects||r.data)) || []; return l.length ? l[0].id : null; }""") + for route in ROUTES: + if "{id}" in route: + if not pid: continue + route = route.replace("{id}", str(pid)) + page.goto(BASE + route, wait_until="networkidle") + page.wait_for_timeout(1800) + tag = "%s/%s%s" % (WIDTH, theme, route) + for rec in page.evaluate(CENSUS_JS): + rec["where"] = tag; records.append(rec) + for c in page.evaluate(NAMES_JS): + c["where"] = tag; ctl_names.append(c) + browser.close() + + gt = set(GLYPHS) + exposed = [r for r in records if r["label"] in gt and not r["hidden"] and not r["hiddenAncestor"]] + # AT 可读口径:排除计算后 visibility:hidden 的(包围盒非零但读屏念不到) + readable = [r for r in exposed if r.get("vis") != "hidden"] + sole = [r for r in readable if r["hostIconOnly"] and not r["hostLabel"] and not r["hostTitle"]] + seensole = set(); sident = [] + for r in sole: + k = (r["label"], r["host"], r["hostText"], r["where"].split("/", 2)[-1]) + if k in seensole: continue + seensole.add(k); sident.append(r) + + name_leaks = [] + for c in ctl_names: + toks = set(re.findall(r"[a-z][a-z-]{2,}", c["axName"].lower())) + if toks & gt: + name_leaks.append((c["where"], c["tag"], c["axName"][:44], ",".join(sorted(toks & gt)))) + + json.dump(records, open(OUT + "/census-icons.json", "w"), ensure_ascii=False, indent=1) + json.dump(ctl_names, open(OUT + "/census-controls.json", "w"), ensure_ascii=False, indent=1) + print("图标读数 %d 条(%s × %s)" % (len(records), WIDTH, "/".join(THEMES))) + print(" 字形名对 AT 可见:%d(包围盒口径)/ %d(AT 可读口径:排除 visibility:hidden 祖先)" + % (len(exposed), len(readable))) + print(" 其中「图标是宿主唯一语义」:%d 条 / %d 种" % (len(sole), len(sident))) + print("\n── B 组:去掉图标就没名字(需要显式可读名称;按 AT 可读口径)") + for r in sident: + print(" %-15s host=%-34s text=%-18s %s" % (r["label"], r["host"][:34], (r["hostText"] or "-")[:18], r["where"][:52])) + print("\n── A 组按字形聚合 top 22") + for lab, n in Counter(r["label"] for r in exposed).most_common(22): + print(" %-18s %d" % (lab, n)) + print("\n── D 组:可读名称里混进字形 token 的控件(去重)") + ded = {} + for w, tag, nm, toks in name_leaks: + ded.setdefault((tag, nm, toks), []).append(w) + for (tag, nm, toks), ws in sorted(ded.items(), key=lambda kv: -len(kv[1])): + print(" %-7s %-26s %-16s ×%-3d %s" % (tag, nm, toks, len(ws), ws[0][:46])) + print(" 合计 %d 条读数 / %d 种" % (len(name_leaks), len(ded))) + print("\nGLYPH 表 %d 项" % len(GLYPHS)) + print("\n(只读普查:这条脚本恒返回 0。要当退出条件用的判据在 semanticcheck.GLYPH 与 classaudit 第 2 闸。)") + + +if __name__ == "__main__": + sys.exit(main() or 0) + diff --git a/scripts/ui/classaudit.mjs b/scripts/ui/classaudit.mjs index 32e1994..9c8e991 100644 --- a/scripts/ui/classaudit.mjs +++ b/scripts/ui/classaudit.mjs @@ -189,6 +189,35 @@ walkIcons(SRC) for (const hit of stray) console.log(`ICON ${hit}`) console.log(`${stray.length} 处绕过登记表的图标 import(只许 ${path.relative(FRONTEND, REGISTRY)})`) +/* ── 第 2 条·附:登记表自身的辅助技术口径(2026-11-08 · S-2)─────────────── + 上面那条只管「别人不许 import 字形」,管不到登记表自己怎么写出口。 + `decorative()` 把「图标默认是装饰」写死在唯一的出口上(登记表顶部规则 5); + 绕过它的三种写法都会让英文字形名重新混进可读名称——「upload 导入脚本」 + 「down 导出」就是这么来的(取证:reports/ui_evidence/nex-s2/ax-BEFORE.json): + a) 裸 re-export: export { UploadOutlined } from '@ant-design/icons' + b) 直接赋值: export const IconUpload = UploadOutlined + c) 换名再导出: export { UploadOutlined as IconUpload } + 对账逐条匹配固定形状 `export const IconX = decorative(Glyph, 'IconX')`: + 加图标的人只会复制旁边一行,不会先读注释,所以形状不对就红。 + 反例由 scripts/ui/gateprobe.py 注入验证(改一条注释不会把这条闸改成恒绿)。 */ +const REG_NAME = path.relative(FRONTEND, REGISTRY) +const regSrc = fs.readFileSync(REGISTRY, 'utf8') +const regHits = [] +for (const m of regSrc.matchAll(/^export\s*\{([^}]*)\}/gm)) { + if (/\bIcon[A-Z]\w*\b|Outlined|Filled|TwoTone/.test(m[1])) + regHits.push(`${REG_NAME}: 图标走了 export {${m[1].trim().slice(0, 54)}}` + + ` —— 不吃 decorative(),字形名会重新进辅助技术树`) +} +const regIcons = [...regSrc.matchAll(/^export const (Icon\w+)\s*=\s*([^\n]*)$/gm)] +for (const [, name, rhs] of regIcons) { + if (!new RegExp(`^decorative\\(\\w+\\s*,\\s*'${name}'\\)$`).test(rhs.trim())) + regHits.push(`${REG_NAME}: ${name} 的出口不是 decorative(Glyph, '${name}')(现在是 ${rhs.trim().slice(0, 46)})` + + ` —— 图标默认必须 aria-hidden,需要图标自己承担语义时显式写 aria-label`) +} +if (!regIcons.length) regHits.push(`${REG_NAME}: 一条 decorative() 图标出口都没匹配到 —— 登记表结构变了,这道闸要跟着改`) +for (const hit of regHits) console.log(`ICONA ${hit}`) +console.log(`${regHits.length} 处图标出口未走 decorative()(登记表 ${regIcons.length} 条出口 / ${stray.length} 处外部 import)`) + /* ── 第 3 条:裸 + + + + @@ -301,6 +344,40 @@ def names(rows, key): return " | ".join(str(r.get(key, "")) for r in rows) +def run_classaudit(src: pathlib.Path): + """在临时源码目录上跑一遍 classaudit,只取图标闸的两类点名行。 + + 其余八闸在只有两三个文件的空目录里必然报 BP 噪音,所以这里**不看退出码**, + 只核对 `ICONA `(登记表出口形状)与 `ICON `(绕过登记表的外部 import)。 + """ + out = subprocess.run(["node", str(CLASSAUDIT), str(src)], + capture_output=True, text=True, timeout=300) + lines = (out.stdout or "").splitlines() + return [ln for ln in lines if ln.startswith("ICONA ")] + [ln for ln in lines if ln.startswith("ICON ")] + + +def gate2_static(): + """把真登记表抄进临时目录,喂给 classaudit 跑「好形状 / 坏形状」各一遍。""" + reg = REGISTRY.read_text(encoding="utf8") + with tempfile.TemporaryDirectory(prefix="nex-gate2-") as td: + root = pathlib.Path(td) + bad_src = reg + for old, new in BAD_SHAPES: + if bad_src.count(old) != 1: + raise SystemExit(f"GATEPROBE_FAIL classaudit.GATE2 —— 反向验证的锚点在登记表里找不到:{old}" + " → 登记表那行改名/删除时,先同步这里的 fixture,别让这条判据变成空转") + bad_src = bad_src.replace(old, new, 1) + shapes = {} + for tag, text, extra in (("good", reg, "import { IconUpload } from './components/icons'\n"), + ("bad", bad_src, "import { StarOutlined } from '@ant-design/icons'\n")): + d = root / tag + (d / "components" / "icons").mkdir(parents=True) + (d / "components" / "icons" / "index.ts").write_text(text, encoding="utf8") + (d / "Probe.tsx").write_text(extra, encoding="utf8") + shapes[tag] = " || ".join(run_classaudit(d)) + return shapes + + def main() -> int: fails = [] with sync_playwright() as pw: @@ -387,26 +464,54 @@ def main() -> int: ("semanticcheck.TABTARGET", semanticcheck.COLLECT, (lambda r: [t["sig"] for t in r.get("tabTargets", [])]), [("pb-semt", True), ("pg-semt", False)]), + # S-2(2026-11-08 起常驻):**外泄清单**只收「宿主没有自己的可读名称」那一种。 + # b/c/d 三种形状都必须不出现在这里——b 是名称已被宿主接管(AT 念的是人话), + # c/d 连候选都不该进。放错任何一条,这条判据不是恒绿就是 78 只装饰图标全响。 + ("semanticcheck.GLYPH", semanticcheck.COLLECT, + (lambda r: [g["host"] + " " + g["tok"] + for g in r.get("glyphs", []) if not g["own"]]), + [("pb-glyph", True), ("pg-glyph", False), + ("pg-glyph2", False), ("pg-glyph3", False)]), + # 同一条判据的**采集面**:遮蔽那种(b)必须仍然被采到,否则上一条里 + # 「pg-glyph 必须放行」是空转——没采到、和采到但判为遮蔽,串里看不出差别。 + ("semanticcheck.GLYPH-seen", semanticcheck.COLLECT, + (lambda r: [g["host"] for g in r.get("glyphs", [])]), + [("pb-glyph", True), ("pg-glyph", True), + ("pg-glyph2", False), ("pg-glyph3", False)]), ] + def verdict(label, marker, should_fire, hay): + hit = marker in hay + ok = hit == should_fire + print(f"{'OK ' if ok else 'FAIL'} {label:<22} {marker:<26} " + f"{'必须点名' if should_fire else '必须放行'} " + f"→ {'点名了' if hit else '没点名'}") + if not ok: + fails.append(f"{label}/{marker}") + print(" 实际:", hay[:400]) + for label, js, key, expectations in checks: rows = pg.evaluate(js) hay = names(rows, key) for marker, should_fire in expectations: - hit = marker in hay - ok = hit == should_fire - print(f"{'OK ' if ok else 'FAIL'} {label:<18} {marker:<12} " - f"{'必须点名' if should_fire else '必须放行'} " - f"→ {'点名了' if hit else '没点名'}") - if not ok: - fails.append(f"{label}/{marker}") - print(" 实际:", hay[:400]) + verdict(label, marker, should_fire, hay) b.close() + # ── 判据 ⑰(不吃页面、不触发 HMR):classaudit 第 2 闸的静态反向验证 + # 这条闸读的是一份**源文件**,页面上种不出反例,只能喂临时目录: + # 真登记表必须全程静音(否则它就是恒红),三种绕过 decorative() 的写法必须逐条点名 + # (否则「upload 导入脚本」这类字形名外泄可以大摇大摆重新进来)。 + shapes = gate2_static() + verdict("classaudit.GATE2-bad", "图标走了 export {UploadOutlined}", True, shapes["bad"]) + verdict("classaudit.GATE2-bad", "IconUpload 的出口不是", True, shapes["bad"]) + verdict("classaudit.GATE2-bad", "IconChevronDown 的出口不是", True, shapes["bad"]) + verdict("classaudit.GATE2-bad", "StarOutlined", True, shapes["bad"]) + verdict("classaudit.GATE2-good", "ICON", False, shapes["good"]) + if fails: print("GATEPROBE_FAIL", " ".join(fails)) print("→ 闸门本身出问题:不是漏检(豁免写宽了)就是误报(豁免没生效),先修闸门") return 1 - print(f"GATEPROBE_OK {len(checks)}/{len(checks)} 闸门坏了会响、好了不响") + print(f"GATEPROBE_OK {len(checks) + 1}/{len(checks) + 1} 闸门坏了会响、好了不响") return 0 diff --git a/scripts/ui/semanticcheck.py b/scripts/ui/semanticcheck.py index f6519d3..6718c34 100644 --- a/scripts/ui/semanticcheck.py +++ b/scripts/ui/semanticcheck.py @@ -12,7 +12,7 @@ 实际读到的角色与名称,`getComputedStyle` 给算出来的焦点环,真按 Tab / Space / Escape 给键盘实际走到哪儿。 -七条判据(退出码 = offender 条数,0 = 全绿): +八条判据(退出码 = offender 条数,0 = 全绿): NAME 交互元素必须有辅助技术读得到的名字。AX 树里 name 为空的节点**分两档**: 硬档(进退出码)= 整片上下文都拿不到名字。做法:把无名节点用 CDP @@ -68,6 +68,24 @@ 且必须带 polite/assertive(不许 live="off" 假装有) STATES 空 / 载入 / 错误三种表面必须说得出口:空表有文案、骨架屏有名字与 aria-busy、 错误块有可读文本 + GLYPH 图标自带的英文字形码不许混进控件的可读名称(2026-11-08 · 阶段 8.5.1 · S-2): + antd 的图形是 ``,名字进了控件就是 + VoiceOver 实测到的「upload 导入脚本」「down 导出」(取证 + reports/ui_evidence/nex-p8f/07-screen-reader/voiceover-announcements-2026-11-08.txt + V7/V8/V11)。NAME 那条查不出这种缺陷——它的名称**非空**,只是空话。 + 判据在 DOM 上认「aria-label 等于自己的类名后缀 `anticon-<码>`」:人写的名字 + 不会长成这样,所以登记表将来换写法(现在是 decorative() 统一 aria-hidden) + 也照样咬得住,不需要维护一份字形名单。三档: + · 宿主控件自己有 aria-label / 有效的 aria-labelledby → 名称被宿主接管, + 字形码进不去 = **遮蔽**,只计数(不立案:AT 实际念的是那句人话); + · 宿主存在但名字要靠 contents 算(只有文字 / 只有 title / 什么都没有)→ + 字形码会拼进可读名称 = **立案**; + · 宿主之外(标签上的图标、提示条图标、状态点)→ 那是「这个图形是什么」的 + 独立语义位,本轮承诺只管操作名称,**只打印位置**,逐条列进覆盖说明。 + 另有一条独立的**交叉核对**(只打印,不立案):拿 CDP AX 树里辅助技术真读到的 + 名称去撞登记表解析出来的字形码集合。DOM 侧安静而 AX 侧有命中,说明名字来自 + 正文文本(实测:按钮文字里写着 `/api/meta`,撞中的是 `api`)或闸门看不见的 + 第三处——两种都要人看一眼,所以进覆盖说明。 用法: NEX_BASE=http://127.0.0.1:5199 .venv/bin/python scripts/ui/semanticcheck.py @@ -78,6 +96,8 @@ NEX_ROUTES(逗号分隔,`{id}` 换成镜头最多的项目)。 """ import os +import pathlib +import re import sys from collections import Counter @@ -99,6 +119,32 @@ ROUTES = [r for r in os.environ.get( "/projects/{id}/storyboard,/projects/{id}/dispatch,/projects/{id}/review," "/projects/{id}/timeline,/projects/{id}/delivery,/403,/9e0f-not-a-page").split(",") if r] +# ── GLYPH 用:全站唯一图标登记表里解析出来的字形英文码(upload / down / appstore…) +# 两种导出形状都要认——阶段 8.5.1 之后一律走 decorative(),但这条闸的职责是 +# 「写法换了也认得出字形码」,所以旧的 `export { A as IconB }` 照样解析。 +# 注意它**只服务交叉核对**:立案判据看的是「aria-label == 类名后缀」,不依赖这张表。 +REGISTRY = pathlib.Path(__file__).resolve().parents[2] / "frontend/src/components/icons/index.ts" + + +def glyph_tokens(): + try: + src = REGISTRY.read_text(encoding="utf8") + except OSError: + return set() + glyphs = [g for g, _ in re.findall(r"export\s*\{\s*(\w+)\s+as\s+(Icon\w+)\s*\}", src)] + glyphs += [g for _, g in re.findall(r"export\s+const\s+(Icon\w+)\s*=\s*decorative\(\s*(\w+)\s*,", src)] + out = set() + for name in glyphs: + token = re.sub(r"(Outlined|Filled|TwoTone)$", "", name) + out.add(re.sub(r"(? { const errors = [...document.querySelectorAll('[class*="nex-notice"],[class*="error" i]')] .filter(el => VIS(el) && (el.innerText || '').trim()).length; + /* 5 图标字形码是否混进可读名称(S-2):认「aria-label == 自己的类名后缀」 + —— 人写的名字不会长成 `anticon-upload` 的尾巴,所以不需要维护字形名单。 */ + const ownName = (el) => { + if ((el.getAttribute('aria-label') || '').trim()) return 'aria-label'; + const lb = el.getAttribute('aria-labelledby') || ''; + if (lb.split(/\s+/).some((id) => { + const n = document.getElementById(id); + return n && (n.innerText || n.textContent || '').trim(); + })) return 'aria-labelledby'; + return ''; + }; + const glyphs = []; + for (const el of document.querySelectorAll('.anticon[aria-label]')) { + if (!VIS(el) || el.getAttribute('aria-hidden') === 'true') continue; + let hid = false; + for (let a = el.parentElement; a; a = a.parentElement) { + if (a.getAttribute && a.getAttribute('aria-hidden') === 'true') { hid = true; break; } + } + if (hid) continue; // 整块被藏起来,AT 读不到,不占名额 + const lab = (el.getAttribute('aria-label') || '').trim(); + const tok = (cls(el).split(/\s+/).find((x) => x.startsWith('anticon-')) || '') + .slice('anticon-'.length); + if (!tok || tok !== lab) continue; // 显式给过语义名(「清空搜索」)→ 不是字形码外泄 + const host = el.parentElement + ? el.parentElement.closest(ROLE + ',' + NATIVE + ',[tabindex]') : null; + glyphs.push({ tok, sig: sig(el), own: host ? ownName(host) : '', + host: host ? sig(host) : '', ant: host ? selfAnt(host) : false, + txt: host ? (host.innerText || '').replace(/\s+/g, ' ').trim().slice(0, 28) : '' }); + } + /* 4 页签与选中态 */ let xid = 0; const tabs = [...document.querySelectorAll('[role="tab"]')].filter(VIS).map(el => { @@ -368,7 +444,7 @@ COLLECT = r"""() => { return { path: location.pathname, hasLandmark: !!document.querySelector('main,[role="main"]'), - hotspots, tabTargets, broken, live, empties, skeletons, errors, tabs, current, + hotspots, tabTargets, broken, live, empties, skeletons, errors, tabs, current, glyphs, docScrollW: document.documentElement.scrollWidth, focusables: document.querySelectorAll( 'a[href],button:not([disabled]),input:not([type=hidden]),select,textarea,[tabindex]:not([tabindex="-1"])').length, @@ -723,6 +799,8 @@ def main() -> int: soft = {} seen = {} nav_names = {} + lone = {} + ax_glyph = {} with sync_playwright() as pw: browser = pw.chromium.launch() page = browser.new_page(viewport={"width": WIDTH, "height": HEIGHT}) @@ -878,6 +956,36 @@ def main() -> int: if not d["hasLandmark"]: offenders.append("NAME %s 页面没有 main 地标,读屏无法跳过导航" % tag) + # GLYPH:图标字形码进进了控件的可读名称(阶段 8.5.1 · S-2) + g_leak = g_shadow = g_allow = 0 + for g in d["glyphs"]: + if g["own"]: + g_shadow += 1 # 宿主自己的名字接管,AT 念的是人话 + elif not g["host"]: + lone.setdefault("%s @ %s" % (g["tok"], g["sig"]), 0) + lone["%s @ %s" % (g["tok"], g["sig"])] += 1 + elif g["host"] in GLYPH_ALLOW: + g_allow += 1 + else: + g_leak += 1 + offenders.append( + "GLYPH %s 图标字形码「%s」进入控件可读名称:%s%s" + % (tag, g["tok"], g["host"], + "(宿主文字「%s」)" % g["txt"] if g["txt"] else "(宿主只有这颗图标)")) + if d["glyphs"]: + print(" GLYPH %-21s 可见图标 %2d · 外泄 %d / 遮蔽 %d / 无宿主 %d / 豁免 %d" + % (tag, len(d["glyphs"]), g_leak, g_shadow, + sum(1 for g in d["glyphs"] if not g["host"]), g_allow)) + # 交叉核对:AX 树里辅助技术真读到的名称 vs 登记表字形码(只打印,不立案) + if names and GLYPH_TOKENS: + for n in names: + low = n["name"].lower() + hit = [t for t in sorted(GLYPH_TOKENS) + if re.search(r"(? int: print(" ×%-3d %s" % (cnt, line)) for tg, nm in nav_names.items(): print(" ARIA %-28s 汉堡名称 初始「%s」→ 展开「%s」→ 收起「%s」" % (tg, nm[0], nm[1], nm[2])) + if lone: + print("\n--- GLYPH 无宿主图标 %d 类(图形自己承担语义的位置:标签内图标、提示条图标、" + "状态点。S-2 只管操作名称,这里逐条列出来给人看,不立案)---" % len(lone)) + for k, cnt in sorted(lone.items(), key=lambda x: (-x[1], x[0])): + print(" ×%-3d %s" % (cnt, k)) + for (role, nm, toks), cnt in sorted(ax_glyph.items(), key=lambda x: (-x[1], x[0])): + coverage.append("GLYPH AX 名称撞中字形码 %-13s role=%-9s 「%s」 ×%d" + " —— DOM 侧没立案:名字来自正文文本或闸门看不见的第三处,要人眼确认" + % (toks, role, nm, cnt)) + if not GLYPH_TOKENS: + coverage.append("GLYPH %s 解析出 0 个字形码 —— 交叉核对空转,登记表结构变了要同步改这里" + % REGISTRY) + else: + coverage.append("GLYPH 交叉核对用 %d 个字形码(解析自 %s);DOM 侧立案判据不依赖这张表" + % (len(GLYPH_TOKENS), REGISTRY.name)) + coverage.append("GLYPH 在册豁免 %d 条%s" + % (len(GLYPH_ALLOW), (":" + " / ".join(GLYPH_ALLOW)) if GLYPH_ALLOW else "(空表)")) if coverage: # 覆盖说明 ≠ 放行:这些是闸自己看不见的部分,打印出来供人核对; # 不立 offender 是因为它们不是页面缺陷,而是判据的现场限制。