2001105254-netizen/RacePulsePH / .agents/skills/antislop-human
antislop-human
VerifiedHuman and accessibility skill for antislop. Contrast, keyboard, focus, states, and interaction affordances for real people. Includes the contrast checker.
| File | Kind | Size |
|---|---|---|
| LICENSE-web-quality-skills | other | 1.0 KB |
| SKILL.md | skill md | 15.5 KB |
| contrast-check.py | script | 5.6 KB |
| contrast-mcp.py | script | 4.0 KB |
| references/A11Y-PATTERNS.md | markdown | 7.0 KB |
| references/WCAG.md | markdown | 8.0 KB |
contrast-check.py
View on GitHub#!/usr/bin/env python3
"""WCAG 2.x contrast checker, home of the antislop-human contrast checker.
Usage:
python3 contrast-check.py "#FFFFFF" "#777777"
python3 contrast-check.py FFFFFF 777777
python3 contrast-check.py --selftest
Prints the contrast ratio and a PASS/FAIL verdict for normal text (4.5:1)
and large text (3:1, 18px+ per antislop R-25). Exit code 0 only when both
verdicts pass, so scripts can chain on it.
--selftest parses the reference table out of the SKILL.md next to this script
(the skill doc is the source of truth, not a list copied into this script) and
recomputes every row with the formula, checking the ratio and both verdicts.
"""
import os
import re
import sys
REFERENCE_HEADER = "| Pairing (text on background) | Ratio | Normal text (4.5) | Large text (3.0) |"
NAMED_COLORS = {"black": (0, 0, 0), "white": (255, 255, 255)}
def parse_hex(value):
value = value.strip().lstrip("#")
if len(value) == 3:
value = "".join(ch * 2 for ch in value)
if not re.fullmatch(r"[0-9A-Fa-f]{6}", value):
raise ValueError(f"expected a hex color like #FFFFFF, got {value!r}")
return tuple(int(value[i:i + 2], 16) for i in (0, 2, 4))
def parse_pairing(pairing):
"""Turn 'White on #333333' or '#555555 on black' into two RGB tuples."""
colors = []
for token in re.split(r"\s+on\s+", pairing):
token = token.strip()
match = re.search(r"#[0-9A-Fa-f]{3,6}", token)
if match:
colors.append(parse_hex(match.group(0)))
elif token.lower() in NAMED_COLORS:
colors.append(NAMED_COLORS[token.lower()])
else:
raise ValueError(f"cannot parse {token!r} from pairing {pairing!r}")
if len(colors) != 2:
raise ValueError(f"expected two colors in pairing {pairing!r}")
return tuple(colors)
def linearize(channel):
c = channel / 255.0
if c <= 0.03928:
return c / 12.92
return ((c + 0.055) / 1.055) ** 2.4
def luminance(rgb):
r, g, b = (linearize(ch) for ch in rgb)
return 0.2126 * r + 0.7152 * g + 0.0722 * b
def contrast_ratio(color_a, color_b):
lum_a, lum_b = luminance(color_a), luminance(color_b)
lighter, darker = sorted((lum_a, lum_b), reverse=True)
return (lighter + 0.05) / (darker + 0.05)
def reference_doc_path():
here = os.path.dirname(os.path.abspath(__file__))
candidate = os.path.join(here, "SKILL.md")
return candidate if os.path.isfile(candidate) else None
def parse_reference_rows(path):
"""Reference table rows from SKILL.md, with the ratio already a float.
A row that does not split into four cells is dropped silently, not raised.
"""
rows = []
with open(path, encoding="utf-8") as handle:
in_table = False
for raw in handle:
line = raw.rstrip("\n")
if line.startswith(REFERENCE_HEADER):
in_table = True
continue
if not in_table:
continue
if not line.startswith("|"):
break
if line.startswith("|---"):
continue
cells = [cell.strip() for cell in line.strip().strip("|").split("|")]
if len(cells) != 4:
continue
pairing, ratio, normal, large = cells
rows.append({
"pairing": pairing,
"ratio": float(ratio),
"normal": normal,
"large": large,
})
return rows
def selftest():
doc = reference_doc_path()
if doc is None:
print("selftest: SKILL.md not found next to the script; cannot check the table")
return 2
try:
rows = parse_reference_rows(doc)
except (OSError, ValueError) as exc:
print(f"selftest: could not read the table from SKILL.md: {exc}")
return 1
if not rows:
print("selftest: no reference rows found in SKILL.md")
return 1
failures = 0
for row in rows:
color_a, color_b = parse_pairing(row["pairing"])
# The verdicts read the unrounded ratio, exactly as main() does. Rounding first
# turns a 4.498:1 pairing into a displayed 4.50 that would pass 4.5:1 on paper.
raw = contrast_ratio(color_a, color_b)
computed = round(raw, 2)
expected_normal = "Pass" if raw >= 4.5 else "Fail"
expected_large = "Pass" if raw >= 3.0 else "Fail"
if f"{computed:.2f}" != f"{row['ratio']:.2f}":
failures += 1
print(f"selftest: {row['pairing']}: table says {row['ratio']}, the formula says {computed:.2f}")
if row["normal"] != expected_normal:
failures += 1
print(f"selftest: {row['pairing']}: normal text marked {row['normal']}, should be {expected_normal}")
if row["large"] != expected_large:
failures += 1
print(f"selftest: {row['pairing']}: large text marked {row['large']}, should be {expected_large}")
if failures:
return 1
print(f"selftest: {len(rows)} reference pairs OK")
return 0
def main(argv):
if len(argv) == 1 and argv[0] == "--selftest":
return selftest()
if len(argv) != 2:
print("usage: python3 contrast-check.py <hex1> <hex2> | --selftest")
return 2
try:
ratio = contrast_ratio(parse_hex(argv[0]), parse_hex(argv[1]))
except ValueError as exc:
print(f"error: {exc}")
return 2
normal = ratio >= 4.5
large = ratio >= 3.0
print(f"ratio: {ratio:.2f}:1")
print(f"normal text (4.5:1): {'PASS' if normal else 'FAIL'}")
print(f"large text (3.0:1): {'PASS' if large else 'FAIL'}")
return 0 if normal and large else 1
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |