code wiki / _hdl_build / nx_brand_guard_gate.nx

nx_brand_guard_gate.nx source

↩ module page · 72 lines · 4716 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_brand_guard_gate.nx -- R2 gate: brand-consistency enforcement (contrast + spacing + type-scale). 4// FIRST validates the no-float WCAG contrast math against AUTHORITATIVE reference ratios (black/white=21.0, 5// white/white=1.0, #767676/white=4.54) so accuracy is PROVEN not claimed -- this is what caught the coarse aces 6// fit. THEN enforces on the default brand's token pairs + NEGATIVE controls (low-contrast / off-grid spacing / 7// inverted type-scale must all be FLAGGED). 100% sovereign. license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_brand_guard.nx" 10 11func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 12" as *u8); return ok } 13func t_row(name: *u8, ok: i64, val: i64, tot: *i64) -> i64 { 14 if ok == 1 { gw(" PASS " as *u8); tot[0]=tot[0]+1 } else { gw(" FAIL " as *u8); tot[1]=tot[1]+1 } 15 gw(name); gw(" (got=" as *u8); gn(val); gw(")\n" as *u8); return 0 16} 17func inband(v: i64, lo: i64, hi: i64) -> i64 { if v < lo { return 0 } if v > hi { return 0 } return 1 } 18 19func main() -> i64 { 20 let tot: *i64 = sys_mmap(32) as *i64 21 tot[0]=0; tot[1]=0 22 let d: *u8 = bt_default_brand() 23 let bn: i64 = bt_len(d) 24 gw("=== nx_brand_guard_gate -- R2 brand-consistency enforcement (no-float WCAG contrast + spacing + type-scale) ===\n" as *u8) 25 26 gw("-- contrast math VALIDATION vs authoritative WCAG reference ratios (x100) --\n" as *u8) 27 let v1: i64 = bg_contrast_hex_x100("#000000" as *u8, "#ffffff" as *u8) 28 t_row("V1 black/white == 21.0:1 (WCAG max)" as *u8, inband(v1, 2080, 2120), v1, tot) 29 let v2: i64 = bg_contrast_hex_x100("#ffffff" as *u8, "#ffffff" as *u8) 30 t_row("V2 white/white == 1.0:1" as *u8, inband(v2, 100, 100), v2, tot) 31 let v3: i64 = bg_contrast_hex_x100("#767676" as *u8, "#ffffff" as *u8) 32 t_row("V3 #767676/white ~= 4.54:1 (mid-tone gamma accuracy -- the aces-fit killer)" as *u8, inband(v3, 430, 480), v3, tot) 33 34 gw("-- ENFORCE: default brand token pairs must meet WCAG AA (>=4.5:1 == 450) --\n" as *u8) 35 let e1: i64 = bg_pair_contrast(d, bn, "color" as *u8, "ink" as *u8, "color" as *u8, "bg" as *u8) 36 t_row("E1 body text: color/ink on color/bg >= AA" as *u8, inband(e1, 450, 999999), e1, tot) 37 let e2: i64 = bg_pair_contrast(d, bn, "color" as *u8, "accent-ink" as *u8, "color" as *u8, "accent" as *u8) 38 t_row("E2 CTA text: color/accent-ink on color/accent >= AA" as *u8, inband(e2, 450, 999999), e2, tot) 39 let e3: i64 = bg_pair_contrast(d, bn, "color" as *u8, "primary" as *u8, "color" as *u8, "bg" as *u8) 40 t_row("E3 heading: color/primary on color/bg >= AA" as *u8, inband(e3, 450, 999999), e3, tot) 41 42 gw("-- NEG controls: real violations must be FLAGGED (< AA) --\n" as *u8) 43 let n1: i64 = bg_contrast_hex_x100("#bbbbbb" as *u8, "#ffffff" as *u8) 44 t_row("N1 light-grey-on-white correctly BELOW AA" as *u8, inband(n1, 1, 449), n1, tot) 45 let lowbrand: *u8 = "token|color|ink|#cccccc\ntoken|color|bg|#ffffff\n" as *u8 46 let n2: i64 = bg_pair_contrast(lowbrand, bt_len(lowbrand), "color" as *u8, "ink" as *u8, "color" as *u8, "bg" as *u8) 47 t_row("N2 a low-contrast brand's ink/bg correctly BELOW AA" as *u8, inband(n2, 1, 449), n2, tot) 48 49 gw("-- spacing-grid (space tokens are whole multiples of 8px) --\n" as *u8) 50 let s1a: i64 = bg_space_grid_ok(d, bn, "1" as *u8, 8) 51 let s1b: i64 = bg_space_grid_ok(d, bn, "2" as *u8, 8) 52 let s1c: i64 = bg_space_grid_ok(d, bn, "3" as *u8, 8) 53 let s1d: i64 = bg_space_grid_ok(d, bn, "4" as *u8, 8) 54 var s1: i64 = 0 55 if s1a==1 { if s1b==1 { if s1c==1 { if s1d==1 { s1 = 1 } } } } 56 t_row("S1 default space 1/2/3/4 all on the 8px grid" as *u8, s1, s1d, tot) 57 let badspace: *u8 = "token|space|x|7px\n" as *u8 58 let s2: i64 = bg_space_grid_ok(badspace, bt_len(badspace), "x" as *u8, 8) 59 t_row("S2 NEG: 7px space correctly flagged off-grid" as *u8, inband(s2, 0, 0), s2, tot) 60 61 gw("-- modular type-scale (headings descend within a sane ratio band) --\n" as *u8) 62 let t1: i64 = bg_type_scale_ok(d, bn) 63 t_row("T1 default type-scale h1>h2 in band" as *u8, inband(t1, 1, 1), t1, tot) 64 let badscale: *u8 = "token|font|h1|1rem\ntoken|font|h2|2rem\n" as *u8 65 let t2: i64 = bg_type_scale_ok(badscale, bt_len(badscale)) 66 t_row("T2 NEG: inverted scale (h1<h2) correctly flagged" as *u8, inband(t2, 0, 0), t2, tot) 67 68 gw("\nrows pass=" as *u8); gn(tot[0]); gw(" fail=" as *u8); gn(tot[1]); gw("\n" as *u8) 69 if tot[1] == 0 { gw("VERDICT=GREEN -- brand-consistency enforcement works; contrast math validated vs WCAG references\n" as *u8); return 0 } 70 gw("VERDICT=RED\n" as *u8) 71 return 1 72}