code wiki / _hdl_build / nx_uiq_contrast.nx

nx_uiq_contrast.nx source

↩ module page · 43 lines · 2426 B

1// nx_uiq_contrast.nx -- CLI: FULL-PAGE COMPUTED WCAG 2.x contrast auditor over REAL extracted colors. 2// The quantitative fix for the "presence != conformance" gap: nx_ui_contrast checked ONE hardcoded token 3// pair on 6 hardcoded pages; this parses ANY page, extracts every --custom-property color, and computes 4// the real WCAG ratio for every text-role x surface-role pair -> the failures the presence-judge misses. 5// usage: nx_uiq_contrast --kat (self-test: math + parser + non-vacuous audit) 6// nx_uiq_contrast <html-file-path> (emits JSON: tokens, failing pairs, ratios, verdict) 7// HONEST ENVELOPE: static/source-measured over declared color tokens; role pairing is a name heuristic; 8// true rendered element-on-background stacking + non-text (3:1) + large-text (3:1) tiers = browser-lane. 9// Automated contrast is one axe rule; automated a11y covers ~57% of ISSUES / ~30-40% of WCAG SC (a FLOOR, 10// never proof of conformance). license_tier: ORIGINAL expect_exit: 0 genealogy: w3.org/TR/WCAG21 11import "nx_uiq_color.nx" 12const K_MAGIC_1048576: i64 = 1048576 13 14func uic_slurp(path: *u8, buf: *u8, cap: i64) -> i64 { 15 let fd: i64 = sys_openat_rd(path) 16 if fd<0 { return 0 } 17 var total: i64=0 18 var nrd: i64=sys_read(fd, buf, cap) 19 while nrd>0 { total=total+nrd; if total>=cap { nrd=0 } else { nrd=sys_read(fd, ((buf as i64)+total) as *u8, cap-total) } } 20 sys_close(fd) 21 return total 22} 23 24func main(argc: i64, argv: *i64) -> i64 { 25 if argc>=2 { 26 let a1: *u8 = argv[1] as *u8 27 if a1[0]==(45 as u8) { 28 uiq_w("=== nx_uiq_contrast --kat (computed WCAG 2.x contrast on REAL colors) ===\n" as *u8) 29 let f: i64 = uiq_selftest() 30 uiq_w("checks failed=" as *u8); uiq_pn(f); uiq_w(" (math 21.00/4.54 + rgb()/hex parse + PASS/FAIL/neg-control audit)\n" as *u8) 31 if f==0 { uiq_w("VERDICT=GREEN\n" as *u8); sys_exit(0); return 0 } 32 uiq_w("VERDICT=RED\n" as *u8); sys_exit(1); return 1 33 } 34 let cap: i64 = K_MAGIC_1048576 35 let buf: *u8 = sys_mmap(cap) 36 let n: i64 = uic_slurp(a1, buf, cap) 37 if n<=0 { uiq_w("{\"error\":\"cannot read page\",\"path\":\"" as *u8); uiq_w(a1); uiq_w("\"}\n" as *u8); sys_exit(2); return 2 } 38 uiq_audit_buf(buf, n, 1) 39 sys_exit(0); return 0 40 } 41 uiq_w("usage: nx_uiq_contrast --kat | <html-file-path>\n" as *u8) 42 sys_exit(2); return 2 43}