chunkscope 0.2.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.
- chunkscope/__init__.py +31 -0
- chunkscope/__main__.py +3 -0
- chunkscope/adapters.py +378 -0
- chunkscope/align.py +189 -0
- chunkscope/analyze.py +408 -0
- chunkscope/api.py +44 -0
- chunkscope/checks.py +155 -0
- chunkscope/cli.py +143 -0
- chunkscope/colors.py +181 -0
- chunkscope/models.py +152 -0
- chunkscope/py.typed +0 -0
- chunkscope/render.py +710 -0
- chunkscope/tokenizers.py +108 -0
- chunkscope-0.2.0.dist-info/METADATA +227 -0
- chunkscope-0.2.0.dist-info/RECORD +18 -0
- chunkscope-0.2.0.dist-info/WHEEL +4 -0
- chunkscope-0.2.0.dist-info/entry_points.txt +2 -0
- chunkscope-0.2.0.dist-info/licenses/LICENSE +21 -0
chunkscope/render.py
ADDED
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
"""Render a ``Report`` as one self-contained, offline HTML page.
|
|
2
|
+
|
|
3
|
+
The page loads nothing from the network: CSS and JavaScript are inline, and a
|
|
4
|
+
Content-Security-Policy forbids every external request, so chunk text never
|
|
5
|
+
leaves the machine even if the file is opened on another computer.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import html
|
|
11
|
+
import json
|
|
12
|
+
import math
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from . import __version__
|
|
16
|
+
from .analyze import segments
|
|
17
|
+
from .colors import Palette
|
|
18
|
+
from .models import ChunkResult, DocumentResult, Issue, Report
|
|
19
|
+
|
|
20
|
+
e = html.escape
|
|
21
|
+
|
|
22
|
+
CSP = "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:"
|
|
23
|
+
_SEVERITY_LABEL = {"error": "✕ error", "warning": "▲ warning", "info": "ℹ info"}
|
|
24
|
+
_SEVERITY_ORDER = {"error": 0, "warning": 1, "info": 2}
|
|
25
|
+
_STATUS_HELP = {
|
|
26
|
+
"exact": "found exactly in the source",
|
|
27
|
+
"normalized": "found when ignoring whitespace differences",
|
|
28
|
+
"partial": "only part of the text was found; the chunker transformed it",
|
|
29
|
+
"unmatched": "not found in the source",
|
|
30
|
+
"no_source": "no source text to place it in",
|
|
31
|
+
}
|
|
32
|
+
_METADATA_VALUE_LIMIT = 400
|
|
33
|
+
_LANE_HEIGHT = 11 # px per row of the chunk map
|
|
34
|
+
_MAX_LANES = 6
|
|
35
|
+
_TOP_RETRIEVED = 10
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def render_html(report: Report) -> str:
|
|
39
|
+
"""Return the complete HTML page for a report."""
|
|
40
|
+
palette = Palette(report)
|
|
41
|
+
nav = _nav(report)
|
|
42
|
+
views = [_overview(report)] + [_document_view(report, palette, number, doc) for number, doc in enumerate(report.documents)]
|
|
43
|
+
theme = f' data-theme="{e(report.theme)}"' if report.theme != "auto" else ""
|
|
44
|
+
return (
|
|
45
|
+
f"<!doctype html><html lang=\"en\"{theme}><head><meta charset=\"utf-8\">"
|
|
46
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">'
|
|
47
|
+
f'<meta http-equiv="Content-Security-Policy" content="{CSP}">'
|
|
48
|
+
'<meta name="referrer" content="no-referrer">'
|
|
49
|
+
f"<title>{e(report.title)}</title><style>{CSS}{palette.css()}</style></head><body data-color=\"{palette.initial()}\">"
|
|
50
|
+
f'<div class="layout">{nav}<main>{"".join(views)}</main></div>'
|
|
51
|
+
'<aside id="drawer" hidden><button type="button" class="close" aria-label="Close">×</button><div class="body"></div></aside>'
|
|
52
|
+
f"<script>{JS}</script></body></html>"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def render_notebook(report: Report, height: int = 720) -> str:
|
|
57
|
+
"""Embed the report in an iframe for Jupyter (isolated from the notebook's own styles)."""
|
|
58
|
+
page = render_html(report)
|
|
59
|
+
return (
|
|
60
|
+
f'<iframe srcdoc="{html.escape(page, quote=True)}" sandbox="allow-scripts" '
|
|
61
|
+
f'style="width:100%;height:{height}px;border:1px solid #ddd;border-radius:8px"></iframe>'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# ── Layout pieces ─────────────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _nav(report: Report) -> str:
|
|
69
|
+
links = []
|
|
70
|
+
current_run = None
|
|
71
|
+
for number, doc in enumerate(report.documents):
|
|
72
|
+
if report.runs and doc.run != current_run:
|
|
73
|
+
current_run = doc.run
|
|
74
|
+
links.append(f'<div class="group">Run: {e(str(doc.run))}</div>')
|
|
75
|
+
flagged = sum(1 for issue in doc.all_issues if issue.severity != "info")
|
|
76
|
+
flag = f'<span class="flag" title="{flagged} errors or warnings">▲ {flagged}</span>' if flagged else ""
|
|
77
|
+
links.append(
|
|
78
|
+
f'<a class="file" data-view="d{number}" href="#d{number}"><span class="name">{e(doc.title)}</span>'
|
|
79
|
+
f'{flag}<span class="count">{len(doc.chunks)}</span></a>'
|
|
80
|
+
)
|
|
81
|
+
heading = "" if report.runs else f'<div class="group">Documents ({len(report.documents)})</div>'
|
|
82
|
+
return (
|
|
83
|
+
f'<nav><div class="brand">{e(report.title)}<small>chunkscope {__version__} · offline report</small>'
|
|
84
|
+
'<button type="button" class="theme" title="Switch between automatic, light and dark theme">Theme: auto</button></div>'
|
|
85
|
+
'<a class="file" data-view="overview" href="#overview">Overview</a>'
|
|
86
|
+
f'{heading}{"".join(links)}</nav>'
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _overview(report: Report) -> str:
|
|
91
|
+
summary = report.summary()
|
|
92
|
+
unit = report.size_unit
|
|
93
|
+
tiles = [
|
|
94
|
+
("documents", summary["documents"]),
|
|
95
|
+
("chunks", summary["chunks"]),
|
|
96
|
+
(f"median {unit}", _number(summary["median_size"])),
|
|
97
|
+
(f"min – max {unit}", f'{summary["min_size"]} – {summary["max_size"]}'),
|
|
98
|
+
]
|
|
99
|
+
if report.max_size:
|
|
100
|
+
tiles.append((f"over {report.max_size}", summary["over_limit"]))
|
|
101
|
+
if summary["coverage"] is not None:
|
|
102
|
+
tiles.append(("lowest coverage", f'{summary["coverage"]:.1%}'))
|
|
103
|
+
tiles.append(("errors · warnings", f'{summary["errors"]} · {summary["warnings"]}'))
|
|
104
|
+
|
|
105
|
+
sources = ", ".join(report.frameworks) or "none"
|
|
106
|
+
parts = [
|
|
107
|
+
'<section class="view" id="v-overview">',
|
|
108
|
+
f"<h1>{e(report.title)}</h1>",
|
|
109
|
+
f'<div class="sub">Chunk format: {e(sources)} · sizes in {e(unit)}'
|
|
110
|
+
+ (f" · limit {report.max_size}" if report.max_size else "")
|
|
111
|
+
+ "</div>",
|
|
112
|
+
_tiles(tiles),
|
|
113
|
+
]
|
|
114
|
+
sizes = [chunk.size for chunk in report.chunks]
|
|
115
|
+
if len(sizes) >= 2:
|
|
116
|
+
parts.append('<h2>Chunk size distribution</h2>' + _histogram(sizes, unit, report.max_size))
|
|
117
|
+
|
|
118
|
+
if any(chunk.score is not None for chunk in report.chunks):
|
|
119
|
+
parts.append(_retrieval(report))
|
|
120
|
+
if report.runs:
|
|
121
|
+
parts.append("<h2>Runs</h2>" + _runs_table(report))
|
|
122
|
+
parts.append("<h2>Documents</h2>" + _documents_table(report))
|
|
123
|
+
parts.append("<h2>Issues by type</h2>" + _issue_summary(report))
|
|
124
|
+
parts.append("</section>")
|
|
125
|
+
return "".join(parts)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _retrieval(report: Report) -> str:
|
|
129
|
+
ranked = sorted((c for c in report.chunks if c.rank is not None), key=lambda c: c.rank) # type: ignore[arg-type, return-value]
|
|
130
|
+
where = {id(chunk): (number, doc) for number, doc in enumerate(report.documents) for chunk in doc.chunks}
|
|
131
|
+
rows = []
|
|
132
|
+
for chunk in ranked[:_TOP_RETRIEVED]:
|
|
133
|
+
number, doc = where[id(chunk)]
|
|
134
|
+
preview = " ".join(chunk.chunk.text.split())
|
|
135
|
+
preview = preview if len(preview) <= 140 else preview[:139] + "…"
|
|
136
|
+
target = f"#d{number}:c{chunk.index}" if chunk.located else f"#d{number}:chunks:c{chunk.index}"
|
|
137
|
+
rows.append(
|
|
138
|
+
f'<tr><td class="num">{chunk.rank}</td><td class="num">{chunk.score:.4g}</td>'
|
|
139
|
+
f'<td><a href="{target}">{e(doc.title)} #{chunk.index}</a>{_run_tag(doc)}</td><td class="preview">{e(preview)}</td></tr>'
|
|
140
|
+
)
|
|
141
|
+
query = f'<p class="query">Query: <q>{e(report.query)}</q></p>' if report.query else ""
|
|
142
|
+
more = len(ranked) - _TOP_RETRIEVED
|
|
143
|
+
note = f'<p class="sub">{more} more scored chunk(s). Colour by "Retrieval score" to see them all in context.</p>' if more > 0 else ""
|
|
144
|
+
return (
|
|
145
|
+
f'<h2>Retrieval</h2>{query}<div class="scroll"><table class="grid"><thead><tr><th class="num">Rank</th>'
|
|
146
|
+
f'<th class="num">Score</th><th>Chunk</th><th>Text</th></tr></thead><tbody>{"".join(rows)}</tbody></table></div>{note}'
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _runs_table(report: Report) -> str:
|
|
151
|
+
rows = []
|
|
152
|
+
for run in report.runs:
|
|
153
|
+
docs = [doc for doc in report.documents if doc.run == run]
|
|
154
|
+
sizes = sorted(chunk.size for doc in docs for chunk in doc.chunks)
|
|
155
|
+
counts = _severity_counts([issue for doc in docs for issue in doc.all_issues])
|
|
156
|
+
coverages = [doc.coverage for doc in docs if doc.coverage is not None]
|
|
157
|
+
over = sum(size > report.max_size for size in sizes) if report.max_size else None
|
|
158
|
+
first = report.documents.index(docs[0]) if docs else 0
|
|
159
|
+
rows.append(
|
|
160
|
+
f'<tr><td><a href="#d{first}">{e(run)}</a></td><td class="num">{len(sizes)}</td>'
|
|
161
|
+
f'<td class="num">{_number(_median(sizes)) if sizes else "–"}</td><td class="num">{sizes[-1] if sizes else "–"}</td>'
|
|
162
|
+
f'<td class="num">{"–" if over is None else over}</td>'
|
|
163
|
+
f'<td class="num">{f"{min(coverages):.1%}" if coverages else "–"}</td>'
|
|
164
|
+
f'<td class="num">{counts["error"] or ""}</td><td class="num">{counts["warning"] or ""}</td></tr>'
|
|
165
|
+
)
|
|
166
|
+
unit = e(report.size_unit)
|
|
167
|
+
return (
|
|
168
|
+
'<div class="scroll"><table class="grid"><thead><tr><th>Run</th><th class="num">Chunks</th>'
|
|
169
|
+
f'<th class="num">Median {unit}</th><th class="num">Max</th><th class="num">Over limit</th>'
|
|
170
|
+
'<th class="num">Lowest coverage</th><th class="num">Errors</th><th class="num">Warnings</th></tr></thead>'
|
|
171
|
+
f'<tbody>{"".join(rows)}</tbody></table></div>'
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _documents_table(report: Report) -> str:
|
|
176
|
+
rows = []
|
|
177
|
+
for number, doc in enumerate(report.documents):
|
|
178
|
+
sizes = sorted(chunk.size for chunk in doc.chunks)
|
|
179
|
+
median = _number(_median(sizes)) if sizes else "–"
|
|
180
|
+
biggest = sizes[-1] if sizes else 0
|
|
181
|
+
level = _size_level(biggest, report)
|
|
182
|
+
counts = _severity_counts(doc.all_issues)
|
|
183
|
+
coverage = f"{doc.coverage:.1%}" if doc.coverage is not None else "–"
|
|
184
|
+
placed = sum(1 for chunk in doc.chunks if chunk.located)
|
|
185
|
+
rows.append(
|
|
186
|
+
f'<tr><td><a href="#d{number}">{e(doc.title)}</a>{_run_tag(doc)}</td><td class="num">{len(doc.chunks)}</td>'
|
|
187
|
+
f'<td class="num">{placed}</td><td class="num">{median}</td>'
|
|
188
|
+
f'<td class="num">{_pill(str(biggest), level) if sizes else "–"}</td><td class="num">{coverage}</td>'
|
|
189
|
+
f'<td class="num">{counts["error"] or ""}</td><td class="num">{counts["warning"] or ""}</td></tr>'
|
|
190
|
+
)
|
|
191
|
+
return (
|
|
192
|
+
'<div class="scroll"><table class="grid"><thead><tr><th>Document</th><th class="num">Chunks</th>'
|
|
193
|
+
f'<th class="num">Placed</th><th class="num">Median {e(report.size_unit)}</th><th class="num">Max</th>'
|
|
194
|
+
'<th class="num">Coverage</th><th class="num">Errors</th><th class="num">Warnings</th></tr></thead>'
|
|
195
|
+
f'<tbody>{"".join(rows)}</tbody></table></div>'
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _issue_summary(report: Report) -> str:
|
|
200
|
+
groups: dict[str, list[Issue]] = {}
|
|
201
|
+
for issue in report.issues:
|
|
202
|
+
groups.setdefault(issue.code, []).append(issue)
|
|
203
|
+
if not groups:
|
|
204
|
+
return '<p class="sub">No issues found.</p>'
|
|
205
|
+
ordered = sorted(groups.items(), key=lambda item: (_SEVERITY_ORDER[item[1][0].severity], -len(item[1])))
|
|
206
|
+
rows = "".join(
|
|
207
|
+
f'<tr><td>{_severity_pill(items[0].severity)}</td><td><code>{e(code)}</code></td>'
|
|
208
|
+
f'<td class="num">{len(items)}</td><td>{e(items[0].message)}</td></tr>'
|
|
209
|
+
for code, items in ordered
|
|
210
|
+
)
|
|
211
|
+
return (
|
|
212
|
+
'<div class="scroll"><table class="grid"><thead><tr><th>Severity</th><th>Check</th><th class="num">Count</th>'
|
|
213
|
+
f'<th>Example</th></tr></thead><tbody>{rows}</tbody></table></div>'
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _run_tag(doc: DocumentResult) -> str:
|
|
218
|
+
return f' <span class="pill">{e(doc.run)}</span>' if doc.run is not None else ""
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _siblings(report: Report, doc: DocumentResult) -> list[tuple[int, DocumentResult]]:
|
|
222
|
+
"""The same document in every run (for the Compare tab)."""
|
|
223
|
+
if not report.runs:
|
|
224
|
+
return []
|
|
225
|
+
found = [(n, d) for n, d in enumerate(report.documents) if d.id == doc.id and d.text is not None]
|
|
226
|
+
return found if len(found) > 1 else []
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _document_view(report: Report, palette: Palette, number: int, doc: DocumentResult) -> str:
|
|
230
|
+
sizes = sorted(chunk.size for chunk in doc.chunks)
|
|
231
|
+
unit = report.size_unit
|
|
232
|
+
tiles = [
|
|
233
|
+
("chunks", len(doc.chunks)),
|
|
234
|
+
(f"median {unit}", _number(_median(sizes)) if sizes else "–"),
|
|
235
|
+
(f"max {unit}", sizes[-1] if sizes else "–"),
|
|
236
|
+
]
|
|
237
|
+
if doc.coverage is not None:
|
|
238
|
+
tiles.append(("coverage", f"{doc.coverage:.1%}"))
|
|
239
|
+
tiles.append(("overlapping regions", len(doc.overlaps)))
|
|
240
|
+
counts = _severity_counts(doc.all_issues)
|
|
241
|
+
tiles.append(("errors · warnings", f'{counts["error"]} · {counts["warning"]}'))
|
|
242
|
+
|
|
243
|
+
has_source = doc.text is not None
|
|
244
|
+
siblings = _siblings(report, doc)
|
|
245
|
+
tabs = ([("source", "Source")] if has_source else []) + [
|
|
246
|
+
("chunks", f"Chunks ({len(doc.chunks)})"),
|
|
247
|
+
("issues", f"Issues ({len(doc.all_issues)})"),
|
|
248
|
+
] + ([("compare", f"Compare runs ({len(siblings)})")] if siblings else [])
|
|
249
|
+
tab_links = "".join(f'<a data-tab="{key}" href="#d{number}:{key}">{label}</a>' for key, label in tabs)
|
|
250
|
+
panes = []
|
|
251
|
+
if has_source:
|
|
252
|
+
panes.append(f'<div class="pane" data-tab="source">{_source_pane(palette, number, doc)}</div>')
|
|
253
|
+
panes.append(f'<div class="pane" data-tab="chunks">{_chunks_pane(report, number, doc)}</div>')
|
|
254
|
+
panes.append(f'<div class="pane" data-tab="issues">{_issues_pane(number, doc)}</div>')
|
|
255
|
+
if siblings:
|
|
256
|
+
panes.append(f'<div class="pane" data-tab="compare">{_compare_pane(report, palette, number, siblings)}</div>')
|
|
257
|
+
return (
|
|
258
|
+
f'<section class="view" id="v-d{number}" data-default="{tabs[0][0]}" hidden>'
|
|
259
|
+
f'<h1>{e(doc.title)}{_run_tag(doc)}</h1>'
|
|
260
|
+
+ (f'<div class="sub">{e(doc.id)}</div>' if doc.id != doc.title else "")
|
|
261
|
+
+ _tiles(tiles)
|
|
262
|
+
+ f'<div class="tabs">{tab_links}</div>{_colorbar(palette) if has_source else ""}{"".join(panes)}</section>'
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _colorbar(palette: Palette) -> str:
|
|
267
|
+
options = "".join(f'<option value="{mode}">{e(label)}</option>' for mode, label in palette.modes())
|
|
268
|
+
return (
|
|
269
|
+
f'<div class="colorbar"><label>Colour by <select class="color-select">{options}</select></label>'
|
|
270
|
+
f'<div class="legends">{palette.legends()}</div></div>'
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _chunk_map(palette: Palette, number: int, doc: DocumentResult) -> str:
|
|
275
|
+
"""Bird's-eye view: every placed chunk as a bar along the document, overlaps on extra rows."""
|
|
276
|
+
length = len(doc.text or "")
|
|
277
|
+
placed = sorted((c for c in doc.chunks if c.located and c.end > c.start), key=lambda c: (c.start, -c.end)) # type: ignore[operator]
|
|
278
|
+
if not length or not placed:
|
|
279
|
+
return ""
|
|
280
|
+
lanes: list[int] = []
|
|
281
|
+
bars = []
|
|
282
|
+
for chunk in placed:
|
|
283
|
+
lane = next((i for i, end in enumerate(lanes) if end <= chunk.start), None) # type: ignore[operator]
|
|
284
|
+
if lane is None:
|
|
285
|
+
lane = min(len(lanes), _MAX_LANES - 1)
|
|
286
|
+
if lane == len(lanes):
|
|
287
|
+
lanes.append(0)
|
|
288
|
+
lanes[lane] = max(lanes[lane], chunk.end) # type: ignore[type-var]
|
|
289
|
+
left = chunk.start / length * 100 # type: ignore[operator]
|
|
290
|
+
width = max((chunk.end - chunk.start) / length * 100, 0.25) # type: ignore[operator]
|
|
291
|
+
score = f" · score {chunk.score:.3g}" if chunk.score is not None else ""
|
|
292
|
+
bars.append(
|
|
293
|
+
f'<a class="cmb {palette.classes(chunk)}" href="#d{number}:c{chunk.index}" '
|
|
294
|
+
f'style="left:{left:.3f}%;width:{width:.3f}%;top:{lane * _LANE_HEIGHT}px" '
|
|
295
|
+
f'title="#{chunk.index} · {chunk.size}{score}"></a>'
|
|
296
|
+
)
|
|
297
|
+
gap_top = len(lanes) * _LANE_HEIGHT + 2
|
|
298
|
+
for start, end in doc.gaps:
|
|
299
|
+
bars.append(
|
|
300
|
+
f'<span class="cmg" style="left:{start / length * 100:.3f}%;width:{max((end - start) / length * 100, 0.2):.3f}%;top:{gap_top}px" '
|
|
301
|
+
f'title="gap: characters {start}–{end}"></span>'
|
|
302
|
+
)
|
|
303
|
+
height = gap_top + (6 if doc.gaps else 0)
|
|
304
|
+
return f'<div class="cm" style="height:{height}px" aria-label="Chunk map">{"".join(bars)}</div>'
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _compare_pane(report: Report, palette: Palette, number: int, siblings: list[tuple[int, DocumentResult]]) -> str:
|
|
308
|
+
rows = []
|
|
309
|
+
for other_number, other in siblings:
|
|
310
|
+
sizes = sorted(chunk.size for chunk in other.chunks)
|
|
311
|
+
counts = _severity_counts(other.all_issues)
|
|
312
|
+
current = " (this run)" if other_number == number else ""
|
|
313
|
+
stats = (
|
|
314
|
+
f"{len(other.chunks)} chunks · median {_number(_median(sizes)) if sizes else '–'} · max {sizes[-1] if sizes else '–'} {e(report.size_unit)}"
|
|
315
|
+
f" · coverage {f'{other.coverage:.1%}' if other.coverage is not None else '–'}"
|
|
316
|
+
f" · {counts['error']} errors · {counts['warning']} warnings"
|
|
317
|
+
)
|
|
318
|
+
rows.append(
|
|
319
|
+
f'<div class="cmp"><div class="cmp-head"><a href="#d{other_number}"><b>{e(str(other.run))}</b></a>{current}'
|
|
320
|
+
f'<span class="muted">{stats}</span></div>{_chunk_map(palette, other_number, other)}</div>'
|
|
321
|
+
)
|
|
322
|
+
return (
|
|
323
|
+
'<p class="sub">The same document in every run, on the same scale. Click a bar to open that chunk.</p>'
|
|
324
|
+
+ "".join(rows)
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def _source_pane(palette: Palette, number: int, doc: DocumentResult) -> str:
|
|
329
|
+
text = doc.text or ""
|
|
330
|
+
classes_of = {chunk.index: palette.classes(chunk) for chunk in doc.chunks}
|
|
331
|
+
by_start: dict[int, list[ChunkResult]] = {}
|
|
332
|
+
for chunk in doc.chunks:
|
|
333
|
+
if chunk.located:
|
|
334
|
+
by_start.setdefault(chunk.start, []).append(chunk) # type: ignore[arg-type]
|
|
335
|
+
partial = {chunk.index for chunk in doc.chunks if chunk.status == "partial"}
|
|
336
|
+
|
|
337
|
+
out = []
|
|
338
|
+
for start, end, active in segments(doc):
|
|
339
|
+
for chunk in by_start.pop(start, []):
|
|
340
|
+
out.append(f'<a class="mk" href="#d{number}:c{chunk.index}" title="chunk #{chunk.index}">#{chunk.index}</a>')
|
|
341
|
+
piece = e(text[start:end])
|
|
342
|
+
if not active:
|
|
343
|
+
if piece.strip():
|
|
344
|
+
out.append(f'<span class="gap" title="not in any chunk">{piece}</span>')
|
|
345
|
+
else:
|
|
346
|
+
out.append(piece)
|
|
347
|
+
continue
|
|
348
|
+
classes = ["seg", classes_of[active[0]]]
|
|
349
|
+
if len(active) > 1: # overlap: drawn in the colours of the first two chunks, top and bottom
|
|
350
|
+
classes.extend(("ov", f"o{active[1] % 4}"))
|
|
351
|
+
if any(index in partial for index in active):
|
|
352
|
+
classes.append("pt")
|
|
353
|
+
label = ", ".join(f"#{index}" for index in active)
|
|
354
|
+
out.append(f'<span class="{" ".join(classes)}" data-c="{" ".join(map(str, active))}" title="chunk {label}">{piece}</span>')
|
|
355
|
+
|
|
356
|
+
unplaced = [chunk for chunk in doc.chunks if not chunk.located]
|
|
357
|
+
note = ""
|
|
358
|
+
if unplaced:
|
|
359
|
+
links = ", ".join(f'<a href="#d{number}:chunks:c{c.index}">#{c.index}</a>' for c in unplaced[:50])
|
|
360
|
+
more = f" and {len(unplaced) - 50} more" if len(unplaced) > 50 else ""
|
|
361
|
+
note = f'<p class="note">{len(unplaced)} chunk(s) could not be placed in the source: {links}{more}.</p>'
|
|
362
|
+
legend = (
|
|
363
|
+
'<div class="legend"><span><b class="mk">#n</b> where a chunk starts</span><span><i class="sw ovs"></i>overlap: text in 2+ chunks, dashed (top half: earlier chunk, bottom half: next chunk)</span>'
|
|
364
|
+
'<span><i class="sw gaps"></i>gap: in no chunk</span><span><i class="sw pts"></i>partial match</span>'
|
|
365
|
+
"<span>Click text or a bar to inspect its chunk</span></div>"
|
|
366
|
+
)
|
|
367
|
+
return f'{_chunk_map(palette, number, doc)}{legend}{note}<div class="src" data-doc="{number}">{"".join(out)}</div>'
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _chunks_pane(report: Report, number: int, doc: DocumentResult) -> str:
|
|
371
|
+
if not doc.chunks:
|
|
372
|
+
return '<p class="sub">No chunks.</p>'
|
|
373
|
+
sort = ""
|
|
374
|
+
if any(chunk.score is not None for chunk in doc.chunks):
|
|
375
|
+
sort = '<label>Order <select class="sort-cards"><option value="index">document order</option><option value="rank">retrieval rank</option></select></label>'
|
|
376
|
+
toolbar = (
|
|
377
|
+
f'<div class="toolbar"><label><input type="checkbox" class="only-issues"> Show only chunks with errors or warnings</label>{sort}</div>'
|
|
378
|
+
)
|
|
379
|
+
cards = "".join(_card(report, number, chunk) for chunk in doc.chunks)
|
|
380
|
+
return f'{toolbar}<div class="cards">{cards}</div>'
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _card(report: Report, number: int, chunk: ChunkResult) -> str:
|
|
384
|
+
level = _size_level(chunk.size, report)
|
|
385
|
+
flagged = any(issue.severity != "info" for issue in chunk.issues)
|
|
386
|
+
head = [f'<span class="cid">#{chunk.index}</span>', _status_pill(chunk.status), _pill(f"{chunk.size} {report.size_unit}", level)]
|
|
387
|
+
if chunk.score is not None:
|
|
388
|
+
head.append(f'<span class="pill score" title="retrieval score">rank {chunk.rank} · score {chunk.score:.4g}</span>')
|
|
389
|
+
if report.max_size:
|
|
390
|
+
head.append(_bar(chunk.size, report.max_size, level))
|
|
391
|
+
if chunk.located:
|
|
392
|
+
head.append(f'<span class="muted">chars {chunk.start}–{chunk.end}</span>')
|
|
393
|
+
if chunk.located and chunk.status != "unmatched":
|
|
394
|
+
head.append(f'<a class="goto" href="#d{number}:c{chunk.index}">show in source</a>')
|
|
395
|
+
issues = ""
|
|
396
|
+
if chunk.issues:
|
|
397
|
+
items = "".join(f"<li>{_severity_pill(i.severity)} {e(i.message)}</li>" for i in chunk.issues)
|
|
398
|
+
issues = f'<ul class="issues">{items}</ul>'
|
|
399
|
+
meta = _metadata(chunk)
|
|
400
|
+
return (
|
|
401
|
+
f'<article class="card" id="d{number}-c{chunk.index}" data-flagged="{int(flagged)}" data-index="{chunk.index}" data-rank="{chunk.rank or 0}">'
|
|
402
|
+
f'<div class="head">{"".join(head)}</div>{issues}{meta}<pre>{e(chunk.chunk.text)}</pre></article>'
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def _metadata(chunk: ChunkResult) -> str:
|
|
407
|
+
fields: dict[str, Any] = {}
|
|
408
|
+
if chunk.chunk.id is not None:
|
|
409
|
+
fields["id"] = chunk.chunk.id
|
|
410
|
+
if chunk.chunk.parent_id is not None:
|
|
411
|
+
fields["parent_id"] = chunk.chunk.parent_id
|
|
412
|
+
if chunk.chunk.doc_id is not None:
|
|
413
|
+
fields["doc_id"] = chunk.chunk.doc_id
|
|
414
|
+
if chunk.chunk.start is not None:
|
|
415
|
+
fields["offsets (given)"] = f"{chunk.chunk.start}–{chunk.chunk.end if chunk.chunk.end is not None else '?'}"
|
|
416
|
+
fields.update(chunk.chunk.metadata)
|
|
417
|
+
if not fields:
|
|
418
|
+
return ""
|
|
419
|
+
rows = "".join(f"<tr><th>{e(str(key))}</th><td>{e(_short(value))}</td></tr>" for key, value in fields.items())
|
|
420
|
+
return f'<details class="meta"><summary>Metadata ({len(fields)})</summary><table>{rows}</table></details>'
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def _issues_pane(number: int, doc: DocumentResult) -> str:
|
|
424
|
+
issues = sorted(doc.all_issues, key=lambda i: (_SEVERITY_ORDER[i.severity], -1 if i.chunk is None else i.chunk))
|
|
425
|
+
if not issues:
|
|
426
|
+
return '<p class="sub">No issues found.</p>'
|
|
427
|
+
rows = []
|
|
428
|
+
for issue in issues:
|
|
429
|
+
where = "document" if issue.chunk is None else f'<a href="#d{number}:chunks:c{issue.chunk}">#{issue.chunk}</a>'
|
|
430
|
+
rows.append(
|
|
431
|
+
f"<tr><td>{_severity_pill(issue.severity)}</td><td>{where}</td><td><code>{e(issue.code)}</code></td>"
|
|
432
|
+
f"<td>{e(issue.message)}</td></tr>"
|
|
433
|
+
)
|
|
434
|
+
return (
|
|
435
|
+
'<div class="scroll"><table class="grid"><thead><tr><th>Severity</th><th>Where</th><th>Check</th>'
|
|
436
|
+
f'<th>Message</th></tr></thead><tbody>{"".join(rows)}</tbody></table></div>'
|
|
437
|
+
)
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
# ── Small components ──────────────────────────────────────────────────────────
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def _tiles(pairs: list[tuple[str, Any]]) -> str:
|
|
444
|
+
return '<div class="tiles">' + "".join(f'<div class="tile"><b>{e(str(v))}</b><span>{e(k)}</span></div>' for k, v in pairs) + "</div>"
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
def _pill(text: str, level: str = "") -> str:
|
|
448
|
+
return f'<span class="pill {level}">{e(text)}</span>'
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def _severity_pill(severity: str) -> str:
|
|
452
|
+
return f'<span class="pill sev-{severity}">{_SEVERITY_LABEL[severity]}</span>'
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def _status_pill(status: str) -> str:
|
|
456
|
+
level = {"unmatched": "warn", "partial": "info"}.get(status, "")
|
|
457
|
+
return f'<span class="pill {level}" title="{e(_STATUS_HELP[status])}">{e(status.replace("_", " "))}</span>'
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def _bar(size: int, limit: int, level: str) -> str:
|
|
461
|
+
width = min(size / limit, 1) * 100
|
|
462
|
+
return f'<span class="bar" title="{size} of {limit}"><i class="{level}" style="width:{width:.1f}%"></i></span>'
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def _size_level(size: int, report: Report) -> str:
|
|
466
|
+
if report.max_size is not None and size > report.max_size:
|
|
467
|
+
return "over"
|
|
468
|
+
if report.min_size is not None and size < report.min_size:
|
|
469
|
+
return "warn"
|
|
470
|
+
return ""
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _severity_counts(issues: list[Issue]) -> dict[str, int]:
|
|
474
|
+
counts = {"error": 0, "warning": 0, "info": 0}
|
|
475
|
+
for issue in issues:
|
|
476
|
+
counts[issue.severity] += 1
|
|
477
|
+
return counts
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def _histogram(sizes: list[int], unit: str, limit: int | None) -> str:
|
|
481
|
+
"""Single-series histogram as inline SVG; bins over the limit use the 'over' status colour."""
|
|
482
|
+
top = max(max(sizes), limit or 0)
|
|
483
|
+
bins = 24
|
|
484
|
+
width_per_bin = max(1, math.ceil((top + 1) / bins))
|
|
485
|
+
bins = math.ceil((top + 1) / width_per_bin)
|
|
486
|
+
counts = [0] * bins
|
|
487
|
+
for size in sizes:
|
|
488
|
+
counts[min(size // width_per_bin, bins - 1)] += 1
|
|
489
|
+
peak = max(counts)
|
|
490
|
+
|
|
491
|
+
w, h, left, bottom, top_pad = 720, 200, 40, 28, 26
|
|
492
|
+
plot_w, plot_h = w - left - 12, h - bottom - top_pad
|
|
493
|
+
step = plot_w / bins
|
|
494
|
+
bars = []
|
|
495
|
+
for number, count in enumerate(counts):
|
|
496
|
+
if not count:
|
|
497
|
+
continue
|
|
498
|
+
low, high = number * width_per_bin, (number + 1) * width_per_bin - 1
|
|
499
|
+
bar_h = max(2.0, count / peak * plot_h)
|
|
500
|
+
x, y = left + number * step + 1, top_pad + plot_h - bar_h
|
|
501
|
+
bw = max(1.0, step - 2)
|
|
502
|
+
r = min(4.0, bw / 2, bar_h)
|
|
503
|
+
over = limit is not None and low > limit
|
|
504
|
+
path = f"M{x:.1f},{y + bar_h:.1f}V{y + r:.1f}Q{x:.1f},{y:.1f} {x + r:.1f},{y:.1f}H{x + bw - r:.1f}Q{x + bw:.1f},{y:.1f} {x + bw:.1f},{y + r:.1f}V{y + bar_h:.1f}Z"
|
|
505
|
+
label = f"{low}–{high} {unit}: {count} chunk{'s' if count != 1 else ''}" + (" (over the limit)" if over else "")
|
|
506
|
+
bars.append(f'<path class="hb{" over" if over else ""}" d="{path}"><title>{e(label)}</title></path>')
|
|
507
|
+
|
|
508
|
+
axis_y = top_pad + plot_h
|
|
509
|
+
parts = [
|
|
510
|
+
f'<svg class="hist" viewBox="0 0 {w} {h}" role="img" aria-label="Histogram of chunk sizes in {e(unit)}">',
|
|
511
|
+
f'<line class="axis" x1="{left}" y1="{axis_y}" x2="{w - 12}" y2="{axis_y}"/>',
|
|
512
|
+
f'<text class="tick" x="{left - 6}" y="{top_pad + 4}" text-anchor="end">{peak}</text>',
|
|
513
|
+
f'<text class="tick" x="{left - 6}" y="{axis_y}" text-anchor="end">0</text>',
|
|
514
|
+
f'<text class="tick" x="{left}" y="{h - 8}">0</text>',
|
|
515
|
+
f'<text class="tick" x="{w - 12}" y="{h - 8}" text-anchor="end">{bins * width_per_bin} {e(unit)}</text>',
|
|
516
|
+
*bars,
|
|
517
|
+
]
|
|
518
|
+
if limit is not None:
|
|
519
|
+
lx = left + (limit + 1) / width_per_bin * step
|
|
520
|
+
parts.append(f'<line class="limit" x1="{lx:.1f}" y1="{top_pad}" x2="{lx:.1f}" y2="{axis_y}"/>')
|
|
521
|
+
parts.append(f'<text class="tick" x="{lx:.1f}" y="{top_pad - 10}" text-anchor="middle">limit {limit}</text>')
|
|
522
|
+
parts.append("</svg>")
|
|
523
|
+
legend = ""
|
|
524
|
+
if limit is not None:
|
|
525
|
+
legend = '<div class="legend"><span><i class="sw hbs"></i>chunks per size range</span><span><i class="sw overs"></i>✕ over the limit</span></div>'
|
|
526
|
+
return legend + "".join(parts)
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def _median(values: list[int]) -> float:
|
|
530
|
+
if not values:
|
|
531
|
+
return 0
|
|
532
|
+
middle = len(values) // 2
|
|
533
|
+
return values[middle] if len(values) % 2 else (values[middle - 1] + values[middle]) / 2
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def _number(value: float) -> str:
|
|
537
|
+
return str(int(value)) if float(value).is_integer() else f"{value:.1f}"
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
def _short(value: Any) -> str:
|
|
541
|
+
if isinstance(value, str):
|
|
542
|
+
text = value
|
|
543
|
+
else:
|
|
544
|
+
try:
|
|
545
|
+
text = json.dumps(value, ensure_ascii=False, default=str)
|
|
546
|
+
except (TypeError, ValueError):
|
|
547
|
+
text = repr(value)
|
|
548
|
+
return text if len(text) <= _METADATA_VALUE_LIMIT else text[:_METADATA_VALUE_LIMIT] + "…"
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
# ── Assets ────────────────────────────────────────────────────────────────────
|
|
552
|
+
|
|
553
|
+
CSS = """
|
|
554
|
+
:root{--bg:#fbfaf7;--panel:#fff;--ink:#1f2328;--muted:#5f6670;--line:#e4e1da;--accent:#2f6fde;--code:#f2f0eb;
|
|
555
|
+
--over:#c4372d;--warn:#a86a00;--info:#2f6fde;
|
|
556
|
+
--k0:rgba(47,111,222,.13);--k0b:#2f6fde;--k1:rgba(30,150,90,.14);--k1b:#1e965a;--k2:rgba(132,84,214,.13);--k2b:#8454d6;--k3:rgba(0,150,170,.14);--k3b:#0096aa;
|
|
557
|
+
--k0s:rgba(47,111,222,.42);--k1s:rgba(30,150,90,.42);--k2s:rgba(132,84,214,.42);--k3s:rgba(0,150,170,.42);--ovl:#1f2328;
|
|
558
|
+
--gap:rgba(196,55,45,.12);--sel:rgba(255,196,0,.45);color-scheme:light dark}
|
|
559
|
+
:root[data-theme="light"]{color-scheme:light}
|
|
560
|
+
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){--bg:#15171b;--panel:#1c1f24;--ink:#e7e7e7;--muted:#a1a8b2;--line:#2d3139;--accent:#7aa7ff;--code:#24272d;
|
|
561
|
+
--over:#ff7a6e;--warn:#e7b04a;--info:#7aa7ff;
|
|
562
|
+
--k0:rgba(122,167,255,.17);--k0b:#7aa7ff;--k1:rgba(90,200,140,.16);--k1b:#5ac88c;--k2:rgba(180,140,255,.17);--k2b:#b48cff;--k3:rgba(60,200,220,.16);--k3b:#3cc8dc;
|
|
563
|
+
--k0s:rgba(122,167,255,.62);--k1s:rgba(90,200,140,.58);--k2s:rgba(180,140,255,.62);--k3s:rgba(60,200,220,.58);--ovl:#f2f2f2;
|
|
564
|
+
--gap:rgba(255,122,110,.16);--sel:rgba(255,200,40,.35)}}
|
|
565
|
+
:root[data-theme="dark"]{color-scheme:dark;--bg:#15171b;--panel:#1c1f24;--ink:#e7e7e7;--muted:#a1a8b2;--line:#2d3139;--accent:#7aa7ff;--code:#24272d;
|
|
566
|
+
--over:#ff7a6e;--warn:#e7b04a;--info:#7aa7ff;
|
|
567
|
+
--k0:rgba(122,167,255,.17);--k0b:#7aa7ff;--k1:rgba(90,200,140,.16);--k1b:#5ac88c;--k2:rgba(180,140,255,.17);--k2b:#b48cff;--k3:rgba(60,200,220,.16);--k3b:#3cc8dc;
|
|
568
|
+
--k0s:rgba(122,167,255,.62);--k1s:rgba(90,200,140,.58);--k2s:rgba(180,140,255,.62);--k3s:rgba(60,200,220,.58);--ovl:#f2f2f2;
|
|
569
|
+
--gap:rgba(255,122,110,.16);--sel:rgba(255,200,40,.35)}
|
|
570
|
+
*{box-sizing:border-box}body{margin:0;font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;background:var(--bg);color:var(--ink)}
|
|
571
|
+
a{color:var(--accent);text-decoration:none}a:hover{text-decoration:underline}
|
|
572
|
+
code{font:12px ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
573
|
+
.layout{display:grid;grid-template-columns:280px minmax(0,1fr);min-height:100vh}
|
|
574
|
+
nav{border-right:1px solid var(--line);padding:16px 0;position:sticky;top:0;height:100vh;overflow:auto;background:var(--panel)}
|
|
575
|
+
nav .brand{padding:0 16px 12px;font-weight:650}nav .brand small{display:block;color:var(--muted);font-weight:400;font-size:12px}
|
|
576
|
+
nav a.file{display:flex;gap:8px;padding:5px 16px;color:var(--ink);font-size:13px;align-items:baseline}
|
|
577
|
+
nav a.file:hover,nav a.file.active{background:var(--k0);text-decoration:none}
|
|
578
|
+
nav .name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
579
|
+
nav .count{margin-left:auto;color:var(--muted);font-size:12px;font-variant-numeric:tabular-nums}
|
|
580
|
+
nav .flag{color:var(--warn);font-size:11px;white-space:nowrap}
|
|
581
|
+
nav .group{padding:14px 16px 4px;color:var(--muted);font-size:11px;text-transform:uppercase;letter-spacing:.06em}
|
|
582
|
+
main{padding:24px 32px 80px;max-width:1240px}
|
|
583
|
+
h1{font-size:22px;margin:0 0 4px;word-break:break-word}h2{font-size:15px;margin:28px 0 10px}.sub{color:var(--muted);margin-bottom:12px}
|
|
584
|
+
.tiles{display:flex;flex-wrap:wrap;gap:10px;margin:12px 0 18px}
|
|
585
|
+
.tile{background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:8px 12px;min-width:112px}
|
|
586
|
+
.tile b{display:block;font-size:18px;font-variant-numeric:tabular-nums}.tile span{color:var(--muted);font-size:12px}
|
|
587
|
+
.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);margin-bottom:14px}
|
|
588
|
+
.tabs a{padding:8px 14px;color:var(--muted);border-bottom:2px solid transparent;margin-bottom:-1px}
|
|
589
|
+
.tabs a.active{color:var(--ink);border-color:var(--accent);font-weight:600}.tabs a:hover{text-decoration:none;color:var(--ink)}
|
|
590
|
+
.scroll{overflow-x:auto}
|
|
591
|
+
table.grid{border-collapse:collapse;width:100%;background:var(--panel);border:1px solid var(--line);border-radius:8px}
|
|
592
|
+
table.grid th,table.grid td{padding:6px 10px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}
|
|
593
|
+
table.grid th{font-size:12px;color:var(--muted);font-weight:600}.num{text-align:right!important;font-variant-numeric:tabular-nums}
|
|
594
|
+
.pill{display:inline-block;font:11px/1.6 -apple-system,sans-serif;padding:0 7px;border-radius:10px;background:var(--code);border:1px solid var(--line);white-space:nowrap}
|
|
595
|
+
.pill.over,.pill.sev-error{color:var(--over);border-color:var(--over)}.pill.warn,.pill.sev-warning{color:var(--warn);border-color:var(--warn)}
|
|
596
|
+
.pill.info,.pill.sev-info{color:var(--info);border-color:var(--info)}
|
|
597
|
+
.muted{color:var(--muted);font-size:12px}
|
|
598
|
+
.bar{display:inline-block;position:relative;height:6px;width:120px;background:var(--code);border-radius:3px;overflow:hidden}
|
|
599
|
+
.bar i{position:absolute;inset:0 auto 0 0;background:var(--muted)}.bar i.over{background:var(--over)}.bar i.warn{background:var(--warn)}
|
|
600
|
+
.legend{display:flex;flex-wrap:wrap;gap:6px 16px;color:var(--muted);font-size:12px;margin:0 0 10px}
|
|
601
|
+
.sw{display:inline-block;width:12px;height:12px;border-radius:2px;margin-right:4px;vertical-align:-2px}
|
|
602
|
+
.sw.k0{background:var(--k0);box-shadow:inset 0 -2px var(--k0b)}.sw.k1{background:var(--k1);box-shadow:inset 0 -2px var(--k1b)}
|
|
603
|
+
.sw.ovs{background:linear-gradient(var(--k0s) 0 50%,var(--k1s) 50% 100%);outline:1px dashed var(--ovl);outline-offset:-1px}
|
|
604
|
+
.sw.gaps{background:var(--gap);box-shadow:inset 0 -2px var(--over)}.sw.pts{box-shadow:inset 0 -2px var(--muted);background:var(--code)}
|
|
605
|
+
.sw.hbs{background:var(--muted)}.sw.overs{background:var(--over)}
|
|
606
|
+
.note{background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:8px 12px;font-size:13px}
|
|
607
|
+
.src{background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:14px 16px;white-space:pre-wrap;word-break:break-word;
|
|
608
|
+
font:12.5px/1.65 ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
609
|
+
.seg{cursor:pointer;border-radius:2px}
|
|
610
|
+
.seg.ov{outline:1px dashed var(--ovl);outline-offset:1px;color:var(--ink)}
|
|
611
|
+
.seg.pt{box-shadow:inset 0 -2px var(--muted)}
|
|
612
|
+
.seg.sel{background:var(--sel)!important;color:var(--ink)!important;box-shadow:inset 0 -2px var(--warn)}
|
|
613
|
+
.gap{background:var(--gap);box-shadow:inset 0 -2px var(--over)}
|
|
614
|
+
.mk{font:10px/1.4 -apple-system,sans-serif;padding:0 4px;margin:0 2px;border-radius:6px;background:var(--ink);color:var(--bg);vertical-align:1px;white-space:nowrap}
|
|
615
|
+
a.mk:hover{text-decoration:none;opacity:.8}b.mk{font-weight:400}
|
|
616
|
+
.toolbar{display:block;margin:0 0 12px;color:var(--muted);font-size:13px}
|
|
617
|
+
.cards.only-flagged .card[data-flagged="0"]{display:none}
|
|
618
|
+
.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;margin:0 0 12px;overflow:hidden;scroll-margin-top:16px}
|
|
619
|
+
.card.hl{outline:2px solid var(--accent)}
|
|
620
|
+
.card .head{padding:8px 12px;border-bottom:1px solid var(--line);display:flex;gap:8px;align-items:center;flex-wrap:wrap}
|
|
621
|
+
.card .cid{font-weight:650;font-variant-numeric:tabular-nums}.card .goto{margin-left:auto;font-size:12px}
|
|
622
|
+
.card pre{margin:0;padding:10px 12px;white-space:pre-wrap;word-break:break-word;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace;max-height:520px;overflow:auto}
|
|
623
|
+
.card ul.issues{margin:0;padding:8px 12px 8px 30px;border-bottom:1px solid var(--line);font-size:13px}.card ul.issues li{margin:2px 0}
|
|
624
|
+
details.meta{border-bottom:1px solid var(--line);font-size:12px}details.meta summary{cursor:pointer;padding:6px 12px;color:var(--muted)}
|
|
625
|
+
details.meta table{border-collapse:collapse;margin:0 12px 8px}details.meta th{text-align:left;color:var(--muted);font-weight:600;padding:2px 12px 2px 0;vertical-align:top;white-space:nowrap}
|
|
626
|
+
details.meta td{font-family:ui-monospace,Menlo,monospace;word-break:break-all;padding:2px 0}
|
|
627
|
+
svg.hist{width:100%;max-width:720px;height:auto;display:block}
|
|
628
|
+
svg.hist .hb{fill:var(--muted);opacity:.75}svg.hist .hb.over{fill:var(--over);opacity:.9}svg.hist .hb:hover{opacity:1}
|
|
629
|
+
svg.hist .axis{stroke:var(--line)}svg.hist .limit{stroke:var(--ink);stroke-dasharray:4 3;opacity:.6}
|
|
630
|
+
svg.hist .tick{fill:var(--muted);font-size:11px}
|
|
631
|
+
#drawer{position:fixed;right:16px;bottom:16px;width:min(560px,calc(100vw - 32px));max-height:60vh;overflow:auto;background:var(--panel);
|
|
632
|
+
border:1px solid var(--line);border-radius:12px;box-shadow:0 10px 30px rgba(0,0,0,.18);z-index:10}
|
|
633
|
+
#drawer .close{position:sticky;top:0;float:right;margin:6px 8px;border:0;background:transparent;color:var(--muted);font-size:20px;cursor:pointer}
|
|
634
|
+
#drawer .card{margin:0;border:0}
|
|
635
|
+
.sw.k0{background:var(--k0b)}.sw.k1{background:var(--k1b)}.sw.k2{background:var(--k2b)}.sw.k3{background:var(--k3b)}
|
|
636
|
+
.sw.sw-line{background:transparent;box-shadow:inset 0 -2px var(--line);border:1px solid var(--line)}
|
|
637
|
+
nav .theme{display:block;margin-top:8px;border:1px solid var(--line);background:var(--bg);color:var(--muted);border-radius:6px;padding:2px 8px;font-size:11px;cursor:pointer}
|
|
638
|
+
nav .theme:hover{color:var(--ink)}
|
|
639
|
+
.colorbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 16px;margin:0 0 12px;font-size:12px;color:var(--muted)}
|
|
640
|
+
.colorbar select,.toolbar select{font:inherit;font-size:12px;color:var(--ink);background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:2px 6px;margin-left:4px}
|
|
641
|
+
.colorbar .legends{display:flex;flex-wrap:wrap;gap:6px}.lg{display:none;flex-wrap:wrap;align-items:center;gap:4px 10px}.lg .sw{margin:0 2px}
|
|
642
|
+
.lgi{white-space:nowrap}.lgi small{color:var(--muted)}
|
|
643
|
+
.toolbar{display:flex;flex-wrap:wrap;gap:8px 20px;margin:0 0 12px;color:var(--muted);font-size:13px}
|
|
644
|
+
.cm{position:relative;margin:0 0 12px;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:0;box-sizing:content-box;border-width:8px 10px;border-color:var(--panel);outline:1px solid var(--line)}
|
|
645
|
+
.cmb{position:absolute;height:8px;border-radius:2px;background:var(--muted);opacity:.9;box-shadow:0 0 0 1px var(--panel)}
|
|
646
|
+
.cmb:hover{opacity:1;outline:2px solid var(--ink);z-index:2}
|
|
647
|
+
.cmg{position:absolute;height:4px;border-radius:2px;background:var(--over)}
|
|
648
|
+
.cmp{margin:0 0 18px}.cmp-head{display:flex;flex-wrap:wrap;gap:4px 12px;align-items:baseline;margin:0 0 6px;font-size:13px}
|
|
649
|
+
.pill.score{color:var(--ink);border-color:#f47230}
|
|
650
|
+
.query{font-size:14px}.query q{font-weight:600}
|
|
651
|
+
td.preview{color:var(--muted);font-size:12.5px}
|
|
652
|
+
@media (max-width:820px){.layout{grid-template-columns:1fr}nav{position:static;height:auto}main{padding:16px}}
|
|
653
|
+
"""
|
|
654
|
+
|
|
655
|
+
JS = """
|
|
656
|
+
(function(){
|
|
657
|
+
var drawer=document.getElementById('drawer'),body=drawer.querySelector('.body');
|
|
658
|
+
function parse(){var p=decodeURIComponent(location.hash.slice(1)||'overview').split(':');
|
|
659
|
+
var r={view:p[0],tab:null,chunk:null};p.slice(1).forEach(function(x){if(/^c\\d+$/.test(x))r.chunk=+x.slice(1);else r.tab=x;});return r;}
|
|
660
|
+
function route(){var r=parse(),view=document.getElementById('v-'+r.view);
|
|
661
|
+
if(!view){r={view:'overview',tab:null,chunk:null};view=document.getElementById('v-overview');}
|
|
662
|
+
document.querySelectorAll('.view').forEach(function(v){v.hidden=v!==view;});
|
|
663
|
+
document.querySelectorAll('nav a.file').forEach(function(a){a.classList.toggle('active',a.dataset.view===r.view);});
|
|
664
|
+
closeDrawer();
|
|
665
|
+
if(r.view==='overview'){window.scrollTo(0,0);return;}
|
|
666
|
+
var tab=r.tab||view.dataset['default'];
|
|
667
|
+
if(!view.querySelector('.pane[data-tab="'+tab+'"]'))tab=view.dataset['default'];
|
|
668
|
+
view.querySelectorAll('.pane').forEach(function(p){p.hidden=p.dataset.tab!==tab;});
|
|
669
|
+
view.querySelectorAll('.tabs a').forEach(function(a){a.classList.toggle('active',a.dataset.tab===tab);});
|
|
670
|
+
if(r.chunk===null){window.scrollTo(0,0);return;}
|
|
671
|
+
if(tab==='source')select(view,r.chunk,true);
|
|
672
|
+
else{var card=document.getElementById(r.view+'-c'+r.chunk);if(card){card.classList.add('hl');card.scrollIntoView({block:'start'});
|
|
673
|
+
setTimeout(function(){card.classList.remove('hl');},1600);}}
|
|
674
|
+
}
|
|
675
|
+
function select(view,index,scroll){
|
|
676
|
+
view.querySelectorAll('.seg.sel').forEach(function(s){s.classList.remove('sel');});
|
|
677
|
+
var segs=view.querySelectorAll('.seg[data-c~="'+index+'"]');
|
|
678
|
+
segs.forEach(function(s){s.classList.add('sel');});
|
|
679
|
+
view.dataset.selected=index;
|
|
680
|
+
if(scroll&&segs.length)segs[0].scrollIntoView({block:'center'});
|
|
681
|
+
var card=document.getElementById(view.id.slice(2)+'-c'+index);
|
|
682
|
+
if(card){var copy=card.cloneNode(true);copy.removeAttribute('id');body.innerHTML='';body.appendChild(copy);drawer.hidden=false;}
|
|
683
|
+
}
|
|
684
|
+
function closeDrawer(){drawer.hidden=true;body.innerHTML='';}
|
|
685
|
+
document.addEventListener('click',function(ev){
|
|
686
|
+
var seg=ev.target.closest('.seg');
|
|
687
|
+
if(seg){var view=seg.closest('.view'),list=seg.dataset.c.split(' ').map(Number),cur=+view.dataset.selected;
|
|
688
|
+
var i=list.indexOf(cur),next=list[(i+1)%list.length];
|
|
689
|
+
try{history.replaceState(null,'','#'+view.id.slice(2)+':c'+next);}catch(e){}select(view,next,false);return;}
|
|
690
|
+
if(ev.target.closest('#drawer .close'))closeDrawer();
|
|
691
|
+
});
|
|
692
|
+
function setColor(mode){document.body.dataset.color=mode;document.querySelectorAll('.color-select').forEach(function(s){s.value=mode;});}
|
|
693
|
+
setColor(document.body.dataset.color);
|
|
694
|
+
var themes=['auto','light','dark'],themeButton=document.querySelector('nav .theme');
|
|
695
|
+
function setTheme(t){if(t==='auto')document.documentElement.removeAttribute('data-theme');else document.documentElement.dataset.theme=t;
|
|
696
|
+
if(themeButton)themeButton.textContent='Theme: '+t;}
|
|
697
|
+
setTheme(document.documentElement.dataset.theme||'auto');
|
|
698
|
+
if(themeButton)themeButton.addEventListener('click',function(){var t=document.documentElement.dataset.theme||'auto';setTheme(themes[(themes.indexOf(t)+1)%3]);});
|
|
699
|
+
document.addEventListener('change',function(ev){
|
|
700
|
+
var t=ev.target;
|
|
701
|
+
if(t.classList.contains('only-issues')){t.closest('.pane').querySelector('.cards').classList.toggle('only-flagged',t.checked);}
|
|
702
|
+
if(t.classList.contains('color-select'))setColor(t.value);
|
|
703
|
+
if(t.classList.contains('sort-cards')){var box=t.closest('.pane').querySelector('.cards'),cards=Array.prototype.slice.call(box.children);
|
|
704
|
+
cards.sort(function(a,b){if(t.value==='rank'){var ra=+a.dataset.rank||1e9,rb=+b.dataset.rank||1e9;return ra-rb;}return a.dataset.index-b.dataset.index;});
|
|
705
|
+
cards.forEach(function(c){box.appendChild(c);});}
|
|
706
|
+
});
|
|
707
|
+
document.addEventListener('keydown',function(ev){if(ev.key==='Escape')closeDrawer();});
|
|
708
|
+
window.addEventListener('hashchange',route);route();
|
|
709
|
+
})();
|
|
710
|
+
"""
|