@kinti/a11y-toolkit 5.22.0 → 5.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/a11y_toolkit/__init__.py +5 -0
  2. package/a11y_toolkit/a11y.py +115 -0
  3. package/a11y_toolkit/a11yact.py +167 -0
  4. package/a11y_toolkit/a11yaudit.py +1951 -0
  5. package/a11y_toolkit/a11ybadge.py +102 -0
  6. package/a11y_toolkit/a11ybudget.py +122 -0
  7. package/a11y_toolkit/a11ycrit.py +1017 -0
  8. package/a11y_toolkit/a11ydiff.py +192 -0
  9. package/a11y_toolkit/a11ydisprove.py +175 -0
  10. package/a11y_toolkit/a11ydocx.py +132 -0
  11. package/a11y_toolkit/a11ydom.py +1831 -0
  12. package/a11y_toolkit/a11yevidence.py +272 -0
  13. package/a11y_toolkit/a11yfix.py +330 -0
  14. package/a11y_toolkit/a11yi18n.py +100 -0
  15. package/a11y_toolkit/a11yinit.py +113 -0
  16. package/a11y_toolkit/a11yjourney.py +284 -0
  17. package/a11y_toolkit/a11yledger.py +210 -0
  18. package/a11y_toolkit/a11ymutants.py +406 -0
  19. package/a11y_toolkit/a11yopenacr.py +207 -0
  20. package/a11y_toolkit/a11ypdf.py +273 -0
  21. package/a11y_toolkit/a11yroute.py +378 -0
  22. package/a11y_toolkit/a11ysarif.py +139 -0
  23. package/a11y_toolkit/a11yscroll.py +212 -0
  24. package/a11y_toolkit/a11ystatement.py +158 -0
  25. package/a11y_toolkit/a11yvalidate.py +127 -0
  26. package/a11y_toolkit/a11yvpat.py +238 -0
  27. package/a11y_toolkit/a11yvtt.py +136 -0
  28. package/a11y_toolkit/a11ywcag3.py +262 -0
  29. package/a11y_toolkit/arialive.js +107 -0
  30. package/a11y_toolkit/arialive_js.py +113 -0
  31. package/a11y_toolkit/contrast.py +536 -0
  32. package/a11y_toolkit/locales/_template.json +468 -0
  33. package/a11y_toolkit/locales/en.json +525 -0
  34. package/a11y_toolkit/locales/es.json +525 -0
  35. package/a11y_toolkit/server.py +1529 -0
  36. package/bin/a11y-toolkit-mcp.cjs +2 -2
  37. package/bin/a11y-toolkit.cjs +2 -2
  38. package/lib/runner.cjs +30 -22
  39. package/package.json +2 -1
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env python3
2
+ """Honest SVG badge — accessibility score with date and scope, no promises.
3
+
4
+ The industry lesson (FTC v. accessiBe, $1M, 2025): a badge that promises
5
+ "compliant" ends in a fine. This badge only states what the toolkit can
6
+ demonstrate: a score over what is automatable, the date and the scope
7
+ (screening). Accessible SVG (role="img" + <title>), zero dependencies.
8
+
9
+ Score colors: ≥90 green · 75-89 lime · 50-74 orange · <50 red.
10
+
11
+ CLI:
12
+ a11ybadge.py --score 92 [--date 2026-09-07] [--scope screening] [--lang en] [--out badge.svg]
13
+ """
14
+
15
+ import argparse
16
+ import datetime
17
+ import json
18
+ import sys
19
+ from xml.sax.saxutils import escape as _xesc
20
+ from . import a11yi18n
21
+
22
+ _TEXTS = a11yi18n.pair('badge') # locales/<lang>.json — community-editable
23
+
24
+ _COLORS = [(90, '#2da44e'), (75, '#8bdb5e'), (50, '#d29922'), (0, '#cf222e')]
25
+
26
+
27
+ def _color(score):
28
+ for threshold, c in _COLORS:
29
+ if score >= threshold:
30
+ return c
31
+ return _COLORS[-1][1]
32
+
33
+
34
+ def badge(score, date=None, scope=None, lang='en', brand=None, palette=None, height=None):
35
+ """Honest SVG badge. score 0-100.
36
+
37
+ `brand` overrides the left label; `palette` overrides the score colors as
38
+ [(threshold, '#hex'), …] (measure your contrast with a11y_contrast_pair —
39
+ a WCAG tool's own badge must pass 1.4.3); `height` scales the SVG (default 20).
40
+ """
41
+ score = max(0, min(100, int(round(score))))
42
+ t = dict(_TEXTS.get(lang, _TEXTS['en']))
43
+ if brand:
44
+ t['name'] = brand[:24]
45
+ colors = palette or _COLORS
46
+
47
+ def _color(s):
48
+ for threshold, c in colors:
49
+ if s >= threshold:
50
+ return c
51
+ return colors[-1][1]
52
+
53
+ date = date or datetime.date.today().isoformat()
54
+ scope = scope or t['scope']
55
+ date = _xesc(date)[:30]
56
+ scope = _xesc(scope)[:60]
57
+ title = _xesc(t['title'].format(score=score, date=date, scope=scope))
58
+ color = _color(score)
59
+ h = height or 20
60
+ font = 11 if h == 20 else round(h * 0.58)
61
+ y = h / 2 + font * 0.35
62
+ left = len(t['name']) * (font * 0.60) + 14
63
+ right = len(f'{score}/100 · {date}') * (font * 0.60) + 14
64
+ width = left + right
65
+ return f'''<svg xmlns="http://www.w3.org/2000/svg" width="{width:.0f}" height="{h}" role="img" aria-label="{title}">
66
+ <title>{title}</title>
67
+ <linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient>
68
+ <clipPath id="r"><rect width="{width:.0f}" height="{h}" rx="3" fill="#fff"/></clipPath>
69
+ <g clip-path="url(#r)">
70
+ <rect width="{left:.0f}" height="{h}" fill="#1f2328"/>
71
+ <rect x="{left:.0f}" width="{right:.0f}" height="{h}" fill="{color}"/>
72
+ <rect width="{width:.0f}" height="{h}" fill="url(#s)"/>
73
+ </g>
74
+ <g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="{font}">
75
+ <text x="{left / 2:.0f}" y="{y + 1:.1f}" fill="#010409" fill-opacity=".3">{t['name']}</text>
76
+ <text x="{left / 2:.0f}" y="{y:.1f}">{t['name']}</text>
77
+ <text x="{left + right / 2:.0f}" y="{y + 1:.1f}" fill="#010409" fill-opacity=".3">{score}/100 · {date}</text>
78
+ <text x="{left + right / 2:.0f}" y="{y:.1f}">{score}/100 · {date}</text>
79
+ </g>
80
+ </svg>'''
81
+
82
+
83
+ def main(argv):
84
+ ap = argparse.ArgumentParser(description=__doc__)
85
+ ap.add_argument('--score', type=float, required=True)
86
+ ap.add_argument('--date', default=None)
87
+ ap.add_argument('--scope', default=None)
88
+ ap.add_argument('--lang', default='en', choices=['es', 'en'])
89
+ ap.add_argument('--out', default=None)
90
+ a = ap.parse_args(argv)
91
+ svg = badge(a.score, date=a.date, scope=a.scope, lang=a.lang)
92
+ if a.out:
93
+ with open(a.out, 'w', encoding='utf-8') as f:
94
+ f.write(svg)
95
+ print(json.dumps({'badge': a.out, 'score': int(a.score)}))
96
+ else:
97
+ print(svg)
98
+ return 0
99
+
100
+
101
+ if __name__ == '__main__':
102
+ sys.exit(main(sys.argv[1:]))
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env python3
2
+ """Accessibility error budget — Google SRE's lesson applied to WCAG.
3
+
4
+ The classic paralysis: the audit finds 40 issues, nobody can fix them this
5
+ week, so nobody turns the control on. The budget breaks the deadlock: today's
6
+ baseline is ACCEPTED and only what is NEW blocks. Every fix lowers the
7
+ baseline; every regression screams.
8
+
9
+ Budget file (budget.json):
10
+
11
+ {
12
+ "url": "https://mysite",
13
+ "signals": ["img_no_alt", "field_label"], // accepted baseline
14
+ "blocking": ["high", "medium"], // severities that block
15
+ "max_new": 0, // how many new ones tolerated
16
+ "review_date": "2026-12-07" // baseline expiry (optional)
17
+ }
18
+
19
+ Generate the baseline: a11ytoolkit audit --url https://mysite | a11ytoolkit budget --init
20
+ Compare with: a11ytoolkit budget --budget budget.json --audit audit.json
21
+ Exit code: 0 ok / 2 blocked.
22
+
23
+ Only stable keys ('signal') and severities are compared, never prose.
24
+ """
25
+
26
+ import argparse
27
+ import datetime
28
+ import json
29
+
30
+ from .a11yaudit import normalize_signal # noqa: E402 (compat 5.10)
31
+ import sys
32
+
33
+
34
+ def init(audit):
35
+ """Informe (o site) → fichero de presupuesto inicial."""
36
+ pages = audit.get('reports') if 'reports' in audit else [audit]
37
+ signals = sorted({normalize_signal(h.get('signal', '')) for pg in pages for h in pg.get('findings', [])})
38
+ return {
39
+ 'url': audit.get('url', ''),
40
+ 'signals': signals,
41
+ 'blocking': ['high', 'medium'],
42
+ 'max_new': 0,
43
+ 'review_date': (datetime.date.today() + datetime.timedelta(days=90)).isoformat(),
44
+ }
45
+
46
+
47
+ def compare(budget, audit, today=None):
48
+ """Presupuesto vs informe actual → veredicto ok/bloqueado con el detalle."""
49
+ pages = audit.get('reports') if 'reports' in audit else [audit]
50
+ base = {normalize_signal(s) for s in budget.get('signals', [])}
51
+ blocking = set(budget.get('blocking', ['high', 'medium']))
52
+ current = {}
53
+ for pg in pages:
54
+ for h in pg.get('findings', []):
55
+ current.setdefault(normalize_signal(h.get('signal', '')), []).append(h['severity'])
56
+ new = sorted(s for s in current if s not in base)
57
+ resolved = sorted(base - set(current))
58
+ new_blocking = [s for s in new
59
+ if any(sev in blocking for sev in current[s])]
60
+ max_new = int(budget.get('max_new', 0))
61
+ ok = len(new_blocking) <= max_new
62
+ expired = False
63
+ date = budget.get('review_date')
64
+ if date:
65
+ expired = (today or datetime.date.today().isoformat()) > date
66
+ return {
67
+ 'ok': ok and not expired,
68
+ 'url': audit.get('url', budget.get('url', '')),
69
+ 'new': new,
70
+ 'new_blocking': new_blocking,
71
+ 'resolved': resolved,
72
+ 'summary': {
73
+ 'baseline': len(base),
74
+ 'current': len(current),
75
+ 'new': len(new),
76
+ 'resolved': len(resolved),
77
+ },
78
+ 'baseline_expired': expired,
79
+ 'note': ('ok=false: there are new blocking findings (or the baseline expired). '
80
+ 'ok=true: nothing new vs the accepted baseline — fix baseline items '
81
+ 'and re-run --init to lower it.'),
82
+ }
83
+
84
+
85
+ def main(argv):
86
+ ap = argparse.ArgumentParser(description=__doc__)
87
+ ap.add_argument('--init', action='store_true',
88
+ help='genera el presupuesto desde un informe (stdin o --audit)')
89
+ ap.add_argument('--budget', default='budget.json', help='fichero de presupuesto')
90
+ ap.add_argument('--audit', help='informe JSON del auditor')
91
+ ap.add_argument('--url', help='auditar esta URL al vuelo')
92
+ a = ap.parse_args(argv)
93
+ if a.init:
94
+ inform = None
95
+ if not sys.stdin.isatty():
96
+ inform = json.loads(sys.stdin.read())
97
+ elif a.audit:
98
+ with open(a.audit, encoding='utf-8') as f:
99
+ inform = json.load(f)
100
+ if not inform:
101
+ print('need the report via stdin or --audit file')
102
+ return 1
103
+ print(json.dumps(init(inform), ensure_ascii=False, indent=1))
104
+ return 0
105
+ if not (a.audit or a.url):
106
+ print('need --audit report.json or --url https://…')
107
+ return 1
108
+ with open(a.budget, encoding='utf-8') as f:
109
+ budget = json.load(f)
110
+ if a.audit:
111
+ with open(a.audit, encoding='utf-8') as f:
112
+ report = json.load(f)
113
+ else:
114
+ from .a11yaudit import audit_url
115
+ report = audit_url(a.url)
116
+ verdict = compare(budget, report)
117
+ print(json.dumps(verdict, ensure_ascii=False, indent=1))
118
+ return 0 if verdict['ok'] else 2
119
+
120
+
121
+ if __name__ == '__main__':
122
+ sys.exit(main(sys.argv[1:]))