prepublic 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.
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +164 -2
- package/SECURITY.md +18 -0
- package/bin/prepublic.js +12 -0
- package/package.json +50 -4
- package/scripts/make-examples.mjs +200 -0
- package/src/checks/history.js +210 -0
- package/src/checks/project.js +351 -0
- package/src/checks/worktree.js +268 -0
- package/src/cli.js +203 -0
- package/src/config.js +59 -0
- package/src/findings.js +53 -0
- package/src/git.js +164 -0
- package/src/gitleaks.js +118 -0
- package/src/index.js +5 -0
- package/src/report/fonts/OFL.txt +192 -0
- package/src/report/fonts/ibm-plex-mono-latin-400.woff2 +0 -0
- package/src/report/fonts/ibm-plex-mono-latin-500.woff2 +0 -0
- package/src/report/fonts/ibm-plex-sans-latin-wght.woff2 +0 -0
- package/src/report/html.js +58 -0
- package/src/report/markdown.js +63 -0
- package/src/report/ui/app.js +590 -0
- package/src/report/ui/styles.css +356 -0
- package/src/report/ui/template.html +87 -0
- package/src/rules/files.js +78 -0
- package/src/rules/personal.js +76 -0
- package/src/rules/secrets.js +241 -0
- package/src/scan.js +221 -0
- package/src/version.js +2 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
/* Prepublic report UI. Vanilla JS, no network access. Report data is only ever
|
|
2
|
+
rendered with textContent; innerHTML is used for static icon markup only. */
|
|
3
|
+
(function () {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
var payload = JSON.parse(document.getElementById('rr-data').textContent);
|
|
7
|
+
var R = payload.report;
|
|
8
|
+
var SEV = ['critical', 'high', 'medium', 'low', 'info'];
|
|
9
|
+
var SEV_LABEL = { critical: 'Critical', high: 'High', medium: 'Medium', low: 'Low', info: 'Info' };
|
|
10
|
+
var CATS = Object.keys(R.categories);
|
|
11
|
+
var CAT_SHORT = { secrets: 'Secrets', history: 'Git history', files: 'Sensitive files', privacy: 'Personal data', hygiene: 'Hygiene', docs: 'Docs & license' };
|
|
12
|
+
var STATUS_LABEL = { pass: 'Passed', fail: 'Failed', warn: 'Review', manual: 'Your call', skipped: 'Not run' };
|
|
13
|
+
|
|
14
|
+
/* ---------- icons (static markup) ---------- */
|
|
15
|
+
var GLYPH = {
|
|
16
|
+
critical: '<svg class="glyph" viewBox="0 0 12 12" aria-hidden="true"><rect x="1" y="1" width="10" height="10" rx="1.4" fill="currentColor"/></svg>',
|
|
17
|
+
high: '<svg class="glyph" viewBox="0 0 12 12" aria-hidden="true"><path fill="currentColor" d="M6 .9 11.4 10.8H.6z"/></svg>',
|
|
18
|
+
medium: '<svg class="glyph" viewBox="0 0 12 12" aria-hidden="true"><path fill="currentColor" d="M6 .6 11.4 6 6 11.4.6 6z"/></svg>',
|
|
19
|
+
low: '<svg class="glyph" viewBox="0 0 12 12" aria-hidden="true"><circle cx="6" cy="6" r="4.3" fill="none" stroke="currentColor" stroke-width="2"/></svg>',
|
|
20
|
+
info: '<svg class="glyph" viewBox="0 0 12 12" aria-hidden="true"><circle cx="6" cy="6" r="2.6" fill="currentColor"/></svg>',
|
|
21
|
+
};
|
|
22
|
+
var ST = {
|
|
23
|
+
pass: '<svg class="st" viewBox="0 0 18 18" aria-hidden="true"><circle cx="9" cy="9" r="8" fill="currentColor" opacity=".14"/><path d="m5.6 9.2 2.3 2.3 4.6-4.9" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
24
|
+
fail: '<svg class="st" viewBox="0 0 18 18" aria-hidden="true"><circle cx="9" cy="9" r="8" fill="currentColor" opacity=".14"/><path d="m6.4 6.4 5.2 5.2m0-5.2-5.2 5.2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>',
|
|
25
|
+
warn: '<svg class="st" viewBox="0 0 18 18" aria-hidden="true"><circle cx="9" cy="9" r="8" fill="currentColor" opacity=".14"/><path d="M9 5.4v4.4M9 12.6v.1" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/></svg>',
|
|
26
|
+
manual: '<svg class="st" viewBox="0 0 18 18" aria-hidden="true"><circle cx="9" cy="9" r="8" fill="currentColor" opacity=".14"/><circle cx="9" cy="9" r="2.2" fill="none" stroke="currentColor" stroke-width="1.7"/><path d="M3.8 9C5 6.7 6.8 5.6 9 5.6s4 1.1 5.2 3.4C13 11.3 11.2 12.4 9 12.4S5 11.3 3.8 9Z" fill="none" stroke="currentColor" stroke-width="1.4"/></svg>',
|
|
27
|
+
skipped: '<svg class="st" viewBox="0 0 18 18" aria-hidden="true"><circle cx="9" cy="9" r="7.3" fill="none" stroke="currentColor" stroke-width="1.4" stroke-dasharray="2.4 2.4"/><path d="M6.2 9h5.6" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>',
|
|
28
|
+
};
|
|
29
|
+
var I = {
|
|
30
|
+
sun: '<svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="3" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M8 1.5v1.6M8 12.9v1.6M1.5 8h1.6M12.9 8h1.6M3.4 3.4l1.1 1.1M11.5 11.5l1.1 1.1M3.4 12.6l1.1-1.1M11.5 4.5l1.1-1.1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
|
|
31
|
+
moon: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M13.4 10.2A5.8 5.8 0 0 1 5.8 2.6a5.8 5.8 0 1 0 7.6 7.6Z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>',
|
|
32
|
+
check: '<svg class="done" viewBox="0 0 16 16" aria-hidden="true"><path d="m3.5 8.4 2.9 2.9 6.1-6.6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
33
|
+
checkSm: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="m3.5 8.4 2.9 2.9 6.1-6.6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
34
|
+
x: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="m4.5 4.5 7 7m0-7-7 7" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
|
|
35
|
+
ext: '<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M4.5 2.5h-2v7h7v-2M7 2.5h2.5V5M9.3 2.7 5.5 6.5" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
36
|
+
stamp: { blocked: '<svg viewBox="0 0 12 12" aria-hidden="true"><rect x="1" y="1" width="10" height="10" fill="currentColor"/></svg>', review: '<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M6 .6 11.4 6 6 11.4.6 6z" fill="currentColor"/></svg>', clear: '<svg viewBox="0 0 12 12" aria-hidden="true"><path d="m2 6.3 2.6 2.6L10 3.3" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square"/></svg>' },
|
|
37
|
+
mark: '<svg class="mark" viewBox="0 0 24 24" aria-hidden="true"><rect x="4" y="3" width="3.2" height="18" rx=".7" fill="currentColor"/><path d="M8.7 3h6.1a5 5 0 0 1 0 10H8.7z" fill="currentColor"/></svg>',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/* ---------- tiny DOM helper ---------- */
|
|
41
|
+
function h(tag, attrs) {
|
|
42
|
+
var el = document.createElement(tag);
|
|
43
|
+
if (attrs) for (var k in attrs) {
|
|
44
|
+
var v = attrs[k];
|
|
45
|
+
if (v == null || v === false) continue;
|
|
46
|
+
if (k === 'class') el.className = v;
|
|
47
|
+
else if (k === 'text') el.textContent = v;
|
|
48
|
+
else if (k === 'html') el.innerHTML = v; // static markup only
|
|
49
|
+
else if (k.slice(0, 2) === 'on') el.addEventListener(k.slice(2), v);
|
|
50
|
+
else el.setAttribute(k, v === true ? '' : v);
|
|
51
|
+
}
|
|
52
|
+
for (var i = 2; i < arguments.length; i++) add(el, arguments[i]);
|
|
53
|
+
return el;
|
|
54
|
+
}
|
|
55
|
+
function add(el, c) {
|
|
56
|
+
if (c == null || c === false) return;
|
|
57
|
+
if (Array.isArray(c)) { c.forEach(function (x) { add(el, x); }); return; }
|
|
58
|
+
el.appendChild(typeof c === 'string' || typeof c === 'number' ? document.createTextNode(String(c)) : c);
|
|
59
|
+
}
|
|
60
|
+
function icon(markup, cls) { return h('span', { class: 'ic' + (cls ? ' ' + cls : ''), html: markup }); }
|
|
61
|
+
function $(id) { return document.getElementById(id); }
|
|
62
|
+
var nf = new Intl.NumberFormat();
|
|
63
|
+
function n(x) { return nf.format(x || 0); }
|
|
64
|
+
function plural(x, one, many) { return n(x) + ' ' + (x === 1 ? one : (many || one + 's')); }
|
|
65
|
+
function bytes(b) { b = b || 0; return b >= 1048576 ? (b / 1048576).toFixed(1) + ' MB' : b >= 1024 ? Math.round(b / 1024) + ' KB' : b + ' B'; }
|
|
66
|
+
function rich(text) { return String(text).split('`').map(function (p, i) { return i % 2 ? h('code', { text: p, translate: 'no' }) : p; }); }
|
|
67
|
+
function locText(l) { return l.path + (l.line ? ':' + l.line : ''); }
|
|
68
|
+
var reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
69
|
+
|
|
70
|
+
/* ---------- local-only preferences ---------- */
|
|
71
|
+
function load(key, fallback) { try { var v = localStorage.getItem(key); return v == null ? fallback : JSON.parse(v); } catch (e) { return fallback; } }
|
|
72
|
+
function save(key, v) { try { localStorage.setItem(key, JSON.stringify(v)); } catch (e) { /* storage unavailable in this viewer */ } }
|
|
73
|
+
var reviewKey = 'prepublic:reviewed:' + R.repo.name;
|
|
74
|
+
var reviewed = load(reviewKey, {}) || {};
|
|
75
|
+
|
|
76
|
+
/* ---------- theme: follows the system unless the reader chooses ---------- */
|
|
77
|
+
var themeBtn = $('theme');
|
|
78
|
+
function applyTheme(t) {
|
|
79
|
+
document.documentElement.setAttribute('data-theme', t);
|
|
80
|
+
var meta = document.querySelector('meta[name="theme-color"]');
|
|
81
|
+
if (meta) meta.setAttribute('content', t === 'dark' ? '#0e0f11' : '#edefea');
|
|
82
|
+
themeBtn.innerHTML = t === 'dark' ? I.sun : I.moon;
|
|
83
|
+
themeBtn.setAttribute('aria-label', t === 'dark' ? 'Switch to light theme' : 'Switch to dark theme');
|
|
84
|
+
themeBtn.title = themeBtn.getAttribute('aria-label');
|
|
85
|
+
}
|
|
86
|
+
var theme = load('prepublic:theme', null) || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
87
|
+
applyTheme(theme);
|
|
88
|
+
themeBtn.addEventListener('click', function () { theme = theme === 'dark' ? 'light' : 'dark'; applyTheme(theme); save('prepublic:theme', theme); });
|
|
89
|
+
|
|
90
|
+
/* ---------- state (mirrored in the URL hash, so views can be linked) ---------- */
|
|
91
|
+
var state = { tab: 'findings', sev: null, cat: null, q: '', hide: false, ids: null, idsLabel: '', sel: null };
|
|
92
|
+
(function readHash() {
|
|
93
|
+
try {
|
|
94
|
+
var p = new URLSearchParams(location.hash.slice(1));
|
|
95
|
+
if (['findings', 'checklist', 'coverage'].indexOf(p.get('tab')) !== -1) state.tab = p.get('tab');
|
|
96
|
+
if (SEV.indexOf(p.get('sev')) !== -1) state.sev = p.get('sev');
|
|
97
|
+
if (CATS.indexOf(p.get('cat')) !== -1) state.cat = p.get('cat');
|
|
98
|
+
if (p.get('q')) state.q = p.get('q').slice(0, 200);
|
|
99
|
+
if (p.get('f')) state.sel = p.get('f');
|
|
100
|
+
} catch (e) { /* ignore a malformed hash */ }
|
|
101
|
+
})();
|
|
102
|
+
function writeHash() {
|
|
103
|
+
var p = new URLSearchParams();
|
|
104
|
+
if (state.tab !== 'findings') p.set('tab', state.tab);
|
|
105
|
+
if (state.sev) p.set('sev', state.sev);
|
|
106
|
+
if (state.cat) p.set('cat', state.cat);
|
|
107
|
+
if (state.q) p.set('q', state.q);
|
|
108
|
+
if (state.sel) p.set('f', state.sel);
|
|
109
|
+
try { history.replaceState(null, '', p.toString() ? '#' + p.toString() : location.pathname + location.search); } catch (e) { /* not allowed in this viewer */ }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var wide = matchMedia('(min-width: 1101px)');
|
|
113
|
+
|
|
114
|
+
/* ---------- the record ---------- */
|
|
115
|
+
function renderHeader() {
|
|
116
|
+
var crumb = $('crumb');
|
|
117
|
+
crumb.append(h('b', { text: R.repo.name, translate: 'no' }));
|
|
118
|
+
if (R.repo.head) crumb.append(h('span', { text: (R.repo.branch ? R.repo.branch + ' @ ' : '') + R.repo.head, translate: 'no' }));
|
|
119
|
+
document.title = R.verdict.label + ': ' + R.repo.name + ' (Prepublic)';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function renderFields() {
|
|
123
|
+
var w = R.coverage.worktree, hi = R.coverage.history, gl = R.coverage.gitleaks || {};
|
|
124
|
+
var d = new Date(R.generatedAt);
|
|
125
|
+
var when = isNaN(d) ? R.generatedAt : new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(d);
|
|
126
|
+
var fields = [
|
|
127
|
+
['Repository', R.repo.name],
|
|
128
|
+
['Revision', R.repo.head ? (R.repo.branch ? R.repo.branch + ' @ ' : '') + R.repo.head : 'No commits yet'],
|
|
129
|
+
['Inspected', plural(w.files, 'file') + (hi.enabled ? ', ' + plural(hi.commitsScanned, 'commit') : '')],
|
|
130
|
+
['Engines', gl.ran ? 'Built-in + Gitleaks ' + gl.version : 'Built-in rules'],
|
|
131
|
+
['Issued', when],
|
|
132
|
+
];
|
|
133
|
+
var dl = $('fields');
|
|
134
|
+
fields.forEach(function (f) { dl.append(h('div', null, h('dt', { text: f[0] }), h('dd', { text: f[1], title: f[1], translate: 'no' }))); });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function renderVerdict() {
|
|
138
|
+
var v = R.verdict;
|
|
139
|
+
var stamp = { blocked: ['Not cleared', 's-critical'], review: ['Review required', 's-medium'], clear: ['No blockers found', 's-pass'] }[v.level];
|
|
140
|
+
var lede;
|
|
141
|
+
if (v.level === 'blocked') {
|
|
142
|
+
lede = [h('b', { text: plural(v.blockers, 'issue') }), v.blockers === 1 ? ' blocks' : ' block', ' publication',
|
|
143
|
+
v.toReview ? [' and ', h('b', { text: n(v.toReview) }), ' more ', v.toReview === 1 ? 'needs' : 'need', ' a decision.'] : '.',
|
|
144
|
+
' Fix them before this repository goes public.'];
|
|
145
|
+
} else if (v.level === 'review') {
|
|
146
|
+
lede = ['Nothing blocks publication, but ', h('b', { text: plural(v.toReview, 'finding') }), v.toReview === 1 ? ' needs' : ' need', ' a decision first.'];
|
|
147
|
+
} else {
|
|
148
|
+
lede = ['Nothing in the tracked files or the Git history blocks publication. Finish the manual steps in the checklist, then publish.'];
|
|
149
|
+
}
|
|
150
|
+
$('verdict').append(
|
|
151
|
+
h('p', { class: 'stamp ' + stamp[1] }, icon(I.stamp[v.level]), stamp[0].toUpperCase()),
|
|
152
|
+
h('h1', { id: 'verdict-title', text: v.label }),
|
|
153
|
+
h('p', { class: 'lede' }, lede));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function renderGauge() {
|
|
157
|
+
var auto = R.checklist.filter(function (c) { return c.status !== 'manual'; });
|
|
158
|
+
var manual = R.checklist.length - auto.length;
|
|
159
|
+
var counts = { pass: 0, warn: 0, fail: 0, skipped: 0 };
|
|
160
|
+
auto.forEach(function (c) { counts[c.status]++; });
|
|
161
|
+
var order = ['pass', 'warn', 'fail', 'skipped'];
|
|
162
|
+
var sorted = auto.slice().sort(function (a, b) { return order.indexOf(a.status) - order.indexOf(b.status); });
|
|
163
|
+
$('gauge').append(
|
|
164
|
+
h('div', { class: 'gauge-top' },
|
|
165
|
+
h('b', null, String(counts.pass), h('small', { text: ' of ' + auto.length + ' checks pass' })),
|
|
166
|
+
h('span', { text: manual ? plural(manual, 'manual step') + ' left' : '' })),
|
|
167
|
+
h('div', { class: 'segments', role: 'img', 'aria-label': counts.pass + ' of ' + auto.length + ' automated checks passed' },
|
|
168
|
+
sorted.map(function (c) { return h('i', { class: 's-' + c.status, title: c.label + ': ' + STATUS_LABEL[c.status] }); })),
|
|
169
|
+
h('div', { class: 'gauge-legend' }, order.filter(function (s) { return counts[s]; }).map(function (s) {
|
|
170
|
+
return h('span', { class: 's-' + s }, h('i', { 'aria-hidden': 'true' }), h('em', { text: STATUS_LABEL[s] + ' ' + counts[s] }));
|
|
171
|
+
})),
|
|
172
|
+
h('p', { class: 'gauge-score', text: 'Readiness score ' + R.score + ' of 100' }));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* ---------- exposure ledger: one mark per finding ---------- */
|
|
176
|
+
var ledgerEl = $('ledger');
|
|
177
|
+
function renderLegend() {
|
|
178
|
+
var box = $('legend');
|
|
179
|
+
box.textContent = '';
|
|
180
|
+
SEV.forEach(function (s) {
|
|
181
|
+
var c = R.counts[s];
|
|
182
|
+
box.append(h('button', { type: 'button', class: 'sevbtn' + (c ? '' : ' zero'), 'aria-pressed': state.sev === s ? 'true' : 'false', disabled: c ? null : true,
|
|
183
|
+
onclick: function () { setFilter(state.sev === s ? null : s, state.cat); } },
|
|
184
|
+
h('span', { class: 's-' + s, html: GLYPH[s] }), SEV_LABEL[s], h('b', { text: String(c) })));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function renderLedger() {
|
|
188
|
+
ledgerEl.textContent = '';
|
|
189
|
+
if (!R.findings.length) $('ledger-hint').textContent = 'All six categories were checked and came back clear.';
|
|
190
|
+
CATS.forEach(function (cat) {
|
|
191
|
+
var items = R.findings.filter(function (f) { return f.category === cat; });
|
|
192
|
+
var label = CAT_SHORT[cat] || R.categories[cat].label;
|
|
193
|
+
var marks = h('div', { class: 'marks' });
|
|
194
|
+
if (!items.length) marks.append(h('span', { class: 'clear' }, icon(I.checkSm), 'Clear'));
|
|
195
|
+
items.forEach(function (f) {
|
|
196
|
+
marks.append(h('button', { type: 'button', class: 'mk c-' + f.severity + (reviewed[f.id] ? ' reviewed' : ''), 'data-id': f.id,
|
|
197
|
+
'aria-current': state.sel === f.id ? 'true' : 'false', 'aria-label': SEV_LABEL[f.severity] + ': ' + f.title, title: SEV_LABEL[f.severity] + ' · ' + f.title,
|
|
198
|
+
onclick: function () { openFinding(f.id); } }));
|
|
199
|
+
});
|
|
200
|
+
ledgerEl.append(h('div', { class: 'lrow', role: 'listitem' },
|
|
201
|
+
h('button', { type: 'button', class: 'lcat', 'aria-pressed': state.cat === cat ? 'true' : 'false', title: R.categories[cat].blurb,
|
|
202
|
+
onclick: function () { setFilter(state.sev, state.cat === cat ? null : cat); } }, h('span', { text: label })),
|
|
203
|
+
marks,
|
|
204
|
+
h('span', { class: 'lcount', 'aria-label': plural(items.length, 'finding'), text: String(items.length) })));
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function introLedger() {
|
|
208
|
+
if (reduceMotion) return;
|
|
209
|
+
var marks = ledgerEl.querySelectorAll('.mk');
|
|
210
|
+
if (!marks.length) return;
|
|
211
|
+
ledgerEl.classList.add('intro');
|
|
212
|
+
marks.forEach(function (m, i) { m.style.transitionDelay = Math.min(i * 22, 600) + 'ms'; });
|
|
213
|
+
requestAnimationFrame(function () { requestAnimationFrame(function () { ledgerEl.classList.remove('intro'); }); });
|
|
214
|
+
setTimeout(function () { marks.forEach(function (m) { m.style.transitionDelay = ''; }); }, 1100);
|
|
215
|
+
}
|
|
216
|
+
function setFilter(sev, cat) {
|
|
217
|
+
state.sev = sev; state.cat = cat; state.ids = null; state.idsLabel = '';
|
|
218
|
+
setTab('findings');
|
|
219
|
+
update();
|
|
220
|
+
}
|
|
221
|
+
function openFinding(id) {
|
|
222
|
+
state.ids = null; state.idsLabel = '';
|
|
223
|
+
var f = byId(id);
|
|
224
|
+
if (f && !matches(f)) { state.sev = null; state.cat = null; state.q = ''; state.hide = false; $('q').value = ''; $('hide-reviewed').checked = false; }
|
|
225
|
+
state.sel = id;
|
|
226
|
+
setTab('findings');
|
|
227
|
+
update();
|
|
228
|
+
var row = document.querySelector('#list .row[data-id="' + id + '"]');
|
|
229
|
+
if (row) {
|
|
230
|
+
row.focus({ preventScroll: true });
|
|
231
|
+
(wide.matches ? $('main') : row).scrollIntoView({ behavior: reduceMotion ? 'auto' : 'smooth', block: 'start' });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/* ---------- tabs ---------- */
|
|
236
|
+
var TABS = [['findings', 'Findings', String(R.findings.length)], ['checklist', 'Checklist', null], ['coverage', 'Coverage', null]];
|
|
237
|
+
function renderTabs() {
|
|
238
|
+
var auto = R.checklist.filter(function (c) { return c.status !== 'manual'; });
|
|
239
|
+
TABS[1][2] = auto.filter(function (c) { return c.status === 'pass'; }).length + '/' + auto.length;
|
|
240
|
+
var tl = $('tabs');
|
|
241
|
+
TABS.forEach(function (t, i) {
|
|
242
|
+
tl.append(h('button', { type: 'button', role: 'tab', id: 'tab-' + t[0], class: 'tab', 'aria-controls': 'panel-' + t[0], 'aria-selected': state.tab === t[0] ? 'true' : 'false', tabindex: state.tab === t[0] ? '0' : '-1',
|
|
243
|
+
onclick: function () { setTab(t[0]); writeHash(); },
|
|
244
|
+
onkeydown: function (e) {
|
|
245
|
+
if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return;
|
|
246
|
+
var next = TABS[(i + (e.key === 'ArrowRight' ? 1 : TABS.length - 1)) % TABS.length][0];
|
|
247
|
+
setTab(next); writeHash(); $('tab-' + next).focus();
|
|
248
|
+
} }, t[1], t[2] != null ? h('span', { text: t[2] }) : null));
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function setTab(name) {
|
|
252
|
+
state.tab = name;
|
|
253
|
+
TABS.forEach(function (t) {
|
|
254
|
+
var on = t[0] === name;
|
|
255
|
+
var b = $('tab-' + t[0]);
|
|
256
|
+
b.setAttribute('aria-selected', on ? 'true' : 'false');
|
|
257
|
+
b.tabIndex = on ? 0 : -1;
|
|
258
|
+
$('panel-' + t[0]).hidden = !on;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* ---------- findings ---------- */
|
|
263
|
+
function matches(f) {
|
|
264
|
+
if (state.ids && state.ids.indexOf(f.id) === -1) return false;
|
|
265
|
+
if (state.sev && f.severity !== state.sev) return false;
|
|
266
|
+
if (state.cat && f.category !== state.cat) return false;
|
|
267
|
+
if (state.hide && reviewed[f.id]) return false;
|
|
268
|
+
if (state.q) {
|
|
269
|
+
var hay = (f.title + ' ' + f.summary + ' ' + f.ruleId + ' ' + f.locations.map(locText).join(' ')).toLowerCase();
|
|
270
|
+
if (hay.indexOf(state.q.toLowerCase()) === -1) return false;
|
|
271
|
+
}
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
function byId(id) { for (var i = 0; i < R.findings.length; i++) if (R.findings[i].id === id) return R.findings[i]; return null; }
|
|
275
|
+
|
|
276
|
+
function renderFilters(shown) {
|
|
277
|
+
var box = $('filters');
|
|
278
|
+
box.textContent = '';
|
|
279
|
+
var chips = [];
|
|
280
|
+
function chip(label, clear) { chips.push(h('button', { type: 'button', class: 'chip', 'aria-label': 'Remove filter: ' + label, onclick: function () { clear(); update(); } }, label, icon(I.x))); }
|
|
281
|
+
if (state.ids) chip(state.idsLabel, function () { state.ids = null; state.idsLabel = ''; });
|
|
282
|
+
if (state.sev) chip(SEV_LABEL[state.sev], function () { state.sev = null; });
|
|
283
|
+
if (state.cat) chip(CAT_SHORT[state.cat] || state.cat, function () { state.cat = null; });
|
|
284
|
+
if (state.q) chip('“' + state.q + '”', function () { state.q = ''; $('q').value = ''; });
|
|
285
|
+
if (state.hide) chip('Reviewed hidden', function () { state.hide = false; $('hide-reviewed').checked = false; });
|
|
286
|
+
if (chips.length > 1) chips.push(h('button', { type: 'button', class: 'chip clearall', onclick: clearAll }, 'Clear all'));
|
|
287
|
+
chips.forEach(function (c) { box.appendChild(c); });
|
|
288
|
+
var done = R.findings.filter(function (f) { return reviewed[f.id]; }).length;
|
|
289
|
+
$('result-count').textContent = (shown.length === R.findings.length ? plural(shown.length, 'finding') : 'Showing ' + n(shown.length) + ' of ' + plural(R.findings.length, 'finding')) + ', ' + n(done) + ' reviewed';
|
|
290
|
+
}
|
|
291
|
+
function clearAll() {
|
|
292
|
+
state.sev = null; state.cat = null; state.q = ''; state.hide = false; state.ids = null; state.idsLabel = '';
|
|
293
|
+
$('q').value = ''; $('hide-reviewed').checked = false;
|
|
294
|
+
update();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function renderList(shown) {
|
|
298
|
+
var list = $('list');
|
|
299
|
+
list.textContent = '';
|
|
300
|
+
if (!shown.length) {
|
|
301
|
+
list.append(R.findings.length
|
|
302
|
+
? h('div', { class: 'empty filtered' }, h('h3', { text: 'No findings match these filters' }), h('p', { text: 'Remove a filter or clear them all to see every finding.' }), h('button', { type: 'button', class: 'btn', onclick: clearAll }, 'Clear filters'))
|
|
303
|
+
: h('div', { class: 'empty' }, h('h3', { text: 'Nothing to fix' }),
|
|
304
|
+
h('p', { text: 'Prepublic checked every tracked file and the full local history and found nothing to flag. ' + (function () { var m = R.checklist.filter(function (c) { return c.status === 'manual'; }).length; return m ? plural(m, 'manual step') + (m === 1 ? ' is' : ' are') + ' still yours to confirm before you publish.' : 'Review the coverage notes before you publish.'; })() }),
|
|
305
|
+
h('button', { type: 'button', class: 'btn', onclick: function () { setTab('checklist'); writeHash(); } }, 'Open the checklist')));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
CATS.forEach(function (cat) {
|
|
309
|
+
var items = shown.filter(function (f) { return f.category === cat; });
|
|
310
|
+
if (!items.length) return;
|
|
311
|
+
var ul = h('ul', { class: 'rows' });
|
|
312
|
+
items.forEach(function (f) { ul.append(renderRow(f)); });
|
|
313
|
+
list.append(h('section', { class: 'group', 'aria-label': R.categories[cat].label }, h('h3', null, R.categories[cat].label, h('span', { text: String(items.length) })), ul));
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function renderRow(f) {
|
|
318
|
+
var where = f.locations.length ? locText(f.locations[0]) + (f.totalLocations > 1 ? ' +' + (f.totalLocations - 1) : '') : R.categories[f.category].label;
|
|
319
|
+
var selected = state.sel === f.id;
|
|
320
|
+
var flags = [];
|
|
321
|
+
if (f.inHistory) flags.push(h('span', { class: 'flag hot', text: 'In history' }));
|
|
322
|
+
if (f.confirmedBy) flags.push(h('span', { class: 'flag ok', text: 'Gitleaks agrees' }));
|
|
323
|
+
if (f.source === 'gitleaks') flags.push(h('span', { class: 'flag', text: 'Gitleaks' }));
|
|
324
|
+
var btn = h('button', { type: 'button', class: 'row c-' + f.severity + (reviewed[f.id] ? ' is-reviewed' : ''), 'data-id': f.id,
|
|
325
|
+
'aria-current': selected ? 'true' : 'false', 'aria-expanded': wide.matches ? null : (selected ? 'true' : 'false'),
|
|
326
|
+
onclick: function () { select(state.sel === f.id && !wide.matches ? null : f.id, true); },
|
|
327
|
+
onkeydown: rowKeys },
|
|
328
|
+
h('span', { class: 's-' + f.severity, title: SEV_LABEL[f.severity], html: GLYPH[f.severity] }),
|
|
329
|
+
h('span', { class: 'row-main' }, h('span', { class: 'row-title', text: f.title }), h('span', { class: 'row-where', text: where, translate: 'no' }), h('span', { class: 'sr-only', text: ', ' + SEV_LABEL[f.severity] + (reviewed[f.id] ? ', reviewed' : '') })),
|
|
330
|
+
h('span', { class: 'row-side' }, flags, reviewed[f.id] ? icon(I.check) : null));
|
|
331
|
+
var li = h('li', null, btn);
|
|
332
|
+
if (selected && !wide.matches) li.append(h('div', { class: 'inline-detail' }, renderDetail(f)));
|
|
333
|
+
return li;
|
|
334
|
+
}
|
|
335
|
+
function rowKeys(e) {
|
|
336
|
+
var k = e.key;
|
|
337
|
+
if (k !== 'ArrowDown' && k !== 'ArrowUp' && k !== 'j' && k !== 'k') return;
|
|
338
|
+
e.preventDefault();
|
|
339
|
+
var rows = Array.prototype.slice.call(document.querySelectorAll('#list .row'));
|
|
340
|
+
var i = rows.indexOf(e.currentTarget) + (k === 'ArrowDown' || k === 'j' ? 1 : -1);
|
|
341
|
+
if (i < 0 || i >= rows.length) return;
|
|
342
|
+
var id = rows[i].getAttribute('data-id');
|
|
343
|
+
if (wide.matches) select(id, false);
|
|
344
|
+
var target = document.querySelector('#list .row[data-id="' + id + '"]');
|
|
345
|
+
if (target) target.focus();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function select(id, fromClick) {
|
|
349
|
+
state.sel = id;
|
|
350
|
+
writeHash();
|
|
351
|
+
renderList(R.findings.filter(matches));
|
|
352
|
+
renderSide(true);
|
|
353
|
+
markCurrent();
|
|
354
|
+
if (fromClick && id) {
|
|
355
|
+
var row = document.querySelector('#list .row[data-id="' + id + '"]');
|
|
356
|
+
if (row) row.focus({ preventScroll: true });
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function markCurrent() {
|
|
360
|
+
ledgerEl.querySelectorAll('.mk').forEach(function (m) { m.setAttribute('aria-current', m.getAttribute('data-id') === state.sel ? 'true' : 'false'); });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function renderSide(animate) {
|
|
364
|
+
var panel = $('detail');
|
|
365
|
+
panel.textContent = '';
|
|
366
|
+
var f = wide.matches && state.sel && byId(state.sel);
|
|
367
|
+
panel.parentElement.classList.toggle('solo', !f);
|
|
368
|
+
panel.className = 'detail' + (f ? ' c-' + f.severity : '');
|
|
369
|
+
if (!f) return;
|
|
370
|
+
var d = renderDetail(f);
|
|
371
|
+
if (animate && !reduceMotion) d.classList.add('d-enter');
|
|
372
|
+
panel.append(d);
|
|
373
|
+
panel.scrollTop = 0;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function renderDetail(f) {
|
|
377
|
+
var cat = R.categories[f.category];
|
|
378
|
+
var d = h('article', { class: 'd c-' + f.severity, 'aria-labelledby': 'dt-' + f.id });
|
|
379
|
+
d.append(h('header', null,
|
|
380
|
+
h('div', { class: 'd-meta' },
|
|
381
|
+
h('span', { class: 'sev' }, icon(GLYPH[f.severity]), SEV_LABEL[f.severity]),
|
|
382
|
+
h('span', { text: cat.label }),
|
|
383
|
+
f.confidence !== 'high' ? h('span', { text: f.confidence === 'medium' ? 'Medium confidence' : 'Low confidence' }) : null,
|
|
384
|
+
f.inHistory ? h('span', { class: 's-critical', text: 'Also in Git history' }) : null,
|
|
385
|
+
f.confirmedBy ? h('span', { class: 's-pass', text: 'Confirmed by Gitleaks' }) : null),
|
|
386
|
+
h('h2', { id: 'dt-' + f.id, text: f.title }),
|
|
387
|
+
h('p', { class: 'd-summary', text: f.summary })));
|
|
388
|
+
|
|
389
|
+
if (f.evidence.length) {
|
|
390
|
+
d.append(h('section', null, h('h3', { text: 'Evidence' }),
|
|
391
|
+
h('pre', { class: 'evidence', translate: 'no' }, f.evidence.map(function (e, i) { return [evidence(e), i < f.evidence.length - 1 ? '\n' : '']; }))));
|
|
392
|
+
}
|
|
393
|
+
if (f.actions.length) d.append(h('section', null, h('h3', { text: 'How to fix it' }), h('ol', null, f.actions.map(function (a) { return h('li', null, h('span', null, rich(a))); }))));
|
|
394
|
+
if (f.commands.length) {
|
|
395
|
+
var cmd = f.commands.join('\n');
|
|
396
|
+
d.append(h('section', null, h('h3', { text: f.commands.length > 1 ? 'Commands' : 'Command' }),
|
|
397
|
+
h('pre', { class: 'cmd', translate: 'no' }, h('code', { text: cmd }), h('button', { type: 'button', class: 'btn', onclick: function () { copy(cmd); } }, 'Copy'))));
|
|
398
|
+
}
|
|
399
|
+
if (f.locations.length) {
|
|
400
|
+
var hasLine = f.locations.some(function (l) { return l.line; });
|
|
401
|
+
var hasCommit = f.locations.some(function (l) { return l.commit; });
|
|
402
|
+
var hasNote = f.locations.some(function (l) { return l.note; });
|
|
403
|
+
var shownLocs = f.locations.slice(0, 12);
|
|
404
|
+
d.append(h('section', null, h('h3', { text: 'Where' }),
|
|
405
|
+
h('table', { class: 'locs' },
|
|
406
|
+
h('thead', null, h('tr', null, h('th', { scope: 'col', text: 'Path' }), hasLine ? h('th', { scope: 'col', text: 'Line' }) : null, hasCommit ? h('th', { scope: 'col', text: 'Commit' }) : null, hasNote ? h('th', { scope: 'col', text: 'Note' }) : null)),
|
|
407
|
+
h('tbody', null, shownLocs.map(function (l) {
|
|
408
|
+
return h('tr', null, h('td', { text: l.path, translate: 'no' }), hasLine ? h('td', { class: 'n', text: l.line ? String(l.line) : '' }) : null,
|
|
409
|
+
hasCommit ? h('td', { class: 'n', text: l.commit || '' }) : null, hasNote ? h('td', { class: 'n', text: l.note || '' }) : null);
|
|
410
|
+
}))),
|
|
411
|
+
f.totalLocations > shownLocs.length ? h('p', { class: 'locs-more', text: n(f.totalLocations - shownLocs.length) + ' more in the JSON export.' }) : null));
|
|
412
|
+
}
|
|
413
|
+
if (f.why) d.append(h('section', null, h('h3', { text: 'Why it matters' }), h('p', null, rich(f.why))));
|
|
414
|
+
if (f.references.length) {
|
|
415
|
+
d.append(h('section', null, h('h3', { text: 'Learn more' }), h('div', { class: 'refs' }, f.references.map(function (r) {
|
|
416
|
+
return h('a', { href: r.url, target: '_blank', rel: 'noopener noreferrer' }, r.label, icon(I.ext));
|
|
417
|
+
}))));
|
|
418
|
+
}
|
|
419
|
+
var rb = h('button', { type: 'button', class: 'btn review-btn', 'aria-pressed': reviewed[f.id] ? 'true' : 'false', onclick: function () {
|
|
420
|
+
if (reviewed[f.id]) delete reviewed[f.id]; else reviewed[f.id] = 1;
|
|
421
|
+
save(reviewKey, reviewed);
|
|
422
|
+
rb.setAttribute('aria-pressed', reviewed[f.id] ? 'true' : 'false');
|
|
423
|
+
rb.lastChild.textContent = reviewed[f.id] ? 'Reviewed' : 'Mark as reviewed';
|
|
424
|
+
toast(reviewed[f.id] ? 'Marked as reviewed' : 'Marked as not reviewed');
|
|
425
|
+
var shown = R.findings.filter(matches);
|
|
426
|
+
renderList(shown); renderFilters(shown); renderLedger(); markCurrent();
|
|
427
|
+
} }, icon(I.checkSm), h('span', { text: reviewed[f.id] ? 'Reviewed' : 'Mark as reviewed' }));
|
|
428
|
+
d.append(h('footer', { class: 'd-foot' }, h('span', { class: 'rule', text: f.ruleId, translate: 'no' }), rb));
|
|
429
|
+
return d;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/* Redacted values render as solid marks: the value is gone, its place is kept. */
|
|
433
|
+
function evidence(text) {
|
|
434
|
+
var out = [];
|
|
435
|
+
var re = /‹redacted:([a-z0-9-]+)›/g;
|
|
436
|
+
var last = 0, m;
|
|
437
|
+
while ((m = re.exec(text))) {
|
|
438
|
+
out.push(text.slice(last, m.index));
|
|
439
|
+
out.push(h('span', { class: 'redact', role: 'img', 'aria-label': 'redacted ' + m[1].replace(/-/g, ' '), title: 'Value removed (' + m[1] + ')' }));
|
|
440
|
+
last = re.lastIndex;
|
|
441
|
+
}
|
|
442
|
+
out.push(text.slice(last));
|
|
443
|
+
return out;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/* ---------- checklist & coverage ---------- */
|
|
447
|
+
function renderChecklist() {
|
|
448
|
+
var panel = $('panel-checklist');
|
|
449
|
+
var auto = R.checklist.filter(function (c) { return c.status !== 'manual'; });
|
|
450
|
+
var manual = R.checklist.filter(function (c) { return c.status === 'manual'; });
|
|
451
|
+
function list(items) {
|
|
452
|
+
return h('ul', { class: 'checks' }, items.map(function (c) {
|
|
453
|
+
var related = c.related && c.related.length;
|
|
454
|
+
return h('li', null,
|
|
455
|
+
h('span', { class: 's-' + c.status, html: ST[c.status] }),
|
|
456
|
+
h('div', null, h('span', { class: 'lbl', text: c.label }), h('span', { class: 'det', text: c.detail || '' }),
|
|
457
|
+
related ? h('button', { type: 'button', class: 'linkbtn', onclick: function () {
|
|
458
|
+
state.ids = c.related; state.idsLabel = c.label; state.sev = null; state.cat = null;
|
|
459
|
+
setTab('findings'); update(); $('main').focus({ preventScroll: true });
|
|
460
|
+
} }, 'Show ' + plural(c.related.length, 'finding')) : null),
|
|
461
|
+
h('span', { class: 'stw s-' + c.status, text: STATUS_LABEL[c.status] }));
|
|
462
|
+
}));
|
|
463
|
+
}
|
|
464
|
+
panel.append(h('div', { class: 'cols2' },
|
|
465
|
+
h('div', null, h('h2', { class: 'sub', text: 'Automated checks' }), h('p', { class: 'sub', text: 'What Prepublic verified in this scan.' }), list(auto)),
|
|
466
|
+
h('div', null, h('h2', { class: 'sub', text: 'Before you publish' }), h('p', { class: 'sub', text: 'Steps no scanner can take for you.' }), list(manual))));
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function renderCoverage() {
|
|
470
|
+
var w = R.coverage.worktree, hi = R.coverage.history, gl = R.coverage.gitleaks || {};
|
|
471
|
+
var facts = [
|
|
472
|
+
['Tracked files', n(w.files) + ' inspected, ' + n(w.textFiles) + ' content-scanned (' + bytes(w.bytes) + ')'],
|
|
473
|
+
['Skipped content', n(w.binary) + ' binary, ' + n(w.skippedLarge) + ' over ' + Math.round(w.maxFileBytes / 1048576) + ' MB' + (w.symlinks ? ', ' + plural(w.symlinks, 'symlink') : '')],
|
|
474
|
+
['Untracked files', plural(w.untracked, 'file') + ' checked by name only'],
|
|
475
|
+
['Git history', hi.enabled ? n(hi.commitsScanned) + ' of ' + plural(hi.commits, 'commit') + ' on ' + plural(hi.refs, 'ref') + ', ' + bytes(hi.patchBytes) + ' of patches' + (hi.truncated ? ' (stopped early)' : '') : 'Not scanned'],
|
|
476
|
+
['Secret engines', 'Built-in rules' + (gl.ran ? ' and Gitleaks ' + gl.version : '; Gitleaks ' + (gl.mode === 'off' ? 'disabled' : (gl.error || 'did not run')))],
|
|
477
|
+
['Suppressions', R.suppressed.config ? R.suppressed.config + ': ' + plural(R.suppressed.paths, 'path') + ', ' + plural(R.suppressed.rules, 'finding') : 'None'],
|
|
478
|
+
['Duration', (R.durationMs / 1000).toFixed(1) + ' s, read-only, offline'],
|
|
479
|
+
];
|
|
480
|
+
var dl = h('dl', { class: 'facts' });
|
|
481
|
+
facts.forEach(function (f) { dl.append(h('dt', { text: f[0] }), h('dd', { text: f[1] })); });
|
|
482
|
+
$('panel-coverage').append(h('div', { class: 'cols2' },
|
|
483
|
+
h('div', null, h('h2', { class: 'sub', text: 'What was scanned' }), h('p', { class: 'sub', text: 'Everything ran on this machine. Nothing was sent anywhere.' }), dl),
|
|
484
|
+
h('div', null, h('h2', { class: 'sub', text: 'Limitations' }), h('p', { class: 'sub', text: 'A clean result is not a guarantee. Keep these in mind.' }), h('ul', { class: 'limits' }, R.limitations.map(function (l) { return h('li', { text: l }); })))));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function renderFooter() {
|
|
488
|
+
$('foot').append(icon(I.mark),
|
|
489
|
+
h('span', { text: 'Prepublic ' + R.tool.version + '. Generated locally; this page makes no network requests.' }),
|
|
490
|
+
h('span', { text: 'Secret values are never included. Personal paths and emails are masked.' }));
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/* ---------- updates ---------- */
|
|
494
|
+
function update() {
|
|
495
|
+
var shown = R.findings.filter(matches);
|
|
496
|
+
if (wide.matches && (!state.sel || !shown.some(function (f) { return f.id === state.sel; }))) state.sel = shown.length ? shown[0].id : null;
|
|
497
|
+
writeHash();
|
|
498
|
+
renderLegend();
|
|
499
|
+
ledgerEl.querySelectorAll('.lcat').forEach(function (b, i) { b.setAttribute('aria-pressed', state.cat === CATS[i] ? 'true' : 'false'); });
|
|
500
|
+
markCurrent();
|
|
501
|
+
renderFilters(shown);
|
|
502
|
+
renderList(shown);
|
|
503
|
+
renderSide(false);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/* ---------- export, copy, toast ---------- */
|
|
507
|
+
var toastTimer;
|
|
508
|
+
function toast(msg) {
|
|
509
|
+
var t = $('toast'); t.textContent = msg; t.classList.add('show');
|
|
510
|
+
clearTimeout(toastTimer); toastTimer = setTimeout(function () { t.classList.remove('show'); }, 1800);
|
|
511
|
+
}
|
|
512
|
+
function copy(text) {
|
|
513
|
+
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(text).then(function () { toast('Copied to clipboard'); }, function () { toast('Copy failed. Select the text instead.'); });
|
|
514
|
+
else toast('Copy is unavailable here. Select the text instead.');
|
|
515
|
+
}
|
|
516
|
+
function download(name, type, text) {
|
|
517
|
+
var a = h('a', { href: URL.createObjectURL(new Blob([text], { type: type })), download: name });
|
|
518
|
+
document.body.append(a); a.click(); a.remove();
|
|
519
|
+
setTimeout(function () { URL.revokeObjectURL(a.href); }, 1000);
|
|
520
|
+
toast('Saved ' + name);
|
|
521
|
+
}
|
|
522
|
+
var fileBase = 'prepublic-' + R.repo.name.replace(/[^\w.-]+/g, '-') + '-' + R.generatedAt.slice(0, 10);
|
|
523
|
+
var menuBtn = $('export'), menu = $('export-menu');
|
|
524
|
+
function closeMenu(focus) { menu.hidden = true; menuBtn.setAttribute('aria-expanded', 'false'); if (focus) menuBtn.focus(); }
|
|
525
|
+
menuBtn.addEventListener('click', function () {
|
|
526
|
+
var open = menu.hidden;
|
|
527
|
+
menu.hidden = !open; menuBtn.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
528
|
+
if (open) menu.querySelector('button').focus();
|
|
529
|
+
});
|
|
530
|
+
menu.addEventListener('keydown', function (e) {
|
|
531
|
+
var items = Array.prototype.slice.call(menu.querySelectorAll('button'));
|
|
532
|
+
var i = items.indexOf(document.activeElement);
|
|
533
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); items[(i + 1) % items.length].focus(); }
|
|
534
|
+
if (e.key === 'ArrowUp') { e.preventDefault(); items[(i - 1 + items.length) % items.length].focus(); }
|
|
535
|
+
if (e.key === 'Escape') closeMenu(true);
|
|
536
|
+
});
|
|
537
|
+
document.addEventListener('click', function (e) { if (!menu.hidden && !e.target.closest('.menu-wrap')) closeMenu(false); });
|
|
538
|
+
menu.addEventListener('click', function (e) {
|
|
539
|
+
var b = e.target.closest('button[data-export]');
|
|
540
|
+
if (!b) return;
|
|
541
|
+
closeMenu(false);
|
|
542
|
+
var kind = b.getAttribute('data-export');
|
|
543
|
+
if (kind === 'md') download(fileBase + '.md', 'text/markdown', payload.markdown);
|
|
544
|
+
else if (kind === 'json') download(fileBase + '.json', 'application/json', JSON.stringify(R, null, 2));
|
|
545
|
+
else window.print();
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
/* Print: paper theme, every finding expanded. */
|
|
549
|
+
var printTheme = null;
|
|
550
|
+
window.addEventListener('beforeprint', function () {
|
|
551
|
+
printTheme = theme; applyTheme('light');
|
|
552
|
+
var list = $('list');
|
|
553
|
+
list.textContent = '';
|
|
554
|
+
CATS.forEach(function (cat) {
|
|
555
|
+
var items = R.findings.filter(function (f) { return f.category === cat; });
|
|
556
|
+
if (!items.length) return;
|
|
557
|
+
list.append(h('section', { class: 'group' }, h('h3', null, R.categories[cat].label, h('span', { text: String(items.length) })), items.map(renderDetail)));
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
window.addEventListener('afterprint', function () { if (printTheme) applyTheme(printTheme); update(); });
|
|
561
|
+
|
|
562
|
+
/* ---------- global keys ---------- */
|
|
563
|
+
document.addEventListener('keydown', function (e) {
|
|
564
|
+
if (e.key === '/' && !/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName)) {
|
|
565
|
+
e.preventDefault(); setTab('findings'); $('q').focus();
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
var q = $('q');
|
|
569
|
+
q.value = state.q;
|
|
570
|
+
var qTimer;
|
|
571
|
+
q.addEventListener('input', function () { clearTimeout(qTimer); qTimer = setTimeout(function () { state.q = q.value.trim(); update(); }, 80); });
|
|
572
|
+
q.addEventListener('keydown', function (e) { if (e.key === 'Escape' && q.value) { q.value = ''; state.q = ''; update(); } });
|
|
573
|
+
$('hide-reviewed').addEventListener('change', function (e) { state.hide = e.target.checked; update(); });
|
|
574
|
+
wide.addEventListener('change', function () { update(); });
|
|
575
|
+
|
|
576
|
+
/* ---------- boot ---------- */
|
|
577
|
+
renderHeader();
|
|
578
|
+
renderFields();
|
|
579
|
+
renderVerdict();
|
|
580
|
+
renderGauge();
|
|
581
|
+
renderLedger();
|
|
582
|
+
renderTabs();
|
|
583
|
+
renderChecklist();
|
|
584
|
+
renderCoverage();
|
|
585
|
+
renderFooter();
|
|
586
|
+
setTab(state.tab);
|
|
587
|
+
if (!wide.matches && state.sel && !byId(state.sel)) state.sel = null;
|
|
588
|
+
update();
|
|
589
|
+
introLedger();
|
|
590
|
+
})();
|