protocolith 0.6.0__py3-none-any.whl
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.
- protocolith/__init__.py +38 -0
- protocolith/baseline_groups.py +294 -0
- protocolith/baselines.py +288 -0
- protocolith/card_svg_render.py +281 -0
- protocolith/card_svg_styles.py +178 -0
- protocolith/cli.py +796 -0
- protocolith/core/__init__.py +63 -0
- protocolith/core/_lock_posix.py +29 -0
- protocolith/core/_lock_windows.py +29 -0
- protocolith/core/atlas.py +406 -0
- protocolith/core/atlas_assets/atlas.css +86 -0
- protocolith/core/atlas_assets/atlas.html +84 -0
- protocolith/core/atlas_assets/atlas.js +370 -0
- protocolith/core/atlas_i18n/en.json +61 -0
- protocolith/core/canonical.py +124 -0
- protocolith/core/capture.py +68 -0
- protocolith/core/clock.py +25 -0
- protocolith/core/commands.py +356 -0
- protocolith/core/errors.py +116 -0
- protocolith/core/issue.py +98 -0
- protocolith/core/ledger.py +75 -0
- protocolith/core/mcp.py +371 -0
- protocolith/core/ops.py +183 -0
- protocolith/core/rules.py +352 -0
- protocolith/core/schema.py +137 -0
- protocolith/core/store.py +101 -0
- protocolith/core/views.py +136 -0
- protocolith/doctor.py +135 -0
- protocolith/evidence_card.py +354 -0
- protocolith/family_ledger.py +489 -0
- protocolith/generic_ohlcv_batch_pre_registration_meta.py +123 -0
- protocolith/inspect.py +48 -0
- protocolith/nasa_power.py +266 -0
- protocolith/nasa_power_fetch.py +64 -0
- protocolith/nasa_power_parser.py +133 -0
- protocolith/nasa_power_prereg_runner.py +383 -0
- protocolith/noaa_coops_fetch.py +188 -0
- protocolith/noaa_coops_parser.py +120 -0
- protocolith/noaa_coops_prereg_runner.py +341 -0
- protocolith/public_ai_protocol.py +176 -0
- protocolith/py.typed +0 -0
- protocolith/registry.py +139 -0
- protocolith/registry_view.py +302 -0
- protocolith/rerun_report.py +111 -0
- protocolith/run_root.py +243 -0
- protocolith/scaffold.py +565 -0
- protocolith/source_probe.py +230 -0
- protocolith/svg_a11y.py +100 -0
- protocolith/tree_overlay.py +343 -0
- protocolith/verify_packs.py +251 -0
- protocolith/workflows.py +233 -0
- protocolith-0.6.0.dist-info/METADATA +283 -0
- protocolith-0.6.0.dist-info/RECORD +57 -0
- protocolith-0.6.0.dist-info/WHEEL +4 -0
- protocolith-0.6.0.dist-info/entry_points.txt +3 -0
- protocolith-0.6.0.dist-info/licenses/LICENSE +201 -0
- protocolith-0.6.0.dist-info/licenses/NOTICE +13 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Render Protocolith evidence-card SVG from JSON."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import textwrap
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
from xml.sax.saxutils import escape
|
|
11
|
+
|
|
12
|
+
from protocolith.card_svg_styles import (
|
|
13
|
+
HEIGHT,
|
|
14
|
+
WIDTH,
|
|
15
|
+
gradient_defs,
|
|
16
|
+
reproduction_gradient,
|
|
17
|
+
result_gradient,
|
|
18
|
+
style_attr,
|
|
19
|
+
validity_gradient,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def render_svg(card_path: Path) -> str:
|
|
24
|
+
card = json.loads(card_path.read_text(encoding="utf-8"))
|
|
25
|
+
if not isinstance(card, dict):
|
|
26
|
+
raise ValueError("evidence card must be a JSON object")
|
|
27
|
+
return _render_card(_visual_values(card))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def render_all_cards(cards_dir: Path) -> list[Path]:
|
|
31
|
+
rendered: list[Path] = []
|
|
32
|
+
for card_path in sorted(cards_dir.glob("PLITH-*.json")):
|
|
33
|
+
svg_path = card_path.with_suffix(".svg")
|
|
34
|
+
svg_path.write_text(render_svg(card_path), encoding="utf-8")
|
|
35
|
+
rendered.append(svg_path)
|
|
36
|
+
return rendered
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _visual_values(card: dict[str, Any]) -> dict[str, Any]:
|
|
40
|
+
visual = card.get("visual_summary")
|
|
41
|
+
if not isinstance(visual, dict):
|
|
42
|
+
visual = {}
|
|
43
|
+
|
|
44
|
+
evidence_id = str(card.get("evidence_id", ""))
|
|
45
|
+
source_name = str(card.get("official_source_name", ""))
|
|
46
|
+
source_url = str(card.get("official_source_url", ""))
|
|
47
|
+
sanitized_report_path = str(card.get("sanitized_report_path", ""))
|
|
48
|
+
sanitized_report_sha256 = str(card.get("sanitized_report_sha256", ""))
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
"access_date": str(card.get("access_date", "")),
|
|
52
|
+
"allowed_claim_sentence": _first(
|
|
53
|
+
visual,
|
|
54
|
+
"allowed_claim_sentence",
|
|
55
|
+
card.get("allowed_claim_sentence") or card.get("claim_type"),
|
|
56
|
+
),
|
|
57
|
+
"artifact_ref": _first(visual, "artifact_ref", sanitized_report_path),
|
|
58
|
+
"candidate_definition": _first(visual, "candidate_definition", source_name),
|
|
59
|
+
"card_validity_level": str(card.get("card_validity_level") or _default_card_validity(card)),
|
|
60
|
+
"claim_boundary": str(card.get("claim_boundary", "")),
|
|
61
|
+
"controls_and_gate": _first(
|
|
62
|
+
visual,
|
|
63
|
+
"controls_and_gate",
|
|
64
|
+
card.get("baseline_control_summary"),
|
|
65
|
+
),
|
|
66
|
+
"evidence_id": evidence_id,
|
|
67
|
+
"evidence_url": _format_path(
|
|
68
|
+
_first(visual, "evidence_url", f"docs/evidence_cards/{evidence_id}.json")
|
|
69
|
+
),
|
|
70
|
+
"known_limitations": [str(item) for item in card.get("known_limitations", [])],
|
|
71
|
+
"operator": str(card.get("operator", "")),
|
|
72
|
+
"period_scope": _first(visual, "period_scope", card.get("access_date")),
|
|
73
|
+
"protocol_id": str(card.get("protocol_id", "")),
|
|
74
|
+
"raw_payload_policy": str(
|
|
75
|
+
card.get("raw_payload_manifest") or card.get("source_rights_note") or ""
|
|
76
|
+
),
|
|
77
|
+
"record_type": str(card.get("record_type", "")),
|
|
78
|
+
"reproduction_level": _short_reproduction(str(card.get("reproduction_level", ""))),
|
|
79
|
+
"result_status": str(card.get("result_status", "")),
|
|
80
|
+
"sanitized_report_path": sanitized_report_path,
|
|
81
|
+
"sanitized_report_sha256": sanitized_report_sha256,
|
|
82
|
+
"source": f"{source_name}\n{_format_path(source_url)}".strip(),
|
|
83
|
+
"target_definition": _first(visual, "target_definition", card.get("domain")),
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _render_card(values: dict[str, Any]) -> str:
|
|
88
|
+
out = [
|
|
89
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
90
|
+
(
|
|
91
|
+
f'<svg xmlns="http://www.w3.org/2000/svg" width="{WIDTH}" height="{HEIGHT}" '
|
|
92
|
+
f'viewBox="0 0 {WIDTH} {HEIGHT}" role="img" '
|
|
93
|
+
'aria-labelledby="cb-title cb-desc">'
|
|
94
|
+
),
|
|
95
|
+
f' <title id="cb-title">{_e(_accessible_title(values))}</title>',
|
|
96
|
+
f' <desc id="cb-desc">{_e(_accessible_description(values))}</desc>',
|
|
97
|
+
*gradient_defs(),
|
|
98
|
+
f' <rect x="0" y="0" width="{WIDTH}" height="{HEIGHT}" fill="#eef3f8"/>',
|
|
99
|
+
f' <rect x="44" y="44" width="{WIDTH - 88}" height="{HEIGHT - 88}" rx="34" fill="#ffffff" stroke="#cfd7e3" stroke-width="3"/>',
|
|
100
|
+
' <path d="M70 158 H1930" stroke="#d7dde7" stroke-width="3"/>',
|
|
101
|
+
f' <text x="70" y="93" {style_attr("title")}>Protocolith Card</text>',
|
|
102
|
+
f' <text x="73" y="129" {style_attr("subtitle")}>Protocol-bound, reproducible evidence summary</text>',
|
|
103
|
+
*(_logo_lockup(1415, 52, 0.33)),
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
out.extend(_chip(70, 193, 430, "Result status", values["result_status"], result_gradient(values["result_status"])))
|
|
107
|
+
out.extend(_chip(520, 193, 370, "Validity", values["card_validity_level"], validity_gradient(values["card_validity_level"])))
|
|
108
|
+
out.extend(_chip(910, 193, 480, "Reproduction", values["reproduction_level"], reproduction_gradient(values["reproduction_level"])))
|
|
109
|
+
out.extend(_chip(1410, 193, 520, "Record type", values["record_type"], "blueGrad"))
|
|
110
|
+
out.extend(_claim_box(70, 278, 1860, values["allowed_claim_sentence"]))
|
|
111
|
+
|
|
112
|
+
x1, x2, w = 70, 1010, 920
|
|
113
|
+
out.extend(_field_box(x1, 420, w, 106, "Evidence ID", values["evidence_id"], mono=True))
|
|
114
|
+
out.extend(_field_box(x2, 420, w, 106, "Protocol", values["protocol_id"], mono=True))
|
|
115
|
+
out.extend(_field_box(x1, 542, w, 114, "Official Source", values["source"]))
|
|
116
|
+
out.extend(_field_box(x2, 542, w, 114, "Target / Candidate", f"{values['target_definition']}\n{values['candidate_definition']}"))
|
|
117
|
+
out.extend(_field_box(x1, 672, w, 114, "Controls / Gate", values["controls_and_gate"]))
|
|
118
|
+
out.extend(_field_box(x2, 672, w, 114, "Period / Scope / Date", f"{values['period_scope']}\nAccess date: {values['access_date']}"))
|
|
119
|
+
out.extend(_field_box(x1, 802, w, 114, "Artifact / Report", f"{values['artifact_ref']}\n{values['sanitized_report_path']}"))
|
|
120
|
+
out.extend(_field_box(x2, 802, w, 114, "Evidence URL", values["evidence_url"], mono=True))
|
|
121
|
+
out.extend(_wide_note(70, 938, 1860, "Claim boundary", values["claim_boundary"], values["known_limitations"]))
|
|
122
|
+
out.append("</svg>")
|
|
123
|
+
return "\n".join(out) + "\n"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _accessible_title(values: dict[str, Any]) -> str:
|
|
127
|
+
return f"Protocolith Card {values['evidence_id'] or 'unidentified'}"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _accessible_description(values: dict[str, Any]) -> str:
|
|
131
|
+
parts = [
|
|
132
|
+
f"Result status: {values['result_status'] or 'n/a'}.",
|
|
133
|
+
f"Reproduction: {values['reproduction_level'] or 'n/a'}.",
|
|
134
|
+
f"Allowed narrow claim: {values['allowed_claim_sentence'] or 'n/a'}.",
|
|
135
|
+
f"Claim boundary: {values['claim_boundary'] or 'n/a'}",
|
|
136
|
+
]
|
|
137
|
+
return " ".join(" ".join(part.split()) for part in parts)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _chip(x: int, y: int, w: int, label: str, value: str, gradient_id: str) -> list[str]:
|
|
141
|
+
lines = [
|
|
142
|
+
f' <text x="{x}" y="{y - 18}" {style_attr("chipLabel")}>{_e(label)}</text>',
|
|
143
|
+
f' <rect x="{x}" y="{y}" width="{w}" height="52" rx="17" fill="url(#{gradient_id})"/>',
|
|
144
|
+
]
|
|
145
|
+
text_lines = _wrap(value, _chars_for_width(w - 42, 21), max_lines=2)
|
|
146
|
+
start_y = y + 23 if len(text_lines) == 2 else y + 34
|
|
147
|
+
lines.extend(_text_lines(x + 21, start_y, text_lines, "chipText", 24))
|
|
148
|
+
return lines
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _claim_box(x: int, y: int, w: int, claim: str) -> list[str]:
|
|
152
|
+
lines = [
|
|
153
|
+
f' <rect x="{x}" y="{y}" width="{w}" height="96" rx="16" fill="#f8fbff" stroke="#1758d6" stroke-width="4"/>',
|
|
154
|
+
f' <text x="{x + 26}" y="{y + 31}" {style_attr("claimLabel")}>Allowed narrow claim</text>',
|
|
155
|
+
]
|
|
156
|
+
wrapped = _wrap(claim, _chars_for_width(w - 52, 39), max_lines=2)
|
|
157
|
+
lines.extend(_text_lines(x + 26, y + 73, wrapped, "claimText", 42))
|
|
158
|
+
return lines
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _field_box(
|
|
162
|
+
x: int,
|
|
163
|
+
y: int,
|
|
164
|
+
w: int,
|
|
165
|
+
h: int,
|
|
166
|
+
label: str,
|
|
167
|
+
value: str,
|
|
168
|
+
*,
|
|
169
|
+
mono: bool = False,
|
|
170
|
+
) -> list[str]:
|
|
171
|
+
text_style = "mono" if mono else "fieldText"
|
|
172
|
+
font_size = 18 if mono else 22
|
|
173
|
+
line_height = 23 if mono else 26
|
|
174
|
+
max_lines = max(1, (h - 48) // line_height)
|
|
175
|
+
wrapped = _wrap(value, _chars_for_width(w - 52, font_size), max_lines=max_lines)
|
|
176
|
+
lines = [
|
|
177
|
+
f' <rect x="{x}" y="{y}" width="{w}" height="{h}" rx="14" fill="#ffffff" stroke="#d8dee9" stroke-width="3"/>',
|
|
178
|
+
f' <text x="{x + 22}" y="{y + 29}" {style_attr("fieldLabel")}>{_e(label)}</text>',
|
|
179
|
+
]
|
|
180
|
+
lines.extend(_text_lines(x + 22, y + 58, wrapped, text_style, line_height))
|
|
181
|
+
return lines
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _wide_note(
|
|
185
|
+
x: int,
|
|
186
|
+
y: int,
|
|
187
|
+
w: int,
|
|
188
|
+
label: str,
|
|
189
|
+
boundary: str,
|
|
190
|
+
limitations: list[str],
|
|
191
|
+
) -> list[str]:
|
|
192
|
+
boundary_lines = _wrap(boundary, _chars_for_width(w - 48, 20), max_lines=3)
|
|
193
|
+
limitation_text = " Limitations: " + " ".join(f"{idx + 1}. {item}" for idx, item in enumerate(limitations))
|
|
194
|
+
limitation_lines = _wrap(limitation_text, _chars_for_width(w - 48, 17), max_lines=2)
|
|
195
|
+
h = 42 + (len(boundary_lines) * 24) + 10 + (len(limitation_lines) * 20) + 22
|
|
196
|
+
lines = [
|
|
197
|
+
f' <rect x="{x}" y="{y - 2}" width="{w}" height="{h}" rx="14" fill="#fbfcfe" stroke="#d8dee9" stroke-width="3"/>',
|
|
198
|
+
f' <text x="{x + 22}" y="{y + 28}" {style_attr("fieldLabel")}>{_e(label)}</text>',
|
|
199
|
+
]
|
|
200
|
+
lines.extend(_text_lines(x + 22, y + 55, boundary_lines, "bodyText", 24))
|
|
201
|
+
lines.extend(_text_lines(x + 22, y + 55 + len(boundary_lines) * 24 + 10, limitation_lines, "muted", 20))
|
|
202
|
+
return lines
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _logo_lockup(x: int, y: int, scale: float) -> list[str]:
|
|
206
|
+
return [
|
|
207
|
+
f' <g aria-label="Protocolith evidence logo" transform="translate({x},{y}) scale({scale}) translate(-40,-478)">',
|
|
208
|
+
' <g stroke-linecap="butt" stroke-linejoin="round">',
|
|
209
|
+
' <g stroke="#CBD3DC" stroke-width="3.2" stroke-linecap="round" stroke-dasharray="10 12" opacity="0.72">',
|
|
210
|
+
' <path d="M130 507V714"/><path d="M162 490V719"/><path d="M199 491V719"/>',
|
|
211
|
+
' <path d="M230 471V726"/><path d="M276 521V690"/><path d="M327 508V650"/>',
|
|
212
|
+
' <path d="M128 520H277"/><path d="M128 595H327"/><path d="M128 672H355"/>',
|
|
213
|
+
" </g>",
|
|
214
|
+
' <path d="M342.6 514.3A160 160 0 1 0 230 787" fill="none" stroke="url(#logoRingBlue)" stroke-width="23"/>',
|
|
215
|
+
' <path d="M230 787A160 160 0 0 0 388.4 649.3" fill="none" stroke="url(#logoRingTeal)" stroke-width="23"/>',
|
|
216
|
+
' <path d="M63 629.5C87 616.4 104.3 613.6 121.2 632.2C140.7 653.8 153.4 651.6 162.1 616.2C173.8 568.5 182.5 527.5 198.9 527.5C217.5 527.5 228.4 590.6 240.3 630.8C253.4 675.4 268.6 682.8 284.6 641.5C303.5 592.9 315.2 567.6 333.7 574.7C352.6 582 355.7 635.1 376.6 634.9C386.2 634.8 394 630.4 402 626.8" fill="none" stroke="url(#logoSignalGradient)" stroke-width="11.5" stroke-linecap="round"/>',
|
|
217
|
+
' <path d="M284 684.5L307.5 707.7L353 657" fill="none" stroke="#12B4A4" stroke-width="10.5" stroke-linecap="square"/>',
|
|
218
|
+
" </g>",
|
|
219
|
+
' <text x="428" y="633" font-family="Inter, Segoe UI, Arial, sans-serif" font-size="124" font-weight="750" fill="#082F59" text-rendering="geometricPrecision">Claim</text>',
|
|
220
|
+
' <text x="792" y="633" font-family="Inter, Segoe UI, Arial, sans-serif" font-size="124" font-weight="750" fill="#0E73CC" text-rendering="geometricPrecision">Bound</text>',
|
|
221
|
+
' <line x1="436" y1="700" x2="514" y2="700" stroke="#11AFA9" stroke-width="4"/>',
|
|
222
|
+
' <text x="542" y="717" font-family="Inter, Segoe UI, Arial, sans-serif" font-size="38" font-weight="500" letter-spacing="13" fill="#082F59">evidence</text>',
|
|
223
|
+
' <line x1="1120" y1="700" x2="1194" y2="700" stroke="#11AFA9" stroke-width="4"/>',
|
|
224
|
+
" </g>",
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _text_lines(x: int, y: int, lines: list[str], style_name: str, line_height: int) -> list[str]:
|
|
229
|
+
attrs = style_attr(style_name)
|
|
230
|
+
return [f' <text x="{x}" y="{y + idx * line_height}" {attrs}>{_e(line)}</text>' for idx, line in enumerate(lines)]
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _wrap(value: str, width: int, *, max_lines: int) -> list[str]:
|
|
234
|
+
paragraphs = [" ".join(part.split()) for part in str(value or "").splitlines() if part.strip()]
|
|
235
|
+
if not paragraphs:
|
|
236
|
+
return ["n/a"]
|
|
237
|
+
lines: list[str] = []
|
|
238
|
+
for paragraph in paragraphs:
|
|
239
|
+
lines.extend(textwrap.wrap(paragraph, width=max(8, width), break_long_words=True, break_on_hyphens=False))
|
|
240
|
+
return lines[:max_lines]
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _chars_for_width(width: int, font_size: int) -> int:
|
|
244
|
+
return max(8, int(width / (font_size * 0.55)))
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _first(mapping: dict[str, Any], key: str, fallback: object) -> str:
|
|
248
|
+
value = mapping.get(key)
|
|
249
|
+
if value is None or str(value).strip() == "":
|
|
250
|
+
value = fallback
|
|
251
|
+
return str(value or "")
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _format_path(value: str) -> str:
|
|
255
|
+
github_blob_prefix = "https://github.com/protocolith/protocolith/blob/main/"
|
|
256
|
+
if value.startswith(github_blob_prefix):
|
|
257
|
+
return value.removeprefix(github_blob_prefix)
|
|
258
|
+
if len(value) <= 64 or "/" not in value:
|
|
259
|
+
return value
|
|
260
|
+
prefix, leaf = value.rsplit("/", 1)
|
|
261
|
+
return f"{prefix}/\n{leaf}"
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _short_reproduction(value: str) -> str:
|
|
265
|
+
value = value.strip()
|
|
266
|
+
if value.upper() == "REPRODUCED_OUTCOME_WITH_SOURCE_BYTE_DRIFT":
|
|
267
|
+
return "OUTCOME REPRODUCED; BYTE DRIFT"
|
|
268
|
+
if value.upper() == "REPRODUCED_OUTCOME":
|
|
269
|
+
return "OUTCOME REPRODUCED"
|
|
270
|
+
return value
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def _default_card_validity(card: dict[str, Any]) -> str:
|
|
274
|
+
draft_status = str(card.get("draft_status", "")).upper()
|
|
275
|
+
if draft_status:
|
|
276
|
+
return draft_status
|
|
277
|
+
return "GREEN_VALIDATED"
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _e(value: str) -> str:
|
|
281
|
+
return escape(str(value), {'"': """})
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Inline SVG text styles for GitHub-safe evidence card rendering."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
WIDTH = 2000
|
|
9
|
+
HEIGHT = 1190
|
|
10
|
+
|
|
11
|
+
_FONT = 'font-family="Inter, Segoe UI, Arial, sans-serif"'
|
|
12
|
+
_MONO = 'font-family="SFMono-Regular, Consolas, Liberation Mono, monospace"'
|
|
13
|
+
|
|
14
|
+
TEXT_STYLES: dict[str, str] = {
|
|
15
|
+
"title": f'{_FONT} font-size="50" font-weight="750" fill="#0d1736"',
|
|
16
|
+
"subtitle": f'{_FONT} font-size="23" font-weight="400" fill="#55627a"',
|
|
17
|
+
"chipLabel": f'{_FONT} font-size="16" font-weight="650" fill="#536174"',
|
|
18
|
+
"chipText": f'{_FONT} font-size="21" font-weight="800" fill="#ffffff"',
|
|
19
|
+
"claimLabel": f'{_FONT} font-size="20" font-weight="750" fill="#1758d6"',
|
|
20
|
+
"claimText": f'{_FONT} font-size="39" font-weight="800" fill="#0d1736"',
|
|
21
|
+
"fieldLabel": f'{_FONT} font-size="19" font-weight="750" fill="#1758d6"',
|
|
22
|
+
"fieldText": f'{_FONT} font-size="22" font-weight="600" fill="#111827"',
|
|
23
|
+
"mono": f'{_MONO} font-size="18" font-weight="600" fill="#111827"',
|
|
24
|
+
"bodyText": f'{_FONT} font-size="20" font-weight="500" fill="#1f2937"',
|
|
25
|
+
"muted": f'{_FONT} font-size="17" font-weight="500" fill="#55627a"',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Status-chip text is white, so every chip gradient stop must reach this WCAG 2.x
|
|
30
|
+
# contrast ratio against it; dark text is checked against the page backgrounds.
|
|
31
|
+
MIN_TEXT_CONTRAST = 4.5
|
|
32
|
+
CHIP_TEXT_FILL = "#ffffff"
|
|
33
|
+
PAGE_BACKGROUNDS = ("#eef3f8", "#ffffff", "#f8fbff", "#fbfcfe")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def style_attr(name: str) -> str:
|
|
37
|
+
try:
|
|
38
|
+
return TEXT_STYLES[name]
|
|
39
|
+
except KeyError as exc:
|
|
40
|
+
raise KeyError(f"unknown SVG text style: {name}") from exc
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def gradient_defs() -> list[str]:
|
|
44
|
+
return [
|
|
45
|
+
" <defs>",
|
|
46
|
+
' <linearGradient id="greenGrad" x1="0" y1="0" x2="1" y2="0">',
|
|
47
|
+
' <stop offset="0%" stop-color="#0b7a70"/>',
|
|
48
|
+
' <stop offset="100%" stop-color="#08685f"/>',
|
|
49
|
+
" </linearGradient>",
|
|
50
|
+
' <linearGradient id="yellowGrad" x1="0" y1="0" x2="1" y2="0">',
|
|
51
|
+
' <stop offset="0%" stop-color="#a16207"/>',
|
|
52
|
+
' <stop offset="100%" stop-color="#854d0e"/>',
|
|
53
|
+
" </linearGradient>",
|
|
54
|
+
' <linearGradient id="amberGrad" x1="0" y1="0" x2="1" y2="0">',
|
|
55
|
+
' <stop offset="0%" stop-color="#c2410c"/>',
|
|
56
|
+
' <stop offset="100%" stop-color="#9a3412"/>',
|
|
57
|
+
" </linearGradient>",
|
|
58
|
+
' <linearGradient id="redGrad" x1="0" y1="0" x2="1" y2="0">',
|
|
59
|
+
' <stop offset="0%" stop-color="#dc2626"/>',
|
|
60
|
+
' <stop offset="100%" stop-color="#b91c1c"/>',
|
|
61
|
+
" </linearGradient>",
|
|
62
|
+
' <linearGradient id="grayGrad" x1="0" y1="0" x2="1" y2="0">',
|
|
63
|
+
' <stop offset="0%" stop-color="#64748b"/>',
|
|
64
|
+
' <stop offset="100%" stop-color="#475569"/>',
|
|
65
|
+
" </linearGradient>",
|
|
66
|
+
' <linearGradient id="blueGrad" x1="0" y1="0" x2="1" y2="0">',
|
|
67
|
+
' <stop offset="0%" stop-color="#1f64f2"/>',
|
|
68
|
+
' <stop offset="100%" stop-color="#1758d6"/>',
|
|
69
|
+
" </linearGradient>",
|
|
70
|
+
' <linearGradient id="logoRingBlue" x1="73" y1="453" x2="348" y2="793" gradientUnits="userSpaceOnUse">',
|
|
71
|
+
' <stop offset="0" stop-color="#1E64BA"/>',
|
|
72
|
+
' <stop offset="0.55" stop-color="#0C75C8"/>',
|
|
73
|
+
' <stop offset="1" stop-color="#0A5FAB"/>',
|
|
74
|
+
" </linearGradient>",
|
|
75
|
+
' <linearGradient id="logoRingTeal" x1="221" y1="792" x2="403" y2="594" gradientUnits="userSpaceOnUse">',
|
|
76
|
+
' <stop offset="0" stop-color="#18B7A3"/>',
|
|
77
|
+
' <stop offset="1" stop-color="#089EBC"/>',
|
|
78
|
+
" </linearGradient>",
|
|
79
|
+
' <linearGradient id="logoSignalGradient" x1="61" y1="628" x2="404" y2="628" gradientUnits="userSpaceOnUse">',
|
|
80
|
+
' <stop offset="0" stop-color="#1E64BA"/>',
|
|
81
|
+
' <stop offset="0.43" stop-color="#0877C4"/>',
|
|
82
|
+
' <stop offset="0.72" stop-color="#0A97BB"/>',
|
|
83
|
+
' <stop offset="1" stop-color="#14B69E"/>',
|
|
84
|
+
" </linearGradient>",
|
|
85
|
+
" </defs>",
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def result_gradient(result_status: str) -> str:
|
|
90
|
+
value = result_status.upper()
|
|
91
|
+
if value in {"PASSED_UNDER_PROTOCOL", "REPRODUCED_OUTCOME"}:
|
|
92
|
+
return "greenGrad"
|
|
93
|
+
if value == "REPRODUCED_OUTCOME_WITH_SOURCE_BYTE_DRIFT":
|
|
94
|
+
return "yellowGrad"
|
|
95
|
+
if value in {"BLOCKED_SOURCE", "INSUFFICIENT_COVERAGE"}:
|
|
96
|
+
return "amberGrad"
|
|
97
|
+
if value == "NEGATIVE_RESULT_UNDER_PROTOCOL":
|
|
98
|
+
return "redGrad"
|
|
99
|
+
if "DRAFT" in value or "NOT_EXECUTED" in value:
|
|
100
|
+
return "grayGrad"
|
|
101
|
+
return "blueGrad"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def validity_gradient(card_validity_level: str) -> str:
|
|
105
|
+
value = card_validity_level.upper()
|
|
106
|
+
if value.startswith("GREEN") or value == "VALIDATED":
|
|
107
|
+
return "greenGrad"
|
|
108
|
+
if value.startswith("YELLOW"):
|
|
109
|
+
return "yellowGrad"
|
|
110
|
+
if value.startswith("RED"):
|
|
111
|
+
return "redGrad"
|
|
112
|
+
if value.startswith("GRAY") or "DRAFT" in value:
|
|
113
|
+
return "grayGrad"
|
|
114
|
+
return "blueGrad"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def reproduction_gradient(reproduction_level: str) -> str:
|
|
118
|
+
value = reproduction_level.upper()
|
|
119
|
+
if value == "REPRODUCED_OUTCOME":
|
|
120
|
+
return "greenGrad"
|
|
121
|
+
if "SOURCE_BYTE_DRIFT" in value or "BYTE DRIFT" in value:
|
|
122
|
+
return "yellowGrad"
|
|
123
|
+
if "NOT" in value and "REPRODUCED" in value:
|
|
124
|
+
return "blueGrad"
|
|
125
|
+
if "DRAFT" in value or "NOT_EXECUTED" in value:
|
|
126
|
+
return "grayGrad"
|
|
127
|
+
return "blueGrad"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def relative_luminance(color: str) -> float:
|
|
131
|
+
"""WCAG 2.x relative luminance of a ``#rrggbb`` (or ``#rgb``) colour."""
|
|
132
|
+
value = color.strip().lstrip("#")
|
|
133
|
+
if len(value) == 3:
|
|
134
|
+
value = "".join(ch * 2 for ch in value)
|
|
135
|
+
if len(value) != 6:
|
|
136
|
+
raise ValueError(f"unsupported colour: {color!r}")
|
|
137
|
+
channels = []
|
|
138
|
+
for index in (0, 2, 4):
|
|
139
|
+
c = int(value[index : index + 2], 16) / 255
|
|
140
|
+
channels.append(c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4)
|
|
141
|
+
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def contrast_ratio(foreground: str, background: str) -> float:
|
|
145
|
+
"""WCAG 2.x contrast ratio (1.0 to 21.0) between two colours."""
|
|
146
|
+
lighter, darker = sorted(
|
|
147
|
+
(relative_luminance(foreground), relative_luminance(background)), reverse=True
|
|
148
|
+
)
|
|
149
|
+
return (lighter + 0.05) / (darker + 0.05)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def chip_gradient_stops() -> list[str]:
|
|
153
|
+
"""Stop colours of the status-chip gradients (not the logo gradients)."""
|
|
154
|
+
stops: list[str] = []
|
|
155
|
+
current = ""
|
|
156
|
+
for line in gradient_defs():
|
|
157
|
+
ident = re.search(r'<linearGradient id="(\w+)"', line)
|
|
158
|
+
if ident:
|
|
159
|
+
current = ident.group(1)
|
|
160
|
+
stop = re.search(r'stop-color="(#[0-9a-fA-F]{6})"', line)
|
|
161
|
+
if stop and current.endswith("Grad") and not current.startswith("logo"):
|
|
162
|
+
stops.append(stop.group(1))
|
|
163
|
+
return stops
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def text_color_pairs() -> list[tuple[str, str, str, float]]:
|
|
167
|
+
"""All (style, foreground, background, ratio) text pairs the renderer emits."""
|
|
168
|
+
pairs: list[tuple[str, str, str, float]] = []
|
|
169
|
+
for name, attrs in TEXT_STYLES.items():
|
|
170
|
+
match = re.search(r'fill="(#[0-9a-fA-F]{6})"', attrs)
|
|
171
|
+
if match is None:
|
|
172
|
+
continue
|
|
173
|
+
fg = match.group(1)
|
|
174
|
+
backgrounds = (
|
|
175
|
+
chip_gradient_stops() if fg.lower() == CHIP_TEXT_FILL else list(PAGE_BACKGROUNDS)
|
|
176
|
+
)
|
|
177
|
+
pairs.extend((name, fg, bg, contrast_ratio(fg, bg)) for bg in backgrounds)
|
|
178
|
+
return pairs
|