@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.
- package/a11y_toolkit/__init__.py +5 -0
- package/a11y_toolkit/a11y.py +115 -0
- package/a11y_toolkit/a11yact.py +167 -0
- package/a11y_toolkit/a11yaudit.py +1951 -0
- package/a11y_toolkit/a11ybadge.py +102 -0
- package/a11y_toolkit/a11ybudget.py +122 -0
- package/a11y_toolkit/a11ycrit.py +1017 -0
- package/a11y_toolkit/a11ydiff.py +192 -0
- package/a11y_toolkit/a11ydisprove.py +175 -0
- package/a11y_toolkit/a11ydocx.py +132 -0
- package/a11y_toolkit/a11ydom.py +1831 -0
- package/a11y_toolkit/a11yevidence.py +272 -0
- package/a11y_toolkit/a11yfix.py +330 -0
- package/a11y_toolkit/a11yi18n.py +100 -0
- package/a11y_toolkit/a11yinit.py +113 -0
- package/a11y_toolkit/a11yjourney.py +284 -0
- package/a11y_toolkit/a11yledger.py +210 -0
- package/a11y_toolkit/a11ymutants.py +406 -0
- package/a11y_toolkit/a11yopenacr.py +207 -0
- package/a11y_toolkit/a11ypdf.py +273 -0
- package/a11y_toolkit/a11yroute.py +378 -0
- package/a11y_toolkit/a11ysarif.py +139 -0
- package/a11y_toolkit/a11yscroll.py +212 -0
- package/a11y_toolkit/a11ystatement.py +158 -0
- package/a11y_toolkit/a11yvalidate.py +127 -0
- package/a11y_toolkit/a11yvpat.py +238 -0
- package/a11y_toolkit/a11yvtt.py +136 -0
- package/a11y_toolkit/a11ywcag3.py +262 -0
- package/a11y_toolkit/arialive.js +107 -0
- package/a11y_toolkit/arialive_js.py +113 -0
- package/a11y_toolkit/contrast.py +536 -0
- package/a11y_toolkit/locales/_template.json +468 -0
- package/a11y_toolkit/locales/en.json +525 -0
- package/a11y_toolkit/locales/es.json +525 -0
- package/a11y_toolkit/server.py +1529 -0
- package/bin/a11y-toolkit-mcp.cjs +2 -2
- package/bin/a11y-toolkit.cjs +2 -2
- package/lib/runner.cjs +30 -22
- package/package.json +2 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""VPAT 2.5 (WCAG edition) generator — the US counterpart of the EAA declaration.
|
|
3
|
+
|
|
4
|
+
Input: an a11y-evidence-pack/2 (from a11y_evidence / a11y_evidence MCP tool)
|
|
5
|
+
or raw audit reports (the pack is built here). Output: an accessible HTML
|
|
6
|
+
VPAT with the full 55-criterion WCAG 2.2 A/AA table.
|
|
7
|
+
|
|
8
|
+
Honesty rule (non-negotiable, mirrors the pack): the machine fills Remarks,
|
|
9
|
+
never the Conformance Level. Every row starts at 'Not Evaluated' unless an
|
|
10
|
+
automated fail forces 'Does Not Support' (or 'Partially Supports' for
|
|
11
|
+
review-level signals). A qualified human sets the final level via `overrides`
|
|
12
|
+
and signs; until then the document is a DRAFT and says so. The signature
|
|
13
|
+
statement must reference the evidence pack's sha256 — same tamper-evidence
|
|
14
|
+
rule as the pack itself. VPAT is a vendor self-declaration, not a certificate.
|
|
15
|
+
|
|
16
|
+
CLI:
|
|
17
|
+
a11yvpat.py pack.json --product "Acme App" --contact a11y@acme.example \
|
|
18
|
+
--overrides '{"1.1.1": "does_not_support", "1.2.2": "not_applicable"}' \
|
|
19
|
+
-o vpat.html
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import datetime
|
|
24
|
+
import html
|
|
25
|
+
import json
|
|
26
|
+
import sys
|
|
27
|
+
from . import a11yi18n
|
|
28
|
+
|
|
29
|
+
LEVELS = a11yi18n.pair('vpat_levels') # locales/<lang>.json — community-editable
|
|
30
|
+
|
|
31
|
+
_STATUS_TO_LEVEL = {
|
|
32
|
+
'automated-fail': 'does_not_support',
|
|
33
|
+
'automated-review': 'partially_supports',
|
|
34
|
+
# not-flagged ≠ pass; agent-verified no es una firma humana
|
|
35
|
+
'not-flagged': 'not_evaluated',
|
|
36
|
+
'not-run': 'not_evaluated',
|
|
37
|
+
'manual-only': 'not_evaluated',
|
|
38
|
+
'agent-verified': 'not_evaluated',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
TXT = a11yi18n.pair('vpat_txt') # locales/<lang>.json — community-editable
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _t(lang):
|
|
45
|
+
return TXT.get(lang, TXT['en'])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _findings_by_code(pack):
|
|
49
|
+
"""Código de criterio → primer hallazgo con issue+remediation (de los artefactos)."""
|
|
50
|
+
by_code = {}
|
|
51
|
+
for art in pack.get('artifacts', []):
|
|
52
|
+
body = art.get('body') or {}
|
|
53
|
+
for h in body.get('findings', []):
|
|
54
|
+
code = (h.get('criterion') or '').split(' ')[0]
|
|
55
|
+
if code and code not in by_code:
|
|
56
|
+
by_code[code] = h
|
|
57
|
+
return by_code
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _remarks(t, row, finding, level, pack_sha):
|
|
61
|
+
"""Remarks auto por fila: estado + valor medido + esfuerzo + hallazgo + hash."""
|
|
62
|
+
parts = []
|
|
63
|
+
state = row.get('status')
|
|
64
|
+
if state == 'automated-fail':
|
|
65
|
+
parts.append(t['draft'] + ' — ' + 'automated-fail')
|
|
66
|
+
elif state == 'automated-review':
|
|
67
|
+
parts.append('automated-review')
|
|
68
|
+
else:
|
|
69
|
+
parts.append(state)
|
|
70
|
+
note = row.get('note')
|
|
71
|
+
if note:
|
|
72
|
+
parts.append(note)
|
|
73
|
+
val = row.get('value')
|
|
74
|
+
if val:
|
|
75
|
+
chunks = []
|
|
76
|
+
if val.get('measured'):
|
|
77
|
+
chunks.append(f"measured {val['measured']}")
|
|
78
|
+
if val.get('example'):
|
|
79
|
+
chunks.append(f"e.g. {val['example']}")
|
|
80
|
+
if chunks:
|
|
81
|
+
parts.append('; '.join(chunks))
|
|
82
|
+
if finding:
|
|
83
|
+
parts.append(f"issue: {finding.get('issue', '')[:220]}")
|
|
84
|
+
if finding.get('remediation'):
|
|
85
|
+
parts.append(f"remediation: {finding['remediation'][:220]}")
|
|
86
|
+
ef = row.get('effort')
|
|
87
|
+
if ef:
|
|
88
|
+
parts.append(f"remaining human effort: {ef['class']} ({ef['minutes']} min)")
|
|
89
|
+
parts.append(f"evidence pack sha256 {pack_sha}")
|
|
90
|
+
return ' | '.join(p for p in parts if p)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _wcag_order(code):
|
|
94
|
+
try:
|
|
95
|
+
return tuple(int(p) for p in code.split('.'))
|
|
96
|
+
except ValueError:
|
|
97
|
+
return (99, 0, 0)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def generate_vpat(pack=None, reports=None, product='', product_version=None,
|
|
101
|
+
report_date=None, description=None, contact=None, methods=None,
|
|
102
|
+
notes=None, overrides=None, reviewer=None, lang='en',
|
|
103
|
+
verified=None, output_path=None):
|
|
104
|
+
"""Pack (o informes) → HTML VPAT 2.5 accesible + resumen.
|
|
105
|
+
|
|
106
|
+
overrides: {'1.1.1': 'supports', …} — niveles fijados por una persona
|
|
107
|
+
cualificada; ganan sobre la derivación automática."""
|
|
108
|
+
t = _t(lang)
|
|
109
|
+
if pack is None:
|
|
110
|
+
if not reports:
|
|
111
|
+
return {'error': t['error_no_pack']}
|
|
112
|
+
from .a11yevidence import build_pack
|
|
113
|
+
pack = build_pack(reports, verified=verified,
|
|
114
|
+
reviewer=reviewer)
|
|
115
|
+
if not isinstance(pack, dict) or 'criteria' not in pack:
|
|
116
|
+
return {'error': t['error_no_pack']}
|
|
117
|
+
overrides = overrides or {}
|
|
118
|
+
for code, level in overrides.items():
|
|
119
|
+
if level not in LEVELS[lang]:
|
|
120
|
+
return {'error': t['error_level'].format(n=level)}
|
|
121
|
+
|
|
122
|
+
from .a11ycrit import _C as _CAT
|
|
123
|
+
pack_sha = pack.get('sha256', '')
|
|
124
|
+
by_code = _findings_by_code(pack)
|
|
125
|
+
report_date = report_date or datetime.date.today().isoformat()
|
|
126
|
+
|
|
127
|
+
rows = []
|
|
128
|
+
summary = {n: 0 for n in LEVELS[lang]}
|
|
129
|
+
for row in sorted(pack['criteria'], key=lambda r: _wcag_order(r['criterion'].split(' ')[0])):
|
|
130
|
+
code = row['criterion'].split(' ')[0]
|
|
131
|
+
level = _STATUS_TO_LEVEL.get(row.get('status'), 'not_evaluated')
|
|
132
|
+
level = overrides.get(code, level)
|
|
133
|
+
summary[level] += 1
|
|
134
|
+
cat = _CAT.get(code)
|
|
135
|
+
name = cat[1][lang][0] if cat else row['criterion']
|
|
136
|
+
wcag_level = cat[0] if cat else ''
|
|
137
|
+
finding = by_code.get(code)
|
|
138
|
+
rows.append({
|
|
139
|
+
'code': code, 'name': name, 'level': wcag_level,
|
|
140
|
+
'conformance': level,
|
|
141
|
+
'remarks': _remarks(t, row, finding, level, pack_sha),
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
e = html.escape
|
|
145
|
+
methods = methods or t['method_default']
|
|
146
|
+
rows_html = []
|
|
147
|
+
for f in rows:
|
|
148
|
+
rows_html.append(
|
|
149
|
+
'<tr><th scope="row">' + e(f['code']) + ' ' + e(f['name'])
|
|
150
|
+
+ (' <span class="lvl">(Level ' + e(f['level']) + ')</span>' if f['level'] else '')
|
|
151
|
+
+ '</th><td><strong>' + e(LEVELS[lang][f['conformance']]) + '</strong></td>'
|
|
152
|
+
+ '<td>' + e(f['remarks']) + '</td></tr>')
|
|
153
|
+
legend = ''.join(f'<dt>{e(k)}</dt><dd>{e(v)}</dd>' for k, v in t['legend'])
|
|
154
|
+
|
|
155
|
+
doc = (
|
|
156
|
+
f'<!DOCTYPE html>\n<html lang="{lang}">\n<head>\n<meta charset="utf-8">\n'
|
|
157
|
+
f'<meta name="viewport" content="width=device-width, initial-scale=1">\n'
|
|
158
|
+
f'<title>{e(t["title"])} — {e(product)}</title>\n'
|
|
159
|
+
# self-contained signable document: FIXED colors, not the system theme
|
|
160
|
+
# (dark mode painted light text on light header gray — contrast ~1:1),
|
|
161
|
+
# and long hashes must wrap instead of stretching the page (1.4.10).
|
|
162
|
+
'<style>:root{color-scheme:light}body{max-width:60rem;margin:2rem auto;'
|
|
163
|
+
'padding:0 1rem;color:#161A16;background:#fff;'
|
|
164
|
+
'font:1rem/1.6 system-ui,sans-serif} table{border-collapse:collapse;width:100%}'
|
|
165
|
+
' th,td{border:1px solid #888;padding:.5rem;vertical-align:top;text-align:left}'
|
|
166
|
+
' thead th{background:#f0f0f0;color:#161A16} .lvl{color:#555;font-size:.85em}'
|
|
167
|
+
' code{background:#f5f5f5;padding:.1rem .3rem;overflow-wrap:anywhere}'
|
|
168
|
+
' p,dd,dt,th,td,li{overflow-wrap:anywhere}'
|
|
169
|
+
' .table-scroll{overflow-x:auto}'
|
|
170
|
+
' @media (max-width:40rem){body{margin:1rem auto} th,td{padding:.35rem}}'
|
|
171
|
+
'</style>\n</head>\n<body>\n<main>\n'
|
|
172
|
+
f'<h1>{e(t["title"])}</h1>\n'
|
|
173
|
+
f'<p><strong>{e(product)}</strong>'
|
|
174
|
+
+ (f' — {t["version"]}: {e(product_version)}' if product_version else '')
|
|
175
|
+
+ f' — {t["date"]}: <time datetime="{e(report_date)}">{e(report_date)}</time></p>\n'
|
|
176
|
+
+ (f'<p><strong>{t["description"]}:</strong> {e(description)}</p>\n' if description else '')
|
|
177
|
+
+ (f'<p><strong>{t["contact"]}:</strong> {e(contact)}</p>\n' if contact else '')
|
|
178
|
+
+ f'<h2>{t["standards_section"]}</h2>\n<p>{t["standard"]}</p>\n'
|
|
179
|
+
+ f'<h2>{t["methods"]}</h2>\n<p>{e(methods)}</p>\n'
|
|
180
|
+
+ (f'<h2>{t["notes"]}</h2>\n<p>{e(notes)}</p>\n' if notes else '')
|
|
181
|
+
+ f'<details>\n<summary>{t["legend_title"]}</summary>\n<dl>{legend}</dl>\n</details>\n'
|
|
182
|
+
# the criteria table is wide: scrolling lives HERE, keyboard-focusable,
|
|
183
|
+
# so the PAGE does not overflow (WCAG 1.4.10)
|
|
184
|
+
+ '<div class="table-scroll" tabindex="0" role="group">\n'
|
|
185
|
+
+ f'<table>\n<caption>{t["table_caption"]}</caption>\n'
|
|
186
|
+
+ '<thead><tr><th scope="col">' + t['col_criteria'] + '</th><th scope="col">'
|
|
187
|
+
+ t['col_level'] + '</th><th scope="col">' + t['col_remarks']
|
|
188
|
+
+ '</th></tr></thead>\n<tbody>\n' + '\n'.join(rows_html) + '\n</tbody>\n</table>\n</div>\n'
|
|
189
|
+
+ f'<h2>{t["signature_title"]}</h2>\n<p>{t["signature"]} <code>{e(pack_sha)}</code></p>\n'
|
|
190
|
+
+ '<p><em>' + t['signature_empty'] + '</em></p>\n'
|
|
191
|
+
+ (f'<p>{t["product"]}: {e((reviewer or {}).get("name", "________________"))} — '
|
|
192
|
+
f'{t["credential"]}: {e((reviewer or {}).get("credential", "________________"))} — '
|
|
193
|
+
f'{t["date"]}: {e((reviewer or {}).get("review_date", "________________"))}</p>\n'
|
|
194
|
+
if reviewer else '')
|
|
195
|
+
+ f'</main>\n<footer><p><small>{t["iti_note"]}</small></p></footer>\n</body>\n</html>'
|
|
196
|
+
)
|
|
197
|
+
res = {'html': doc, 'summary': summary, 'levels': {f['code']: f['conformance'] for f in rows},
|
|
198
|
+
'pack_sha256': pack_sha, 'draft': True, 'lang': lang}
|
|
199
|
+
if output_path:
|
|
200
|
+
with open(output_path, 'w', encoding='utf-8') as f:
|
|
201
|
+
f.write(doc)
|
|
202
|
+
res['saved_to'] = output_path
|
|
203
|
+
return res
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def main(argv):
|
|
207
|
+
ap = argparse.ArgumentParser(description='VPAT 2.5 (WCAG edition) from an evidence pack')
|
|
208
|
+
ap.add_argument('pack', nargs='?', help='evidence pack JSON (a11y_evidence output)')
|
|
209
|
+
ap.add_argument('--product', required=True, help='product name')
|
|
210
|
+
ap.add_argument('--reports', nargs='+', help='audit report JSONs (builds the pack) instead of pack')
|
|
211
|
+
ap.add_argument('--report-date', help='report date (YYYY-MM-DD, default today)')
|
|
212
|
+
ap.add_argument('--description', help='product description')
|
|
213
|
+
ap.add_argument('--contact', help='contact information')
|
|
214
|
+
ap.add_argument('--methods', help='evaluation methods used')
|
|
215
|
+
ap.add_argument('--notes', help='notes')
|
|
216
|
+
ap.add_argument('--overrides', help='JSON: {"1.1.1": "does_not_support", …}')
|
|
217
|
+
ap.add_argument('--reviewer', help='JSON: {"name":…, "credential":…, "review_date":…}')
|
|
218
|
+
ap.add_argument('--lang', default='en', choices=['en', 'es'])
|
|
219
|
+
ap.add_argument('-o', '--out')
|
|
220
|
+
a = ap.parse_args(argv)
|
|
221
|
+
pack = json.load(open(a.pack, encoding='utf-8')) if a.pack else None
|
|
222
|
+
reports = [json.load(open(f, encoding='utf-8')) for f in a.reports] if a.reports else None
|
|
223
|
+
res = generate_vpat(pack=pack, reports=reports, product=a.product, report_date=a.report_date,
|
|
224
|
+
description=a.description, contact=a.contact, methods=a.methods,
|
|
225
|
+
notes=a.notes, overrides=json.loads(a.overrides) if a.overrides else None,
|
|
226
|
+
reviewer=json.loads(a.reviewer) if a.reviewer else None,
|
|
227
|
+
lang=a.lang, output_path=a.out)
|
|
228
|
+
if 'error' in res:
|
|
229
|
+
print(res['error'])
|
|
230
|
+
return 1
|
|
231
|
+
print(json.dumps({'summary': res['summary'], 'pack_sha256': res['pack_sha256'],
|
|
232
|
+
'saved_to': res.get('saved_to'),
|
|
233
|
+
'draft': res['draft']}, ensure_ascii=False))
|
|
234
|
+
return 0
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
if __name__ == '__main__':
|
|
238
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""WebVTT caption quality (1.2.2) — the substance, not just the presence.
|
|
3
|
+
|
|
4
|
+
Everyone (axe included) stops at "<track> exists". This parses the actual
|
|
5
|
+
.vtt file and judges the captions people get: malformed cues, empty text,
|
|
6
|
+
overlaps, impossible reading speeds (>21 chars/second — BBC/Netflix
|
|
7
|
+
subtitling standards), and coverage vs the media duration when given.
|
|
8
|
+
|
|
9
|
+
Zero dependencies. Fetch goes through the shared _descarga guard
|
|
10
|
+
(http/https only, size-capped).
|
|
11
|
+
|
|
12
|
+
CLI:
|
|
13
|
+
a11yvtt.py https://site/captions.vtt [--duration 640]
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import json
|
|
18
|
+
import re
|
|
19
|
+
import sys
|
|
20
|
+
from . import a11yi18n
|
|
21
|
+
|
|
22
|
+
_RE_TIME = re.compile(
|
|
23
|
+
r'(?:(\d{2,}):)?(\d{2}):(\d{2})[.,](\d{3})\s*-->\s*(?:(\d{2,}):)?(\d{2}):(\d{2})[.,](\d{3})')
|
|
24
|
+
|
|
25
|
+
T = a11yi18n.pair('vtt') # locales/<lang>.json — community-editable
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _t(lang, key):
|
|
29
|
+
return T.get(lang, T['en'])[key]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _seconds(h, m, s, ms):
|
|
33
|
+
return int(h or 0) * 3600 + int(m) * 60 + int(s) + int(ms) / 1000.0
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def vtt_check(url, duration=None, lang='en'):
|
|
37
|
+
"""Descarga y juzga un .vtt — el contenido de 1.2.2, no su mera presencia."""
|
|
38
|
+
from .a11yaudit import _fetch, compute_score, CRIT
|
|
39
|
+
data = _fetch(url, timeout=30, truncate_at=2_000_000)
|
|
40
|
+
if isinstance(data, dict) and 'error' in data:
|
|
41
|
+
return data
|
|
42
|
+
if isinstance(data, bytes):
|
|
43
|
+
text = data.decode('utf-8', errors='replace')
|
|
44
|
+
else:
|
|
45
|
+
text = str(data)
|
|
46
|
+
|
|
47
|
+
findings = []
|
|
48
|
+
|
|
49
|
+
def add(sev, key, **fmt):
|
|
50
|
+
findings.append({'severity': sev, 'criterion': CRIT.get(lang, CRIT['es']).get('1.2.2', '1.2.2'),
|
|
51
|
+
'signal': key, 'issue': _t(lang, key).format(**fmt),
|
|
52
|
+
'remediation': _t(lang, key + '_rem').format(**fmt)})
|
|
53
|
+
|
|
54
|
+
if not text.lstrip().startswith('WEBVTT'):
|
|
55
|
+
return {'error': 'does not declare WEBVTT (is it .srt or another format?)',
|
|
56
|
+
'primeros_bytes': text[:40]}
|
|
57
|
+
|
|
58
|
+
blocks = [b for b in re.split(r'\n\s*\n', text) if b.strip()]
|
|
59
|
+
cues, malformed = [], []
|
|
60
|
+
for b in blocks[1:]: # el primero es la cabecera
|
|
61
|
+
lines = [l for l in b.splitlines() if l.strip()]
|
|
62
|
+
m = None
|
|
63
|
+
for i, l in enumerate(lines):
|
|
64
|
+
m = _RE_TIME.search(l)
|
|
65
|
+
if m:
|
|
66
|
+
body = '\n'.join(lines[i + 1:]).strip()
|
|
67
|
+
break
|
|
68
|
+
if not m:
|
|
69
|
+
if '-->' in b:
|
|
70
|
+
malformed.append(lines[0][:30])
|
|
71
|
+
continue
|
|
72
|
+
start = _seconds(*m.groups()[:4])
|
|
73
|
+
end = _seconds(*m.groups()[4:])
|
|
74
|
+
cues.append({'start': start, 'end': end, 'text': body})
|
|
75
|
+
|
|
76
|
+
if malformed:
|
|
77
|
+
add('high', 'vtt_malformed', n=len(malformed), example=', '.join(malformed[:3]))
|
|
78
|
+
if not cues:
|
|
79
|
+
add('high', 'vtt_no_cues')
|
|
80
|
+
return _report(url, findings, 0, 0, lang, duration, cues)
|
|
81
|
+
|
|
82
|
+
empties = [c for c in cues if not c['text']]
|
|
83
|
+
if empties:
|
|
84
|
+
add('medium', 'vtt_empty_cue', n=len(empties))
|
|
85
|
+
|
|
86
|
+
overlaps = sum(1 for a, b in zip(cues, cues[1:]) if b['start'] < a['end'])
|
|
87
|
+
if overlaps:
|
|
88
|
+
add('low', 'vtt_overlap', n=overlaps)
|
|
89
|
+
|
|
90
|
+
too_fast = [{'t': c['text'][:30], 'cps': round(len(c['text']) / max(c['end'] - c['start'], 0.1), 1)}
|
|
91
|
+
for c in cues if not c['text'].startswith('<') and c['text']
|
|
92
|
+
and len(c['text']) / max(c['end'] - c['start'], 0.1) > 21]
|
|
93
|
+
if too_fast:
|
|
94
|
+
add('medium', 'vtt_too_fast', n=len(too_fast),
|
|
95
|
+
example=', '.join(f"{r['t']}… ({r['cps']}cps)" for r in too_fast[:3]))
|
|
96
|
+
|
|
97
|
+
if duration:
|
|
98
|
+
covered = sum(max(0.0, min(c['end'], duration) - c['start']) for c in cues if c['start'] < duration)
|
|
99
|
+
pct = round(100 * covered / max(duration, 1), 1)
|
|
100
|
+
if pct < 95:
|
|
101
|
+
add('medium', 'vtt_coverage', pct=pct, dur=round(duration))
|
|
102
|
+
|
|
103
|
+
n_char = sum(len(c['text']) for c in cues)
|
|
104
|
+
return _report(url, findings, len(cues), n_char, lang, duration, cues)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _report(url, findings, n_cues, n_char, lang, duration, cues):
|
|
108
|
+
from .a11yaudit import compute_score
|
|
109
|
+
order = {'high': 0, 'medium': 1, 'low': 2}
|
|
110
|
+
findings.sort(key=lambda h: order[h['severity']])
|
|
111
|
+
return {
|
|
112
|
+
'mode': 'vtt', 'url': url,
|
|
113
|
+
'duration': duration,
|
|
114
|
+
'cues': n_cues, 'characters': n_char,
|
|
115
|
+
'captioned_seconds': round(sum(c['end'] - c['start'] for c in cues), 1) if cues else 0,
|
|
116
|
+
'score': compute_score(findings),
|
|
117
|
+
'findings': findings,
|
|
118
|
+
'summary': {s: sum(1 for h in findings if h['severity'] == s)
|
|
119
|
+
for s in ('high', 'medium', 'low')},
|
|
120
|
+
'limits': _t(lang, 'limits'),
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def main(argv):
|
|
125
|
+
ap = argparse.ArgumentParser(description=__doc__)
|
|
126
|
+
ap.add_argument('url', help='.vtt URL')
|
|
127
|
+
ap.add_argument('--duration', type=float, help='media duration in seconds (coverage check)')
|
|
128
|
+
ap.add_argument('--lang', default='en', choices=['en', 'es'])
|
|
129
|
+
a = ap.parse_args(argv)
|
|
130
|
+
print(json.dumps(vtt_check(a.url, duration=a.duration, lang=a.lang),
|
|
131
|
+
ensure_ascii=False, indent=1))
|
|
132
|
+
return 0
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
if __name__ == '__main__':
|
|
136
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""WCAG 3 preview — re-groups WCAG 2.2 findings under the draft's outcomes.
|
|
3
|
+
|
|
4
|
+
The W3C publishes WCAG 3 as a Working Draft that "will change substantially".
|
|
5
|
+
This module is a VIEW layer, not an evaluation: it takes an audit report
|
|
6
|
+
(a11y_audit_url / a11y_audit_dom / a11y_disprove …) and re-presents its
|
|
7
|
+
findings grouped by the outcomes of the September 2026 draft.
|
|
8
|
+
|
|
9
|
+
Honest boundaries, by design:
|
|
10
|
+
- NO score, NO tier, NO conformance claim: the draft's tier thresholds
|
|
11
|
+
are explicitly "to-be-determined" by the W3C.
|
|
12
|
+
- NO severity-tag assignment: physical-harm/risk/barrier/friction tags
|
|
13
|
+
qualify the draft's core requirements, not WCAG 2.2 findings.
|
|
14
|
+
- The criterion→outcome mapping is OURS. The W3C has published no
|
|
15
|
+
official WCAG 2 → WCAG 3 mapping (transition materials are planned);
|
|
16
|
+
every grouping is a documented approximation.
|
|
17
|
+
|
|
18
|
+
CLI:
|
|
19
|
+
a11ywcag3.py --from-audit informe.json [--lang es] [-o salida.json]
|
|
20
|
+
a11ywcag3.py --url https://… # audita primero, luego previsualiza
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import argparse
|
|
24
|
+
import json
|
|
25
|
+
import re
|
|
26
|
+
import sys
|
|
27
|
+
|
|
28
|
+
from .a11yi18n import pair
|
|
29
|
+
from .a11ycrit import _SIGNAL_CRIT
|
|
30
|
+
|
|
31
|
+
TXT = pair('wcag3') # locales/<lang>.json — community-editable
|
|
32
|
+
|
|
33
|
+
# borrador contra el que se previsualiza (re-baselinear en cada publicación
|
|
34
|
+
# de marzo/septiembre: outcomes, mapa y metadatos)
|
|
35
|
+
DRAFT = {
|
|
36
|
+
'standard': 'W3C Accessibility Guidelines (WCAG) 3.0',
|
|
37
|
+
'stage': 'Working Draft — in progress, will change substantially',
|
|
38
|
+
'draft_date': '10 September 2026',
|
|
39
|
+
'url': 'https://www.w3.org/TR/wcag-3.0/',
|
|
40
|
+
'intro': 'https://www.w3.org/WAI/standards-guidelines/wcag/wcag3-intro/',
|
|
41
|
+
# lo que el propio W3C dice sobre la coexistencia: WCAG 3 no sustituye a
|
|
42
|
+
# WCAG 2 y WCAG 2 no quedará obsoleto durante años
|
|
43
|
+
'supersede_note': 'WCAG 3 does not supersede WCAG 2; WCAG 2 will not be '
|
|
44
|
+
'deprecated for several years after WCAG 3 is final. '
|
|
45
|
+
'W3C advice: meet WCAG 2.2 now.',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# los 46 outcomes del borrador de sept-2026 (§2, Guidelines) — nombres
|
|
49
|
+
# EXACTOS del documento; re-baselinear en la próxima publicación
|
|
50
|
+
_OUTCOMES = {
|
|
51
|
+
'2.1.1': 'Image alternatives', '2.1.2': 'Figure captions',
|
|
52
|
+
'2.1.3': 'Non-text alternatives', '2.1.4': 'Transcripts',
|
|
53
|
+
'2.1.5': 'Captions', '2.1.6': 'Audio descriptions',
|
|
54
|
+
'2.1.7': 'Sign language', '2.1.8': 'Single sense',
|
|
55
|
+
'2.1.9': 'Accessible media player',
|
|
56
|
+
'2.2.1': 'Text appearance', '2.2.2': 'Text-to-speech',
|
|
57
|
+
'2.2.3': 'Clear language',
|
|
58
|
+
'2.3.1': 'Keyboard focus appearance',
|
|
59
|
+
'2.3.2': 'Pointer focus appearance', '2.3.3': 'Navigating content',
|
|
60
|
+
'2.3.4': 'Expected behavior', '2.3.5': 'Control information',
|
|
61
|
+
'2.4.1': 'Keyboard interface input',
|
|
62
|
+
'2.4.2': 'Physical or cognitive effort when using keyboard',
|
|
63
|
+
'2.4.3': 'Pointer input', '2.4.4': 'Speech and voice input',
|
|
64
|
+
'2.4.5': 'Input operation', '2.4.6': 'Authentication',
|
|
65
|
+
'2.5.1': 'Correct errors', '2.5.2': 'Prevent errors',
|
|
66
|
+
'2.6.1': 'Avoid physical harm',
|
|
67
|
+
'2.7.1': 'Recognizable layouts', '2.7.2': 'User orientation',
|
|
68
|
+
'2.7.3': 'Structure', '2.7.4': 'No obstruction',
|
|
69
|
+
'2.8.1': 'Consistency',
|
|
70
|
+
'2.9.1': 'Avoid exclusionary cognitive tasks', '2.9.2': 'Adequate time',
|
|
71
|
+
'2.9.3': 'Avoid deception', '2.9.4': 'Retain information',
|
|
72
|
+
'2.9.5': 'Complete tasks', '2.9.6': 'Unnecessary steps',
|
|
73
|
+
'2.10.1': 'Risk', '2.10.2': 'Algorithms',
|
|
74
|
+
'2.11.1': 'Help available', '2.11.2': 'Feedback',
|
|
75
|
+
'2.12.1': 'Assistive technology control', '2.12.2': 'Control text',
|
|
76
|
+
'2.12.3': 'Adjustable viewport', '2.12.4': 'Media control',
|
|
77
|
+
'2.12.5': 'Content changes',
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# criterio WCAG 2.2 → outcomes del borrador. CURADO por a11y-toolkit:
|
|
81
|
+
# el W3C no ha publicado mapeo oficial (los materiales de transición están
|
|
82
|
+
# planificados). Cubre el 100% de los criterios alcanzables por señales del
|
|
83
|
+
# toolkit (pinned por tests/test_wcag3.py) más los evidentes sin señal.
|
|
84
|
+
_CRIT_OUTCOME = {
|
|
85
|
+
'1.1.1': ['2.1.1', '2.1.3'], # alt texto / alternativas no textuales
|
|
86
|
+
'1.2.2': ['2.1.5'],
|
|
87
|
+
'1.2.3': ['2.1.6', '2.1.4'],
|
|
88
|
+
'1.2.4': ['2.1.5'],
|
|
89
|
+
'1.2.5': ['2.1.6'],
|
|
90
|
+
'1.3.1': ['2.7.3'],
|
|
91
|
+
'1.3.2': ['2.7.3'],
|
|
92
|
+
'1.3.3': ['2.2.3'], # instrucciones sin rasgos sensoriales
|
|
93
|
+
'1.3.4': ['2.12.3'],
|
|
94
|
+
'1.3.5': ['2.3.5'],
|
|
95
|
+
'1.4.1': ['2.2.1'], # "Hue not relied on" es core req del draft
|
|
96
|
+
'1.4.2': ['2.12.4'],
|
|
97
|
+
'1.4.3': ['2.2.1'],
|
|
98
|
+
'1.4.4': ['2.2.1', '2.12.3'],
|
|
99
|
+
'1.4.5': ['2.2.1'],
|
|
100
|
+
'1.4.10': ['2.12.3'],
|
|
101
|
+
'1.4.12': ['2.2.1'],
|
|
102
|
+
'1.4.13': ['2.3.4'],
|
|
103
|
+
'2.1.1': ['2.4.1'],
|
|
104
|
+
'2.1.2': ['2.4.1'],
|
|
105
|
+
'2.1.4': ['2.4.5'],
|
|
106
|
+
'2.2.1': ['2.9.2'],
|
|
107
|
+
'2.2.2': ['2.12.5'],
|
|
108
|
+
'2.3.1': ['2.6.1'], # sin señal hoy; la vía del daño físico
|
|
109
|
+
'2.4.1': ['2.3.3'],
|
|
110
|
+
'2.4.2': ['2.7.2'],
|
|
111
|
+
'2.4.3': ['2.3.3'],
|
|
112
|
+
'2.4.4': ['2.3.5'],
|
|
113
|
+
'2.4.5': ['2.3.3'],
|
|
114
|
+
'2.4.6': ['2.7.3', '2.2.3'],
|
|
115
|
+
'2.4.7': ['2.3.1'],
|
|
116
|
+
'2.4.11': ['2.7.4'],
|
|
117
|
+
'2.5.1': ['2.4.3'],
|
|
118
|
+
'2.5.2': ['2.4.3'],
|
|
119
|
+
'2.5.3': ['2.4.4', '2.3.5'],
|
|
120
|
+
'2.5.4': ['2.4.5'],
|
|
121
|
+
'2.5.7': ['2.4.3'],
|
|
122
|
+
'2.5.8': ['2.4.3'],
|
|
123
|
+
'3.1.1': ['2.2.2'],
|
|
124
|
+
'3.1.2': ['2.2.2'],
|
|
125
|
+
'3.2.1': ['2.3.4'],
|
|
126
|
+
'3.2.2': ['2.3.4'],
|
|
127
|
+
'3.2.3': ['2.8.1'],
|
|
128
|
+
'3.2.4': ['2.8.1'],
|
|
129
|
+
'3.2.5': ['2.3.4'],
|
|
130
|
+
'3.2.6': ['2.11.1'],
|
|
131
|
+
'3.3.1': ['2.5.1'],
|
|
132
|
+
'3.3.2': ['2.3.5', '2.5.2'],
|
|
133
|
+
'3.3.3': ['2.5.1'],
|
|
134
|
+
'3.3.4': ['2.5.2'],
|
|
135
|
+
'3.3.7': ['2.9.6'], # el draft lo llama "Unnecessary steps"
|
|
136
|
+
'3.3.8': ['2.4.6'],
|
|
137
|
+
'4.1.2': ['2.3.5'],
|
|
138
|
+
'4.1.3': ['2.12.5'],
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_CODE = re.compile(r'^(\d+\.\d+\.\d+)')
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def preview(report, lang='en'):
|
|
145
|
+
"""Re-agrupa un informe WCAG 2.2 bajo los outcomes del borrador WCAG 3.
|
|
146
|
+
|
|
147
|
+
report: dict de auditoría (con 'findings') — cualquier tool de auditoría
|
|
148
|
+
del toolkit. Devuelve dict SIN score/tier/claim de conformidad.
|
|
149
|
+
"""
|
|
150
|
+
t = TXT.get(lang, TXT['en'])
|
|
151
|
+
if not isinstance(report, dict) or not isinstance(report.get('findings'), list):
|
|
152
|
+
return {'error': 'report must be an audit report object with a findings list '
|
|
153
|
+
'(from a11y_audit_url, a11y_audit_dom, …)',
|
|
154
|
+
'hint': 'audit first, then preview the same report'}
|
|
155
|
+
|
|
156
|
+
per_outcome = {}
|
|
157
|
+
unmapped = []
|
|
158
|
+
mapped_count = 0
|
|
159
|
+
for i, f in enumerate(report['findings']):
|
|
160
|
+
if not isinstance(f, dict):
|
|
161
|
+
# nada desaparece en silencio: un finding deforme también se reporta
|
|
162
|
+
unmapped.append({'finding': i, 'signal': None, 'criterion': None,
|
|
163
|
+
'reason': 'not a finding object'})
|
|
164
|
+
continue
|
|
165
|
+
code = None
|
|
166
|
+
m = _CODE.match(str(f.get('criterion') or ''))
|
|
167
|
+
if m:
|
|
168
|
+
code = m.group(1)
|
|
169
|
+
else:
|
|
170
|
+
sig = str(f.get('signal') or '')
|
|
171
|
+
code = _SIGNAL_CRIT.get(sig)
|
|
172
|
+
if not code or code not in _CRIT_OUTCOME:
|
|
173
|
+
unmapped.append({'finding': i, 'signal': f.get('signal'),
|
|
174
|
+
'criterion': f.get('criterion')})
|
|
175
|
+
continue
|
|
176
|
+
mapped_count += 1
|
|
177
|
+
for oc in _CRIT_OUTCOME[code]:
|
|
178
|
+
entry = per_outcome.setdefault(
|
|
179
|
+
oc, {'findings': 0, 'high': 0, 'medium': 0, 'low': 0,
|
|
180
|
+
'signals': set(), 'criteria_22': set()})
|
|
181
|
+
entry['findings'] += 1
|
|
182
|
+
sev = str(f.get('severity') or '').lower()
|
|
183
|
+
# membresía contra la TUPLE de severidades, no contra el dict
|
|
184
|
+
# acumulador: 'findings'/'signals' como severity no pueden colarse
|
|
185
|
+
if sev in ('high', 'medium', 'low'):
|
|
186
|
+
entry[sev] += 1
|
|
187
|
+
entry['signals'].add(str(f.get('signal') or code))
|
|
188
|
+
entry['criteria_22'].add(code)
|
|
189
|
+
|
|
190
|
+
def _vers(oc):
|
|
191
|
+
return tuple(int(x) for x in oc.split('.'))
|
|
192
|
+
|
|
193
|
+
outcomes = []
|
|
194
|
+
for oc in sorted(per_outcome, key=_vers):
|
|
195
|
+
e = per_outcome[oc]
|
|
196
|
+
outcomes.append({
|
|
197
|
+
'outcome': f"{oc} {_OUTCOMES[oc]}",
|
|
198
|
+
'draft_url': DRAFT['url'],
|
|
199
|
+
'findings': e['findings'],
|
|
200
|
+
'severity': {'high': e['high'], 'medium': e['medium'], 'low': e['low']},
|
|
201
|
+
'signals': sorted(e['signals']),
|
|
202
|
+
'criteria_22': sorted(e['criteria_22']),
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
'mode': 'wcag3-preview',
|
|
207
|
+
'lang': lang,
|
|
208
|
+
'draft': dict(DRAFT),
|
|
209
|
+
'disclaimer': t['disclaimer'],
|
|
210
|
+
'mapping_note': t['mapping_note'],
|
|
211
|
+
'no_score': t['no_score'],
|
|
212
|
+
'conformance_model': {
|
|
213
|
+
'levels': 'single conformance level (no A/AA/AAA in the draft)',
|
|
214
|
+
'core_requirement_tags': t['model_tags'],
|
|
215
|
+
'reporting_tiers': t['model_tiers'],
|
|
216
|
+
'source': DRAFT['intro'],
|
|
217
|
+
},
|
|
218
|
+
'outcomes': outcomes,
|
|
219
|
+
'counts': {
|
|
220
|
+
'findings_total': len(report['findings']),
|
|
221
|
+
'findings_mapped': mapped_count,
|
|
222
|
+
'findings_unmapped': len(unmapped),
|
|
223
|
+
'outcomes_touched': len(outcomes),
|
|
224
|
+
'outcomes_in_draft': len(_OUTCOMES),
|
|
225
|
+
},
|
|
226
|
+
'unmapped': unmapped,
|
|
227
|
+
'source_report': {'url': report.get('url'), 'mode': report.get('mode')},
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def main(argv):
|
|
232
|
+
p = argparse.ArgumentParser(description=__doc__)
|
|
233
|
+
p.add_argument('--from-audit', help='audit report JSON file (or - for stdin)')
|
|
234
|
+
p.add_argument('--url', help='audit this URL first, then preview')
|
|
235
|
+
p.add_argument('--lang', default='en', choices=['en', 'es'])
|
|
236
|
+
p.add_argument('-o', '--output', help='write the JSON result here')
|
|
237
|
+
a = p.parse_args(argv)
|
|
238
|
+
if not a.from_audit and not a.url:
|
|
239
|
+
p.error('either --from-audit or --url is required')
|
|
240
|
+
if a.url:
|
|
241
|
+
from .a11yaudit import audit_url
|
|
242
|
+
report = audit_url(a.url, lang=a.lang)
|
|
243
|
+
if 'error' in report:
|
|
244
|
+
print(json.dumps({'error': f"audit failed for {a.url}: {report['error']}",
|
|
245
|
+
'hint': 'fix the URL/network, then retry'}, ensure_ascii=False),
|
|
246
|
+
file=sys.stderr)
|
|
247
|
+
return 1
|
|
248
|
+
else:
|
|
249
|
+
raw = sys.stdin.read() if a.from_audit == '-' else open(a.from_audit, encoding='utf-8').read()
|
|
250
|
+
report = json.loads(raw)
|
|
251
|
+
res = preview(report, lang=a.lang)
|
|
252
|
+
out = json.dumps(res, ensure_ascii=False, indent=1)
|
|
253
|
+
if a.output:
|
|
254
|
+
with open(a.output, 'w', encoding='utf-8') as f:
|
|
255
|
+
f.write(out)
|
|
256
|
+
else:
|
|
257
|
+
print(out)
|
|
258
|
+
return 0 if 'error' not in res else 1
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
if __name__ == '__main__':
|
|
262
|
+
sys.exit(main(sys.argv[1:]))
|