@seikika/astro-report 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,84 @@
1
+ import type { ReportData } from "../types";
2
+ import { title } from "./rings";
3
+ import { catalogKindsSorted } from "./summary";
4
+ import { fmt, plural } from "./words";
5
+
6
+ // Kinds in their declared groups, then any kind no group names.
7
+ export function kindGroupsOf(D: ReportData) {
8
+ var catalog = D.catalog || {};
9
+ var seen: Record<string, boolean> = {};
10
+ var groups: { name: string; title: string; description?: string | null; kinds: string[]; count?: number }[] = (D.kindGroups || [])
11
+ .map(function (g) {
12
+ var kinds = (g.kinds || []).filter(function (k) {
13
+ seen[k] = true;
14
+ return catalog[k];
15
+ });
16
+ return { name: g.name, title: g.title || g.name, description: g.description, kinds: kinds };
17
+ })
18
+ .filter(function (g) {
19
+ return g.kinds.length;
20
+ });
21
+ var rest = catalogKindsSorted(D).filter(function (k) {
22
+ return !seen[k];
23
+ });
24
+ if (rest.length) groups.push({ name: "", title: groups.length ? "Other kinds" : "Kinds", kinds: rest });
25
+ groups.forEach(function (g) {
26
+ g.count = g.kinds.reduce(function (n, k) {
27
+ return n + catalog[k].length;
28
+ }, 0);
29
+ });
30
+ return groups;
31
+ }
32
+
33
+ export function kindDescription(D: ReportData, k) {
34
+ return (((D.kinds || {})[k] || {}).description || "").trim();
35
+ }
36
+
37
+ export var ACRONYMS = { Api: "API", Cli: "CLI", Json: "JSON", Mcp: "MCP", Sdlc: "SDLC", Ui: "UI", Url: "URL" };
38
+ // A kind's id (SdlcLayer) in the reader's words (SDLC layer), unless the kind names a title.
39
+ export function kindTitle(D: ReportData, k) {
40
+ var t = ((D.kinds || {})[k] || {}).title;
41
+ if (t) return t;
42
+ var words = String(k || "").match(/OpenSSF|[A-Z]{2,}(?![a-z])|[A-Z][a-z0-9]*|[a-z0-9]+/g) || [k];
43
+ return words
44
+ .map(function (w, i) {
45
+ if (ACRONYMS[w]) return ACRONYMS[w];
46
+ if (w === "OpenSSF" || /^[A-Z]{2,}$/.test(w)) return w;
47
+ return i ? w.toLowerCase() : w;
48
+ })
49
+ .join(" ");
50
+ }
51
+
52
+ // "15 action dependencies", "26 SDLC stages": a count of a kind, in running text.
53
+ export function kindCount(D: ReportData, k, n) {
54
+ var t = kindTitle(D, k);
55
+ if (!/^(?:[A-Z]{2,}|OpenSSF|GitHub|(?:Go|Python|Rust|Cargo|TypeScript|JavaScript)\b)/.test(t)) t = t.charAt(0).toLowerCase() + t.slice(1);
56
+ var tail = (t.match(/ \([^)]*\)$/) || [""])[0];
57
+ t = t.slice(0, t.length - tail.length);
58
+ if (n !== 1) t = /[^aeiou]y$/.test(t) ? t.slice(0, -1) + "ies" : /(s|x|ch|sh)$/.test(t) ? t + "es" : t + "s";
59
+ return fmt(n) + " " + t + tail;
60
+ }
61
+
62
+ // The Scorecard kind counts more than the Scorecards tab: say what the surplus is wherever its total appears.
63
+ export function scorecardSplit(D: ReportData, k) {
64
+ if (k !== "Scorecard") return "";
65
+ var ids = (D.catalog || {})[k] || [];
66
+ var hits = {};
67
+ var split = ids.map(function (id) {
68
+ var m = /^[^:]+:([^/]+)\/(.+)$/.exec(id);
69
+ if (m && (D.scorecards || {})[m[2]]) hits[m[1]] = (hits[m[1]] || 0) + 1;
70
+ return m;
71
+ });
72
+ var mine = Object.keys(hits).sort(function (a, b) {
73
+ return hits[b] - hits[a];
74
+ })[0];
75
+ var own = 0;
76
+ var cmp = 0;
77
+ split.forEach(function (m) {
78
+ if (!m || m[1] !== mine || !(D.scorecards || {})[m[2]]) return;
79
+ if ((D.comparisons || {})[m[2]]) cmp++;
80
+ else own++;
81
+ });
82
+ var parts = [fmt(own) + " of this portal's own", cmp ? plural(cmp, "comparison factor") : null, ids.length - own - cmp ? fmt(ids.length - own - cmp) + " in example portals" : null].filter(Boolean);
83
+ return parts.length > 1 ? " (" + parts.join(", ") + ")" : "";
84
+ }
@@ -0,0 +1,61 @@
1
+ import type { ReportData } from "../types";
2
+ import { KNOWN } from "./dom";
3
+
4
+ // Custom level names (a one-level scorecard's "ten", say) borrow the colour of the
5
+ // standard level at the same height, counted from the top.
6
+ export var ALIAS = {};
7
+ export var LEVEL_NOTE = {};
8
+ export var LEVEL_DEF = {};
9
+ export var ONLY_LEVEL = new Set();
10
+ export function aliasLevels(D: ReportData) {
11
+ Object.entries(D.scorecards || {}).forEach(function (e) {
12
+ var sc = e[1];
13
+ var levels = sc.levels || [];
14
+ levels.forEach(function (l, i) {
15
+ if (KNOWN.indexOf(l) < 0 && !ALIAS[l]) {
16
+ ALIAS[l] = ["gold", "silver", "bronze"][Math.min(2, levels.length - 1 - i)];
17
+ var said = (sc.description || "").split(/(?<=\.)\s+/).filter(function (s) {
18
+ return s.toLowerCase().split(/[^a-z0-9-]+/).indexOf(String(l).toLowerCase()) >= 0;
19
+ })[0];
20
+ if (said) LEVEL_DEF[l] = said.replace(/`/g, "");
21
+ LEVEL_NOTE[l] = "“" + l + "” is a level " + (sc.title || e[0]) + " names itself" + (levels.length === 1 ? ": its only level, so reaching it is the top." : ", ranked like " + ALIAS[l] + ".") + (said ? " " + LEVEL_DEF[l] : "");
22
+ if (levels.length === 1) ONLY_LEVEL.add(l);
23
+ }
24
+ });
25
+ });
26
+ }
27
+
28
+ // Across scorecards, levels are compared on the standard ladder; where one scorecard alone rates a
29
+ // kind, its own level names ("within-limit") are what a reader saw on that scorecard.
30
+ export function ownLevel(D: ReportData, kind, l) {
31
+ var cards = Object.keys(D.scorecards || {})
32
+ .filter(function (n) {
33
+ return D.scorecards[n].kind === kind && !(D.comparisons || {})[n];
34
+ })
35
+ .map(function (n) {
36
+ return D.scorecards[n];
37
+ });
38
+ if (cards.length !== 1 || l === "none" || l === "unscored") return l;
39
+ var own = (cards[0].levels || []).find(function (x) {
40
+ return x === l || known(x) === l;
41
+ });
42
+ return own || l;
43
+ }
44
+
45
+ export function known(l) {
46
+ return KNOWN.indexOf(l) >= 0 ? l : ALIAS[l] || null;
47
+ }
48
+
49
+ // Two textures only: hatched for "not assessed by an agent yet", dotted for "checks not run".
50
+ // Not scored is absence, so it is a plain pale fill.
51
+ export var UNSCORED = "color-mix(in srgb,var(--faint) 45%,var(--bg))";
52
+ export var UNRUN = "radial-gradient(circle,var(--faint) 1.3px,transparent 1.7px) 0 0/5px 5px";
53
+
54
+ export function fill(l) {
55
+ if (l === "unscored") return UNSCORED;
56
+ return "var(--" + (known(l) || "accent") + ")";
57
+ }
58
+
59
+ export function ink(l) {
60
+ return known(l) ? "var(--" + known(l) + "-ink)" : "var(--accent)";
61
+ }
@@ -0,0 +1,244 @@
1
+ import type { ReportData } from "../types";
2
+ import { lockIcon } from "./basis";
3
+ import { el, svg } from "./dom";
4
+ import { LEVEL_DEF, ONLY_LEVEL, fill } from "./levels";
5
+ import { repoLevel } from "./summary";
6
+ import { standingColor } from "./tracks";
7
+
8
+ export function ring(pct, opts) {
9
+ var o = opts || {};
10
+ var s = o.size || 52;
11
+ var r = s / 2 - 5;
12
+ var circ = 2 * Math.PI * r;
13
+ var color = o.color || "var(--accent)";
14
+ var arc = svg("circle", {
15
+ cx: s / 2,
16
+ cy: s / 2,
17
+ r: r,
18
+ fill: "none",
19
+ stroke: color,
20
+ "stroke-width": 6,
21
+ "stroke-linecap": "round",
22
+ "stroke-dasharray": circ,
23
+ "stroke-dashoffset": circ,
24
+ transform: "rotate(-90 " + s / 2 + " " + s / 2 + ")",
25
+ });
26
+ var label = String(o.text != null ? o.text : pct == null ? "—" : pct + "%");
27
+ var target: SVGElement | null = null;
28
+ if (o.target != null && o.target < 100) {
29
+ var a = (o.target / 100) * 2 * Math.PI - Math.PI / 2;
30
+ target = svg("line", {
31
+ x1: s / 2 + (r - 5) * Math.cos(a),
32
+ y1: s / 2 + (r - 5) * Math.sin(a),
33
+ x2: s / 2 + (r + 5) * Math.cos(a),
34
+ y2: s / 2 + (r + 5) * Math.sin(a),
35
+ stroke: "var(--fg)",
36
+ "stroke-width": 2,
37
+ });
38
+ }
39
+ var g = svg(
40
+ "svg",
41
+ { class: "ring", width: s, height: s, viewBox: "0 0 " + s + " " + s, role: "img", "aria-label": o.label || pct + "%" },
42
+ svg("circle", { cx: s / 2, cy: s / 2, r: r, fill: "none", stroke: "var(--line)", "stroke-width": 6 }),
43
+ pct == null ? null : arc,
44
+ target,
45
+ o.bare ? null : svg("text", { x: "50%", y: "50%", "text-anchor": "middle", "dominant-baseline": "central", style: s > 70 ? "font-size:18px" : label.length > 3 ? "font-size:12px" : "" }, label),
46
+ );
47
+ if (pct != null) {
48
+ requestAnimationFrame(function () {
49
+ requestAnimationFrame(function () {
50
+ arc.setAttribute("stroke-dashoffset", String(circ * (1 - Math.max(0, Math.min(100, pct)) / 100)));
51
+ });
52
+ });
53
+ }
54
+ return g;
55
+ }
56
+
57
+ // A comparison's standing: one segment per factor, coloured ahead, at parity or behind, so it is
58
+ // never read as the progress ring's share.
59
+ export function tallyRing(v, n, size, bare?) {
60
+ var s = size || 52;
61
+ var c = s / 2;
62
+ var r = c - 5;
63
+ var circ = 2 * Math.PI * r;
64
+ var seg = circ / Math.max(n, 1);
65
+ var gap = n > 1 ? Math.min(4, seg / 3) : 0;
66
+ var segs: SVGElement[] = [];
67
+ ["ahead", "parity", "behind", "unknown"].forEach(function (k) {
68
+ for (var j = 0; j < (v[k] || 0); j++) {
69
+ segs.push(
70
+ svg("circle", {
71
+ cx: c,
72
+ cy: c,
73
+ r: r,
74
+ fill: "none",
75
+ stroke: standingColor(k),
76
+ "stroke-width": 6,
77
+ "stroke-dasharray": seg - gap + " " + (circ - seg + gap),
78
+ "stroke-dashoffset": -segs.length * seg,
79
+ transform: "rotate(-90 " + c + " " + c + ")",
80
+ }),
81
+ );
82
+ }
83
+ });
84
+ var text = n && v.unknown >= n ? "—" : v.ahead + "/" + n;
85
+ return svg(
86
+ "svg",
87
+ { class: "ring tally", width: s, height: s, viewBox: "0 0 " + s + " " + s, role: "img", "aria-label": tallyWords(v, n) },
88
+ ...segs,
89
+ bare ? null : svg("text", { x: "50%", y: "50%", "text-anchor": "middle", "dominant-baseline": "central", style: s > 70 ? "font-size:18px" : text.length > 3 ? "font-size:12px" : "" }, text),
90
+ );
91
+ }
92
+
93
+ function factorWord(n) {
94
+ return n === 1 ? "factor" : "factors";
95
+ }
96
+
97
+ // The strict count is worded as factors, not as another "ahead on N", so it cannot be read as the verdict digits.
98
+ export function countWords(c, key?: "strict" | "majority") {
99
+ if (key === "strict") {
100
+ var has = function (n) {
101
+ return n === 1 ? "has" : "have";
102
+ };
103
+ var is = function (n) {
104
+ return n === 1 ? "is" : "are";
105
+ };
106
+ return [
107
+ c.ahead + " " + factorWord(c.ahead) + " " + has(c.ahead) + " no rule behind",
108
+ c.parity ? c.parity + " " + factorWord(c.parity) + " " + is(c.parity) + " at parity" : null,
109
+ c.behind + " " + factorWord(c.behind) + " " + has(c.behind) + " at least one rule behind",
110
+ c.unknown ? c.unknown + " " + factorWord(c.unknown) + " " + is(c.unknown) + " not measured" : null,
111
+ ]
112
+ .filter(Boolean)
113
+ .join(". ");
114
+ }
115
+ return ["ahead on " + c.ahead, c.parity ? "at parity on " + c.parity : null, "behind on " + c.behind, c.unknown ? "not measured on " + c.unknown : null].filter(Boolean).join(", ");
116
+ }
117
+
118
+ function sameCount(a, b) {
119
+ return a.ahead === b.ahead && a.parity === b.parity && a.behind === b.behind && a.unknown === b.unknown;
120
+ }
121
+
122
+ // Both counting rules, always strict first and majority second, so two portals that declare
123
+ // different rules still show the same two numbers in the same place (D01M87WF2QZVPTD8CGDZKY133CD).
124
+ export var COUNTS = [
125
+ { key: "strict", label: "Strict count", def: "a factor is behind if any one of its rules is behind" },
126
+ { key: "majority", label: "Majority count", def: "a factor follows whichever side more of its rules are on" },
127
+ ] as const;
128
+
129
+ export function tallyWords(v, n) {
130
+ if (n && v.unknown >= n) return "not measured yet: no factor has values for both products";
131
+ var b = v.both;
132
+ if (!b || v.majority == null) return countWords(v) + " of " + n + " factors";
133
+ var mineKey: "strict" | "majority" = v.majority ? "majority" : "strict";
134
+ var otherKey: "strict" | "majority" = v.majority ? "strict" : "majority";
135
+ var clause = function (key: "strict" | "majority") {
136
+ return key === "strict" ? countWords(b[key], key) : countWords(b[key], key) + " of " + n + " factors";
137
+ };
138
+ if (sameCount(b.strict, b.majority)) return clause(mineKey) + ", by the " + mineKey + " count, this comparison's verdict. The " + otherKey + " count agrees.";
139
+ if (mineKey === "strict") return clause("strict") + ". The strict count is this comparison's verdict. By the majority count, " + clause("majority") + ".";
140
+ return clause("majority") + " by the majority count, this comparison's verdict. By the strict count, " + clause("strict") + ".";
141
+ }
142
+
143
+ // The factor count in a few words, for strips and cards.
144
+ export function tallyShort(v, n) {
145
+ if (n && v.unknown >= n) return "not measured yet";
146
+ var b = v.both;
147
+ if (!b || v.majority == null) return "ahead on " + v.ahead + " of " + n + " factors";
148
+ if (sameCount(b.strict, b.majority)) return "ahead on " + v.ahead + " of " + n + " factors, by the " + (v.majority ? "majority" : "strict") + " count";
149
+ var mine = v.majority ? b.majority : b.strict;
150
+ return "ahead on " + mine.ahead + " of " + n + " factors, behind on " + mine.behind + " (" + (v.majority ? "majority" : "strict") + " count, the verdict)";
151
+ }
152
+
153
+ // The two counts as a small table, the comparison's own rule marked.
154
+ export function bothCounts(v, n) {
155
+ var b = v.both;
156
+ if (!b || v.majority == null || (n && v.unknown >= n)) return null;
157
+ return el(
158
+ "dl",
159
+ { className: "both-counts" },
160
+ ...COUNTS.map(function (c) {
161
+ var mine = (c.key === "majority") === !!v.majority;
162
+ return el("div", { className: mine ? "mine" : "", title: "The " + c.label.toLowerCase() + ": " + c.def + "." }, el("dt", {}, c.label, mine ? el("small", { textContent: " · this comparison's verdict" }) : null), el("dd", { textContent: countWords(b[c.key], c.key) }));
163
+ }),
164
+ );
165
+ }
166
+
167
+ var UNIQUE = new Map<string, string>();
168
+
169
+ function baseName(s: string) {
170
+ var i = Math.max(s.lastIndexOf("/"), s.lastIndexOf(":"));
171
+ return i >= 0 && i < s.length - 1 ? s.slice(i + 1) : s;
172
+ }
173
+
174
+ // Entities whose basenames collide (three check.go files) are named by the shortest path suffix
175
+ // that tells them apart, wherever shortId names them.
176
+ export function registerIds(ids: string[]) {
177
+ UNIQUE = new Map();
178
+ var byBase = new Map<string, string[]>();
179
+ // The same file can be an entity of several kinds; only names within one kind need to differ.
180
+ ids.forEach(function (id) {
181
+ var b = id.slice(0, Math.max(id.indexOf(":"), 0)) + "|" + baseName(id);
182
+ (byBase.get(b) || byBase.set(b, []).get(b)!).push(id);
183
+ });
184
+ byBase.forEach(function (group) {
185
+ if (group.length < 2) return;
186
+ var paths = group.map(function (id) {
187
+ var p = id.slice(id.indexOf(":") + 1);
188
+ return p.split("/");
189
+ });
190
+ group.forEach(function (id, k) {
191
+ var parts = paths[k];
192
+ for (var n = 2; n <= parts.length; n++) {
193
+ var tail = parts.slice(-n).join("/");
194
+ var clash = paths.some(function (q, j) {
195
+ return j !== k && q.slice(-n).join("/") === tail;
196
+ });
197
+ if (!clash) return UNIQUE.set(id, tail);
198
+ }
199
+ });
200
+ });
201
+ }
202
+
203
+ export function shortId(id) {
204
+ var s = String(id || "");
205
+ return UNIQUE.get(s) || baseName(s);
206
+ }
207
+
208
+ // A product with no entity yet (its records are not loaded) takes the spelling the portal's own
209
+ // track prose uses for it, so "openfga" still reads "OpenFGA".
210
+ export function productName(D: ReportData, id, titles?: Record<string, string | null>) {
211
+ var t = titles && titles[id];
212
+ if (t && t !== id) return t;
213
+ var s = shortId(id);
214
+ var re = new RegExp("(^|[^\\w])(" + s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + ")(?![\\w])", "i");
215
+ var tracks = Object.values(D.tracks || {}) as { title?: string; description?: string }[];
216
+ for (var i = 0; i < tracks.length; i++) {
217
+ var m = ((tracks[i].title || "") + " " + (tracks[i].description || "")).match(re);
218
+ if (m && m[2] !== m[2].toLowerCase()) return m[2];
219
+ }
220
+ return s;
221
+ }
222
+
223
+ export function isTop(D: ReportData, name, level) {
224
+ var levels = ((D.scorecards || {})[name] || {}).levels || [];
225
+ return !!level && level === levels[levels.length - 1];
226
+ }
227
+
228
+ // A repository standard whose only top level is the repository's level holds the repository there:
229
+ // that is a ceiling, not an achievement.
230
+ export function capsRepo(D: ReportData, name, level) {
231
+ var R = repoLevel(D);
232
+ return !!(R && R.next && isTop(D, name, level) && level === R.floor && (D.repoRollup || []).indexOf(name) >= 0);
233
+ }
234
+
235
+ export function topNote(D: ReportData, name, level) {
236
+ if (capsRepo(D, name, level)) return el("span", { className: "capnote", title: "Its top level is " + level + ", so the repository cannot rise above " + level + " until this scorecard gains a higher level" }, " ", lockIcon(), " at its top level, " + level + ", so it caps the repository");
237
+ var top = isTop(D, name, level) && !ONLY_LEVEL.has(level) ? el("span", { className: "topmark", textContent: " ✓ top level" }) : "";
238
+ return LEVEL_DEF[level] ? el("span", {}, top, el("span", { className: "sub leveldef", textContent: " · " + LEVEL_DEF[level] })) : top;
239
+ }
240
+
241
+ export function title(D: ReportData, name) {
242
+ var sc = (D.scorecards || {})[name] || {};
243
+ return sc.title || name;
244
+ }
@@ -0,0 +1,118 @@
1
+ import type { ReportData } from "../types";
2
+ import { el, enc, link } from "./dom";
3
+ import { known } from "./levels";
4
+ import { title } from "./rings";
5
+
6
+ export interface Query {
7
+ q?: string;
8
+ level?: string;
9
+ outcome?: string;
10
+ rule?: string;
11
+ }
12
+
13
+ export interface Route {
14
+ mode: string;
15
+ kind?: string;
16
+ id?: string;
17
+ name?: string;
18
+ scorecard?: string;
19
+ rule?: string;
20
+ bare?: boolean;
21
+ query?: Query;
22
+ }
23
+
24
+ export function parseHash(hash: string): Route {
25
+ var h = hash.replace(/^#/, "");
26
+ var query: Query = {};
27
+ var qi = h.indexOf("?");
28
+ if (qi >= 0) {
29
+ var params = new URLSearchParams(h.slice(qi + 1));
30
+ ["q", "level", "outcome", "rule"].forEach(function (k) {
31
+ if (params.has(k)) query[k as keyof Query] = params.get(k) || "";
32
+ });
33
+ h = h.slice(0, qi);
34
+ }
35
+ try {
36
+ return { ...parsePath(h), query };
37
+ } catch {
38
+ return { mode: "missing" };
39
+ }
40
+ }
41
+
42
+ export function parsePath(h: string): Route {
43
+ if (!h || h === "overview") return { mode: "overview" };
44
+ if (h === "catalog") return { mode: "catalog" };
45
+ if (h.indexOf("catalog/") === 0) return { mode: "catalog", kind: decodeURIComponent(h.slice(8)) };
46
+ if (h.indexOf("entity/") === 0) return { mode: "entity", id: decodeURIComponent(h.slice(7)) };
47
+ if (h === "tracks") return { mode: "tracks" };
48
+ if (h.indexOf("track/") === 0) return { mode: "tracks", name: decodeURIComponent(h.slice(6)) };
49
+ if (h.indexOf("rule/") === 0) {
50
+ var rest = h.slice(5);
51
+ var cut = rest.indexOf("/");
52
+ return { mode: "rule", scorecard: decodeURIComponent(rest.slice(0, cut)), rule: decodeURIComponent(rest.slice(cut + 1)) };
53
+ }
54
+ if (h === "campaigns") return { mode: "campaigns" };
55
+ if (h.indexOf("campaign/") === 0) return { mode: "campaign", name: decodeURIComponent(h.slice(9)) };
56
+ if (h === "compare") return { mode: "compare" };
57
+ if (h.indexOf("compare/") === 0) return { mode: "compare", name: decodeURIComponent(h.slice(8)) };
58
+ if (h.indexOf("scorecard/") === 0) return { mode: "scorecard", name: decodeURIComponent(h.slice(10)) };
59
+ if (h === "scorecards") return { mode: "scorecards" };
60
+ return { mode: "scorecard", name: decodeURIComponent(h), bare: true };
61
+ }
62
+
63
+ export function slugOf(text) {
64
+ return String(text)
65
+ .toLowerCase()
66
+ .replace(/[^a-z0-9]+/g, "-")
67
+ .replace(/^-+|-+$/g, "");
68
+ }
69
+
70
+ // Track links read as their titles; the manifest name still resolves, so older links keep working.
71
+ export function trackPath(D: ReportData, name) {
72
+ var def = (D.tracks || {})[name] || {};
73
+ var slug = def.title ? slugOf(def.title) : "";
74
+ var clash = Object.keys(D.tracks || {}).some(function (n) {
75
+ return n !== name && (n === slug || slugOf(((D.tracks || {})[n] || {}).title || "") === slug);
76
+ });
77
+ return "track/" + enc(slug && !clash ? slug : name);
78
+ }
79
+
80
+ export function trackByPath(D: ReportData, key) {
81
+ if ((D.tracks || {})[key]) return key;
82
+ var hit = Object.keys(D.tracks || {}).filter(function (n) {
83
+ return trackPath(D, n) === "track/" + enc(key);
84
+ })[0];
85
+ return hit || key;
86
+ }
87
+
88
+ export function missingTarget(D: ReportData, route: Route) {
89
+ if (route.bare && !(D.scorecards || {})[route.name || ""]) return "The link “#" + route.name + "” doesn't match anything in snapshot " + D.snapshot + ".";
90
+ if (route.mode === "scorecard" && route.name && !(D.scorecards || {})[route.name]) return "No scorecard is named “" + route.name + "”.";
91
+ if (route.mode === "tracks" && route.name && !(D.tracks || {})[route.name]) return "No track is named “" + route.name + "”.";
92
+ if (route.mode === "rule") {
93
+ var card = route.scorecard || "";
94
+ var rsc = (D.scorecards || {})[card];
95
+ if (!rsc) return "No scorecard is named “" + card + "”.";
96
+ if (!(rsc.rules || {})[route.rule || ""]) return title(D, card) + " has no rule named “" + route.rule + "”.";
97
+ }
98
+ if (route.mode === "campaign" && !(D.campaigns || {})[route.name || ""]) return "No campaign is named “" + route.name + "”.";
99
+ if (route.mode === "compare" && route.name && !(D.comparisons || {})[route.name]) return "No comparison is named “" + route.name + "”.";
100
+ if (route.mode === "catalog" && route.kind && !(D.catalog || {})[route.kind]) return "No kind is named “" + route.kind + "”.";
101
+ if (route.mode === "entity") {
102
+ var known = Object.values(D.catalog || {}).some(function (ids) {
103
+ return ids.indexOf(route.id || "") >= 0;
104
+ });
105
+ if (!known) return "No entity has the id “" + route.id + "” in this snapshot.";
106
+ }
107
+ return null;
108
+ }
109
+
110
+ export function notFound(message) {
111
+ return el(
112
+ "section",
113
+ {},
114
+ el("h2", { textContent: "Not found" }),
115
+ el("p", { className: "lede", textContent: message + " The link may be from an older report." }),
116
+ el("p", {}, link("overview", "", "Go to the overview"), " · ", link("catalog", "", "Browse the catalog")),
117
+ );
118
+ }
@@ -0,0 +1,143 @@
1
+ import type { ReportData } from "../types";
2
+ import { badge, unrunIn } from "./bars";
3
+ import { el, enc, link } from "./dom";
4
+ import { known } from "./levels";
5
+ import { shortId, title } from "./rings";
6
+ import { firstSentence, fmt } from "./words";
7
+
8
+ export var RULE_TITLE = new Map();
9
+ export var RULE_WORDS = { api: "API", ci: "CI", id: "ID", ids: "IDs", mcp: "MCP", sdlc: "SDLC", sha: "SHA", otel: "OTel", otlp: "OTLP", cel: "CEL", url: "URL", ui: "UI", kubernetes: "Kubernetes" };
10
+ export var RULE_WHY = new Map();
11
+ export var SC_NAME = new WeakMap();
12
+ export function ruleTitles(D: ReportData) {
13
+ RULE_TITLE.clear();
14
+ RULE_WHY.clear();
15
+ Object.entries(D.scorecards || {}).forEach(function (e) {
16
+ if (e[1] && typeof e[1] === "object") SC_NAME.set(e[1], e[0]);
17
+ Object.entries(e[1].rules || {}).forEach(function (r) {
18
+ if (r[1] && r[1].title) RULE_TITLE.set(e[0] + "\u0000" + r[0], r[1].title);
19
+ if (r[1] && r[1].rationale)
20
+ RULE_WHY.set(
21
+ e[0] + "\u0000" + r[0],
22
+ firstSentence(r[1].rationale)
23
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
24
+ .replace(/`/g, ""),
25
+ );
26
+ });
27
+ });
28
+ }
29
+ // A rule's id (public-api-documented) in the reader's words (Public API documented), unless it names a title.
30
+ export function ruleTitle(scName, rule) {
31
+ var t = RULE_TITLE.get(scName + "\u0000" + rule);
32
+ if (t) return t;
33
+ return String(rule)
34
+ .split("-")
35
+ .map(function (w, i) {
36
+ if (Object.prototype.hasOwnProperty.call(RULE_WORDS, w)) return RULE_WORDS[w];
37
+ return i ? w : w.charAt(0).toUpperCase() + w.slice(1);
38
+ })
39
+ .join(" ");
40
+ }
41
+
42
+ // The same, from the scorecard's definition rather than its name.
43
+ export function ruleTitleOf(sc, rule) {
44
+ return ruleTitle(SC_NAME.get(sc) || "", rule);
45
+ }
46
+
47
+ // `shown`: the rule's why is already printed beside the link, so it gets no tooltip.
48
+ export function ruleLink(scName, rule, text?, shown?) {
49
+ var a = link("rule/" + enc(scName) + "/" + enc(rule), "rl", text || ruleTitle(scName, rule));
50
+ var why = !shown && RULE_WHY.get(scName + "\u0000" + rule);
51
+ if (why) {
52
+ a.dataset.tip = "Why: " + why + (text ? "" : " (" + rule + ")");
53
+ a.setAttribute("aria-description", "Why: " + why);
54
+ } else if (!text) a.title = rule;
55
+ return a;
56
+ }
57
+
58
+ // The members of a folded group, each a link, so a reader can open one without unfolding it. It sits
59
+ // after the details element: links inside a summary would nest interactive controls.
60
+ export function memberLinks(ids, sized?: { order: string; first: string }) {
61
+ var cut = ids.length > 8 ? 6 : ids.length;
62
+ return el(
63
+ "div",
64
+ { className: "members" },
65
+ sized ? "In it, " + sized.order + ": " : "In it: ",
66
+ ...ids.slice(0, cut).flatMap(function (id, i) {
67
+ var name = shortId(id);
68
+ // Two files named check.go are told apart by their paths.
69
+ var twin = ids.some(function (o) {
70
+ return o !== id && shortId(o) === name;
71
+ });
72
+ var a = link("entity/" + enc(id), "", twin ? id.replace(/^[^:]*:/, "") : name);
73
+ if (i === 0 && sized && sized.first) return [a, " (" + sized.first + ")" + (i < cut - 1 ? "," : "")];
74
+ return [i ? " " : "", el("span", { style: "white-space:nowrap" }, a, i < cut - 1 ? "," : "")];
75
+ }),
76
+ ids.length > cut ? " and " + (ids.length - cut) + " more" : null,
77
+ );
78
+ }
79
+
80
+ export function isComparative(D: ReportData, name) {
81
+ return !!(D.comparisons || {})[name];
82
+ }
83
+
84
+ export var LADDER = ["none", "bronze", "silver", "gold"];
85
+
86
+ export function rankLevel(l) {
87
+ if (l == null) return 9;
88
+ var k = known(l);
89
+ return k ? LADDER.indexOf(k) : 0;
90
+ }
91
+
92
+ // A scorecard's lowest level among the entities it really scores: demo fixtures, out-of-scope
93
+ // entities and entities whose every rule is unknown don't count.
94
+ // A scorecard's weakest level as a pill, drawn hollow with the hatched or dotted glyph when at least
95
+ // half the entities holding it hold it only for want of an assessment or of checks not run.
96
+ export function floorPill(D: ReportData, name) {
97
+ var floor = floorOf(D, name);
98
+ var pill = badge(floor || "none");
99
+ if (!floor || floor === "none") return pill;
100
+ var sc = (D.scorecards || {})[name];
101
+ var rows = (D.scores || {})[name] || {};
102
+ var un = new Set((D.unassessed || {})[name] || []);
103
+ var at = 0;
104
+ var unj = 0;
105
+ var unr = 0;
106
+ Object.keys(rows).forEach(function (id) {
107
+ if (id.indexOf("/demo/") >= 0 || rows[id].level !== floor) return;
108
+ at++;
109
+ if (un.has(id)) unj++;
110
+ else if (unrunIn(sc, rows[id]).length) unr++;
111
+ });
112
+ if (!at || (unj + unr) * 2 < at) return pill;
113
+ var judged = unj >= unr;
114
+ pill.classList.add("vacuous", judged ? "unjudged" : "unrun");
115
+ pill.append(judged ? el("span", { className: "vhatch", ariaHidden: "true" }) : el("span", { className: "vglyph", ariaHidden: "true", textContent: " ◌" }));
116
+ pill.setAttribute("aria-label", "level " + floor + ", may not hold: " + fmt(unj + unr) + " of " + fmt(at) + (judged ? " not assessed" : " provisional"));
117
+ pill.title = fmt(unj + unr) + " of " + fmt(at) + " entities at " + floor + (judged ? " are not assessed by an agent yet" : " rest on checks not run in this build") + ", so this level may not hold";
118
+ return pill;
119
+ }
120
+
121
+ export function floorOf(D: ReportData, name) {
122
+ var sc = (D.scorecards || {})[name];
123
+ if (!sc) return null;
124
+ var order = ["none"].concat(sc.levels || []);
125
+ var best = null as { level: string; rank: number } | null;
126
+ Object.keys((D.scores || {})[name] || {}).forEach(function (id) {
127
+ if (id.indexOf("/demo/") >= 0) return;
128
+ var row = D.scores[name][id];
129
+ if (!row || row.level === "skipped") return;
130
+ var rules = row.rules || {};
131
+ var keys = Object.keys(rules);
132
+ if (
133
+ keys.length &&
134
+ keys.every(function (k) {
135
+ return rules[k] === "unknown";
136
+ })
137
+ )
138
+ return;
139
+ var r = order.indexOf(row.level);
140
+ if (best == null || r < best.rank) best = { level: row.level, rank: r };
141
+ });
142
+ return best ? best.level : null;
143
+ }