@snapwonders/report 0.0.0-stage → 0.2.1
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/LICENSE +37 -0
- package/README.md +205 -2
- package/dist/snapwonders-report.js +1061 -0
- package/package.json +45 -4
- package/src/element.js +501 -0
- package/src/index.js +24 -0
- package/src/model.js +566 -0
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snapwonders/report",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Draws a snapWONDERS forensic analysis result as a card — a dependency-free web component for the snapWONDERS API.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js",
|
|
9
|
+
"./model": "./src/model.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "node scripts/build.mjs",
|
|
22
|
+
"test": "node --test",
|
|
23
|
+
"prepack": "node scripts/build.mjs"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"snapwonders",
|
|
27
|
+
"forensics",
|
|
28
|
+
"image-forensics",
|
|
29
|
+
"media-analysis",
|
|
30
|
+
"ai-image-detection",
|
|
31
|
+
"content-credentials",
|
|
32
|
+
"c2pa",
|
|
33
|
+
"web-component",
|
|
34
|
+
"custom-element",
|
|
35
|
+
"report"
|
|
36
|
+
],
|
|
37
|
+
"author": "Kenneth Springer @ snapWONDERS <kenneth@snapwonders.com> (https://kennethbspringer.au)",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"homepage": "https://snapwonders.com/developers",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/snapWONDERS/snapWONDERS-Report.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/snapWONDERS/snapWONDERS-Report/issues"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/element.js
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* snapWONDERS API — Result renderer (JavaScript)
|
|
3
|
+
* API version: 1.0
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2026 Kenneth Springer @ snapWONDERS. MIT Licensed — see LICENSE.
|
|
6
|
+
* The MIT licence covers this client library only; the snapWONDERS API it calls is proprietary.
|
|
7
|
+
*
|
|
8
|
+
* Author: Kenneth Springer @ snapWONDERS <kenneth@snapwonders.com> (https://kennethbspringer.au)
|
|
9
|
+
*
|
|
10
|
+
* All the snapWONDERS API services are available over the Clearnet / **Web** and Dark Web **Tor** and **I2P**
|
|
11
|
+
* Read details: https://snapwonders.com/developers
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* <snapwonders-report> — draws one analyse result as a card.
|
|
16
|
+
*
|
|
17
|
+
* el.result = json; // the JSON from GET /api/analyse/result/{job_uid}
|
|
18
|
+
* <snapwonders-report report-url="…"> // adds "Open full report"
|
|
19
|
+
* <script type="application/json">{…}</script> // or the result inline (static pages)
|
|
20
|
+
* </snapwonders-report>
|
|
21
|
+
*
|
|
22
|
+
* Attributes: mode ("card" or "full"), report-url, file-index, link-params ("src=wp&site=…", added to the
|
|
23
|
+
* snapWONDERS links), check-another (adds a "Check another" button), hide-location (leaves out
|
|
24
|
+
* where the file was taken: set it on public pages unless the owner chose to show it),
|
|
25
|
+
* release-notes-url (where "See what's new" links when a result is newer than this renderer;
|
|
26
|
+
* the extension or plugin passes its own release notes, else the renderer's changelog).
|
|
27
|
+
* Property: assetUrl = (asset) => url — full mode only: where the host keeps each analysis image. The
|
|
28
|
+
* renderer makes no network calls of its own.
|
|
29
|
+
* dismissed-update (the result version whose update note the user dismissed; the host keeps it,
|
|
30
|
+
* e.g. in extension storage, so the note stays hidden for that version and returns on the next).
|
|
31
|
+
* Events: snapwonders-check-another; snapwonders-update-available (result newer than this renderer,
|
|
32
|
+
* detail { level: 'minor' | 'major', schemaVersion }); snapwonders-update-dismissed (detail
|
|
33
|
+
* { schemaVersion }: store it and pass it back as dismissed-update).
|
|
34
|
+
* Attribution and the snapWONDERS Vaultify link come from the result itself (schema 1.1) and are drawn
|
|
35
|
+
* only when they point at snapwonders.com; the renderer never adds a credit of its own.
|
|
36
|
+
* Theming: --sw-font, --sw-bg, --sw-text, --sw-muted, --sw-border, --sw-accent, --sw-radius.
|
|
37
|
+
*
|
|
38
|
+
* Every value is written with textContent — nothing from a result is ever parsed as HTML.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import { buildCardModel, DEFAULT_RELEASE_NOTES_URL, SOFTENED, WARNING_TAIL, PARTIAL_CARD, PARTIAL_FULL, MAP_LINK_TEXT } from './model.js';
|
|
42
|
+
|
|
43
|
+
// Grade colours, as on the report page
|
|
44
|
+
const GRADE_COLOURS = {
|
|
45
|
+
A: ['#dcfce7', '#166534', '#86efac'],
|
|
46
|
+
B: ['#ccfbf1', '#115e59', '#5eead4'],
|
|
47
|
+
C: ['#fef3c7', '#92400e', '#fcd34d'],
|
|
48
|
+
D: ['#ffedd5', '#9a3412', '#fdba74'],
|
|
49
|
+
F: ['#fee2e2', '#991b1b', '#fca5a5'],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const STYLES = `
|
|
53
|
+
:host { display: block; font-family: var(--sw-font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
|
|
54
|
+
color: var(--sw-text, #111827); max-width: 34rem; }
|
|
55
|
+
.card { background: var(--sw-bg, #fff); border: 1px solid var(--sw-border, #e5e7eb); border-radius: var(--sw-radius, 14px);
|
|
56
|
+
padding: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
|
|
57
|
+
.name { font-size: .8rem; color: var(--sw-muted, #4b5563); margin: 0 0 .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
58
|
+
.update { font-size: .8rem; background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; border-radius: 8px; padding: .4rem .6rem; margin-bottom: .75rem; display: flex; gap: .5rem; align-items: flex-start; }
|
|
59
|
+
.update.major { background: #fffbeb; border-color: #fcd34d; color: #92400e; font-weight: 600; }
|
|
60
|
+
.update > span { flex: 1; }
|
|
61
|
+
.update-close { font: inherit; background: none; border: 0; color: inherit; cursor: pointer; padding: 0 .2rem; line-height: 1; }
|
|
62
|
+
.grades { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
|
|
63
|
+
@media (max-width: 26rem) { .grades { grid-template-columns: 1fr; } }
|
|
64
|
+
.tile { border: 1px solid var(--sw-border, #e5e7eb); border-radius: 10px; padding: .7rem; }
|
|
65
|
+
.tile-head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
|
|
66
|
+
.title { font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; margin: 0; }
|
|
67
|
+
.question { font-size: .75rem; color: var(--sw-muted, #4b5563); margin: .15rem 0 0; }
|
|
68
|
+
.letter { flex: none; width: 2.4rem; height: 2.4rem; border: 2px solid; border-radius: 9px; display: flex; align-items: center;
|
|
69
|
+
justify-content: center; font-weight: 800; font-size: 1.35rem; }
|
|
70
|
+
.letter.none { border-style: dashed; border-color: #d1d5db; color: #6b7280; }
|
|
71
|
+
.word { font-size: .95rem; font-weight: 700; margin: .5rem 0 0; }
|
|
72
|
+
.sure { font-size: .75rem; color: var(--sw-muted, #4b5563); margin: .1rem 0 0; }
|
|
73
|
+
.warn { font-size: .75rem; background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; border-radius: 7px; padding: .3rem .45rem; margin-top: .4rem; }
|
|
74
|
+
.rows { margin: .9rem 0 0; display: grid; grid-template-columns: auto 1fr; gap: .3rem .8rem; font-size: .85rem; }
|
|
75
|
+
.rows dt { color: var(--sw-muted, #4b5563); }
|
|
76
|
+
.rows dd { margin: 0; font-weight: 600; }
|
|
77
|
+
h3 { font-size: .8rem; margin: .9rem 0 .35rem; }
|
|
78
|
+
ul { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
|
|
79
|
+
li { display: flex; gap: .5rem; align-items: baseline; padding: .15rem 0; }
|
|
80
|
+
.sev { flex: none; font-size: .65rem; font-weight: 700; text-transform: uppercase; border-radius: 5px; padding: .05rem .35rem; background: #f3f4f6; color: #374151; }
|
|
81
|
+
.sev.critical, .sev.high { background: #fee2e2; color: #991b1b; }
|
|
82
|
+
.sev.medium { background: #fef3c7; color: #92400e; }
|
|
83
|
+
.more { font-size: .75rem; color: var(--sw-muted, #4b5563); margin-top: .25rem; }
|
|
84
|
+
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
|
|
85
|
+
.btn { font: inherit; font-size: .85rem; font-weight: 600; border-radius: 9px; padding: .5rem .85rem; cursor: pointer; text-decoration: none;
|
|
86
|
+
border: 1px solid var(--sw-accent, #4f46e5); }
|
|
87
|
+
.btn.primary { background: var(--sw-accent, #4f46e5); color: #fff; }
|
|
88
|
+
.btn.secondary { background: transparent; color: var(--sw-accent, #4f46e5); }
|
|
89
|
+
.btn:focus-visible { outline: 2px solid var(--sw-accent, #4f46e5); outline-offset: 2px; }
|
|
90
|
+
.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; margin-top: .9rem; padding-top: .7rem;
|
|
91
|
+
border-top: 1px solid var(--sw-border, #e5e7eb); font-size: .75rem; color: var(--sw-muted, #4b5563); }
|
|
92
|
+
.foot a { color: var(--sw-accent, #4f46e5); }
|
|
93
|
+
.empty { font-size: .85rem; color: var(--sw-muted, #4b5563); }
|
|
94
|
+
.cta { margin-top: .9rem; font-size: .85rem; background: #f5f3ff; border: 1px solid #ddd6fe; color: #4c1d95; border-radius: 9px; padding: .55rem .7rem; }
|
|
95
|
+
.cta a { color: #6d28d9; font-weight: 600; }
|
|
96
|
+
.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .7rem; margin-top: .4rem; }
|
|
97
|
+
figure { margin: 0; }
|
|
98
|
+
figure img { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--sw-border, #e5e7eb); background: #f9fafb; }
|
|
99
|
+
figcaption { font-size: .75rem; color: var(--sw-muted, #4b5563); margin-top: .25rem; }
|
|
100
|
+
.warn-head { font-weight: 600; margin: 0; }
|
|
101
|
+
.warn-tail { margin: .15rem 0 0; }
|
|
102
|
+
.partial { color: #92400e; font-weight: 600; }
|
|
103
|
+
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: .5rem; }
|
|
104
|
+
.cat { border: 1px solid var(--sw-border, #e5e7eb); border-radius: 10px; padding: .55rem .7rem; }
|
|
105
|
+
.cat-head { display: flex; gap: .5rem; align-items: center; font-weight: 600; margin: 0; }
|
|
106
|
+
.cat-letter { display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem; border: 1px solid; border-radius: 6px; font-weight: 700; }
|
|
107
|
+
.reasons { margin: .35rem 0 0 2.1rem; font-size: .8rem; }
|
|
108
|
+
.reasons li { display: list-item; padding: .1rem 0; }
|
|
109
|
+
.noted { margin-top: .5rem; padding: .45rem .6rem; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; font-size: .75rem; color: #475569; }
|
|
110
|
+
.noted p { margin: .1rem 0 0; }
|
|
111
|
+
.noted .noted-title { font-weight: 700; color: #334155; margin: 0; }
|
|
112
|
+
.noted .noted-why { color: #64748b; margin-top: .25rem; }
|
|
113
|
+
.capture { margin-top: .75rem; border: 1px solid var(--sw-border, #e5e7eb); border-radius: 10px; padding: .6rem .75rem; }
|
|
114
|
+
.cap-line + .cap-line { margin-top: .55rem; padding-top: .55rem; border-top: 1px solid #f3f4f6; }
|
|
115
|
+
.cap-label { font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--sw-muted, #6b7280); margin: 0; }
|
|
116
|
+
.cap-value { font-size: .9rem; font-weight: 600; margin: .1rem 0 0; }
|
|
117
|
+
.cap-value.unrecorded { color: var(--sw-muted, #6b7280); }
|
|
118
|
+
.cap-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin: .25rem 0; }
|
|
119
|
+
.cap-tag { font-size: .68rem; font-weight: 600; border-radius: 999px; padding: .05rem .5rem; background: #fffbeb; color: #92400e; box-shadow: inset 0 0 0 1px #fcd34d; }
|
|
120
|
+
.cap-tag.file { background: #eef2ff; color: #4338ca; box-shadow: inset 0 0 0 1px #c7d2fe; }
|
|
121
|
+
.cap-map { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .75rem; margin: .2rem 0 0; }
|
|
122
|
+
.cap-map a { color: var(--sw-accent, #4f46e5); font-weight: 600; }
|
|
123
|
+
.cap-map a.cap-credit { color: var(--sw-muted, #6b7280); font-weight: 400; }
|
|
124
|
+
.cap-tip { font-size: .78rem; background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; border-radius: 8px; padding: .4rem .6rem; margin: .6rem 0 0; }
|
|
125
|
+
.nomatch { font-size: .8rem; font-weight: 500; background: #fff7ed; border: 1px solid #fed7aa; color: #7c2d12; border-radius: 8px; padding: .4rem .6rem; }
|
|
126
|
+
.preview { max-width: 14rem; margin-top: .4rem; }
|
|
127
|
+
.ev-head { display: flex; gap: .5rem; align-items: center; }
|
|
128
|
+
.badge { font-size: .7rem; font-weight: 500; background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe; border-radius: 999px; padding: .05rem .5rem; }
|
|
129
|
+
.ev-note { font-size: .8rem; margin: .4rem 0 0; }
|
|
130
|
+
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .8rem; margin-top: .5rem; }
|
|
131
|
+
.maps figure img { background: #111827; }
|
|
132
|
+
.maps figcaption strong { display: block; color: var(--sw-text, #111827); font-size: .8rem; }
|
|
133
|
+
.map-text { display: block; margin-top: .15rem; }
|
|
134
|
+
:host([mode="full"]) { max-width: 60rem; }
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
// Small DOM helper — text only, never HTML
|
|
138
|
+
function el(tag, className, text) {
|
|
139
|
+
const node = document.createElement(tag);
|
|
140
|
+
if (className) node.className = className;
|
|
141
|
+
if (text !== undefined && text !== null) node.textContent = String(text);
|
|
142
|
+
return node;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function link(className, text, href) {
|
|
146
|
+
const a = el('a', className, text);
|
|
147
|
+
a.href = href;
|
|
148
|
+
a.target = '_blank';
|
|
149
|
+
a.rel = 'noopener';
|
|
150
|
+
return a;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Image sources from the host: http(s), blob: or a relative path — never another scheme
|
|
154
|
+
function safeImageSrc(value) {
|
|
155
|
+
const s = String(value);
|
|
156
|
+
if (!/^[a-z][a-z0-9+.-]*:/i.test(s)) return s;
|
|
157
|
+
return /^(https?|blob):/i.test(s) ? s : null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function safeHttpUrl(value) {
|
|
161
|
+
try {
|
|
162
|
+
const url = new URL(String(value));
|
|
163
|
+
return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : null;
|
|
164
|
+
} catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function letterBox(className, grade) {
|
|
170
|
+
const box = el('span', className, grade);
|
|
171
|
+
const [bg, fg, border] = GRADE_COLOURS[grade];
|
|
172
|
+
box.style.background = bg;
|
|
173
|
+
box.style.color = fg;
|
|
174
|
+
box.style.borderColor = border;
|
|
175
|
+
box.setAttribute('aria-hidden', 'true');
|
|
176
|
+
return box;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function renderTile(h, full) {
|
|
180
|
+
const tile = el('section', 'tile');
|
|
181
|
+
tile.setAttribute('aria-label', `${h.title} grade`);
|
|
182
|
+
const head = el('div', 'tile-head');
|
|
183
|
+
const text = el('div');
|
|
184
|
+
text.append(el('p', 'title', h.title), el('p', 'question', h.question));
|
|
185
|
+
const letter = el('div', h.grade ? 'letter' : 'letter none', h.grade ?? '—');
|
|
186
|
+
if (h.grade) {
|
|
187
|
+
const [bg, fg, border] = GRADE_COLOURS[h.grade];
|
|
188
|
+
letter.style.background = bg;
|
|
189
|
+
letter.style.color = fg;
|
|
190
|
+
letter.style.borderColor = border;
|
|
191
|
+
}
|
|
192
|
+
letter.setAttribute('aria-hidden', 'true');
|
|
193
|
+
head.append(text, letter);
|
|
194
|
+
tile.append(head, el('p', 'word', h.word));
|
|
195
|
+
if (h.confidence) tile.append(el('p', 'sure', `How sure we are: ${h.confidence}`));
|
|
196
|
+
if (h.note) tile.append(el('p', 'sure', h.note));
|
|
197
|
+
// Full view, in the web report's order: weakest area, softened or warnings, partial coverage
|
|
198
|
+
if (full && h.weakestArea) tile.append(el('p', 'sure', `Weakest area: ${h.weakestArea}`));
|
|
199
|
+
if (full && h.softened && !h.warnings.length) tile.append(el('p', 'sure', SOFTENED));
|
|
200
|
+
if (full) {
|
|
201
|
+
h.warnings.forEach((w) => {
|
|
202
|
+
const box = el('div', 'warn');
|
|
203
|
+
box.setAttribute('role', 'note');
|
|
204
|
+
box.append(el('p', 'warn-head', `⚠ ${w}`), el('p', 'warn-tail', WARNING_TAIL));
|
|
205
|
+
tile.append(box);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (h.lowConfidence && !(full && h.warnings.length)) tile.append(el('p', 'warn', 'Low confidence. Open the full report before relying on it.'));
|
|
209
|
+
if (h.partial) {
|
|
210
|
+
const p = el('p', 'sure');
|
|
211
|
+
p.append(el('strong', 'partial', full ? 'Partial coverage' : 'Partly checked'), document.createTextNode(` — ${full ? PARTIAL_FULL : PARTIAL_CARD}`));
|
|
212
|
+
tile.append(p);
|
|
213
|
+
}
|
|
214
|
+
return tile;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Why these grades: one box per category, its reasons, and the checks only noted (full view)
|
|
218
|
+
function renderCategories(model) {
|
|
219
|
+
const wrap = el('div', 'cats');
|
|
220
|
+
model.categories.forEach((c) => {
|
|
221
|
+
const box = el('section', 'cat');
|
|
222
|
+
box.setAttribute('aria-label', `${c.name} grade ${c.grade}`);
|
|
223
|
+
const head = el('p', 'cat-head');
|
|
224
|
+
head.append(letterBox('cat-letter', c.grade), el('span', null, c.name));
|
|
225
|
+
box.append(head);
|
|
226
|
+
if (c.reasons.length) {
|
|
227
|
+
const ul = el('ul', 'reasons');
|
|
228
|
+
c.reasons.forEach((r) => ul.append(el('li', null, r.label + (r.reassuring ? ' (reassuring)' : ''))));
|
|
229
|
+
box.append(ul);
|
|
230
|
+
}
|
|
231
|
+
if (c.alsoNoted.length) {
|
|
232
|
+
const noted = el('div', 'noted');
|
|
233
|
+
noted.append(el('p', 'noted-title', model.alsoNoted.title), el('p', null, c.alsoNoted.join(', ')), el('p', 'noted-why', model.alsoNoted.text));
|
|
234
|
+
box.append(noted);
|
|
235
|
+
}
|
|
236
|
+
wrap.append(box);
|
|
237
|
+
});
|
|
238
|
+
return wrap;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// When, where and what took it: each line says where it comes from
|
|
242
|
+
function renderCapture(cap) {
|
|
243
|
+
const part = el('section', 'capture');
|
|
244
|
+
part.setAttribute('aria-label', cap.title);
|
|
245
|
+
cap.lines.forEach((l) => {
|
|
246
|
+
const line = el('div', 'cap-line');
|
|
247
|
+
line.append(el('p', 'cap-label', l.label), el('p', l.recorded ? 'cap-value' : 'cap-value unrecorded', l.value));
|
|
248
|
+
if (l.sources.length) {
|
|
249
|
+
const tags = el('p', 'cap-tags');
|
|
250
|
+
l.sources.forEach((s) => tags.append(el('span', `cap-tag ${s.key}`, s.text)));
|
|
251
|
+
line.append(tags);
|
|
252
|
+
}
|
|
253
|
+
if (l.why) line.append(el('p', 'sure', l.why));
|
|
254
|
+
if (l.map || l.credit) {
|
|
255
|
+
const where = el('p', 'cap-map');
|
|
256
|
+
if (l.map) where.append(link(null, `${MAP_LINK_TEXT} ›`, l.map));
|
|
257
|
+
if (l.credit) where.append(link('cap-credit', l.credit.text, l.credit.url));
|
|
258
|
+
line.append(where);
|
|
259
|
+
}
|
|
260
|
+
part.append(line);
|
|
261
|
+
});
|
|
262
|
+
if (cap.tip) part.append(el('p', 'cap-tip', cap.tip));
|
|
263
|
+
return part;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Evidence maps, each with what it shows (full view)
|
|
267
|
+
function renderEvidenceMaps(ev) {
|
|
268
|
+
const part = el('section', 'evidence');
|
|
269
|
+
const head = el('h3', 'ev-head', 'Evidence maps ');
|
|
270
|
+
head.append(el('span', 'badge', 'Evidence, not a verdict'));
|
|
271
|
+
part.append(head, el('p', 'sure', ev.intro));
|
|
272
|
+
if (ev.note) part.append(el('p', 'ev-note', ev.note));
|
|
273
|
+
if (ev.noMatch) {
|
|
274
|
+
part.append(el('p', 'nomatch', ev.noMatch.text));
|
|
275
|
+
const src = safeImageSrc(ev.noMatch.preview.src);
|
|
276
|
+
if (src) {
|
|
277
|
+
const fig = el('figure', 'preview');
|
|
278
|
+
const img = el('img');
|
|
279
|
+
img.src = src;
|
|
280
|
+
img.alt = ev.noMatch.preview.title;
|
|
281
|
+
fig.append(img, el('figcaption', null, ev.noMatch.preview.title));
|
|
282
|
+
part.append(fig);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const grid = el('div', 'maps');
|
|
286
|
+
ev.maps.forEach((m) => {
|
|
287
|
+
const src = safeImageSrc(m.src);
|
|
288
|
+
if (!src) return;
|
|
289
|
+
const fig = el('figure');
|
|
290
|
+
const img = el('img');
|
|
291
|
+
img.src = src;
|
|
292
|
+
img.alt = `Evidence map: ${m.title}`;
|
|
293
|
+
img.loading = 'lazy';
|
|
294
|
+
const cap = el('figcaption');
|
|
295
|
+
cap.append(el('strong', null, m.title));
|
|
296
|
+
if (m.text) cap.append(el('span', 'map-text', m.text));
|
|
297
|
+
fig.append(img, cap);
|
|
298
|
+
grid.append(fig);
|
|
299
|
+
});
|
|
300
|
+
part.append(grid);
|
|
301
|
+
return part;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function renderCard(model, options = {}) {
|
|
305
|
+
const card = el('article', 'card');
|
|
306
|
+
if (!model.ok) {
|
|
307
|
+
card.append(el('p', 'empty', model.message));
|
|
308
|
+
return card;
|
|
309
|
+
}
|
|
310
|
+
if (model.update) {
|
|
311
|
+
// Non-blocking and dismissable: the rest of the card is still drawn from what this version understands
|
|
312
|
+
const note = el('p', `update ${model.update.level}`);
|
|
313
|
+
note.setAttribute('role', 'status');
|
|
314
|
+
const words = el('span', null, `${model.update.text} `);
|
|
315
|
+
const notes = safeHttpUrl(options.releaseNotesUrl) ?? DEFAULT_RELEASE_NOTES_URL;
|
|
316
|
+
words.append(link('update-link', 'See what’s new', notes));
|
|
317
|
+
note.append(words);
|
|
318
|
+
if (options.onDismissUpdate) {
|
|
319
|
+
const close = el('button', 'update-close', '×');
|
|
320
|
+
close.type = 'button';
|
|
321
|
+
close.setAttribute('aria-label', 'Dismiss');
|
|
322
|
+
close.addEventListener('click', () => options.onDismissUpdate(model.update.schemaVersion));
|
|
323
|
+
note.append(close);
|
|
324
|
+
}
|
|
325
|
+
card.append(note);
|
|
326
|
+
}
|
|
327
|
+
if (model.name) card.append(el('p', 'name', model.name));
|
|
328
|
+
|
|
329
|
+
// The two headline grades — never combined
|
|
330
|
+
const grades = el('div', 'grades');
|
|
331
|
+
model.headlines.forEach((h) => grades.append(renderTile(h, model.mode === 'full')));
|
|
332
|
+
card.append(grades);
|
|
333
|
+
|
|
334
|
+
// When, where and what took it (schema 1.4)
|
|
335
|
+
if (model.capture) card.append(renderCapture(model.capture));
|
|
336
|
+
|
|
337
|
+
// Evidence rows
|
|
338
|
+
if (model.evidence.length) {
|
|
339
|
+
const rows = el('dl', 'rows');
|
|
340
|
+
model.evidence.forEach((r) => rows.append(el('dt', null, r.label), el('dd', null, r.value)));
|
|
341
|
+
card.append(rows);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Key findings
|
|
345
|
+
if (model.findings.shown.length) {
|
|
346
|
+
card.append(el('h3', null, 'What we found'));
|
|
347
|
+
const ul = el('ul');
|
|
348
|
+
model.findings.shown.forEach((f) => {
|
|
349
|
+
const li = el('li');
|
|
350
|
+
li.append(el('span', `sev ${f.severity}`, f.severity), el('span', null, f.label));
|
|
351
|
+
ul.append(li);
|
|
352
|
+
});
|
|
353
|
+
card.append(ul);
|
|
354
|
+
if (model.findings.more) card.append(el('p', 'more', `+${model.findings.more} more in the full report`));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (model.categories.length) {
|
|
358
|
+
card.append(el('h3', null, 'Why these grades'), renderCategories(model));
|
|
359
|
+
}
|
|
360
|
+
if (model.evidenceMaps) {
|
|
361
|
+
card.append(renderEvidenceMaps(model.evidenceMaps));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Analysis images (full mode)
|
|
365
|
+
if (model.images.length) {
|
|
366
|
+
card.append(el('h3', null, 'Analysis images'));
|
|
367
|
+
const grid = el('div', 'images');
|
|
368
|
+
model.images.forEach((img) => {
|
|
369
|
+
const src = safeImageSrc(img.src);
|
|
370
|
+
if (!src) return;
|
|
371
|
+
const fig = el('figure');
|
|
372
|
+
const tag = el('img');
|
|
373
|
+
tag.src = src;
|
|
374
|
+
tag.alt = img.title;
|
|
375
|
+
tag.loading = 'lazy';
|
|
376
|
+
fig.append(tag, el('figcaption', null, img.title));
|
|
377
|
+
grid.append(fig);
|
|
378
|
+
});
|
|
379
|
+
card.append(grid);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// The snapWONDERS Vaultify call to action, from the result
|
|
383
|
+
if (model.vaultifyCta) {
|
|
384
|
+
const cta = el('p', 'cta', `${model.vaultifyCta.text} `);
|
|
385
|
+
cta.append(link(null, 'Hide it →', model.vaultifyCta.url));
|
|
386
|
+
card.append(cta);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Actions
|
|
390
|
+
const actions = el('div', 'actions');
|
|
391
|
+
const reportUrl = options.reportUrl ? safeHttpUrl(options.reportUrl) : null;
|
|
392
|
+
if (reportUrl) actions.append(link('btn primary', 'Open full report', reportUrl));
|
|
393
|
+
if (options.onCheckAnother) {
|
|
394
|
+
const again = el('button', 'btn secondary', 'Check another');
|
|
395
|
+
again.type = 'button';
|
|
396
|
+
again.addEventListener('click', options.onCheckAnother);
|
|
397
|
+
actions.append(again);
|
|
398
|
+
}
|
|
399
|
+
if (actions.childNodes.length) card.append(actions);
|
|
400
|
+
|
|
401
|
+
// Attribution, from the result
|
|
402
|
+
if (model.attribution) {
|
|
403
|
+
const foot = el('div', 'foot');
|
|
404
|
+
foot.append(link(null, model.attribution.text, model.attribution.url));
|
|
405
|
+
card.append(foot);
|
|
406
|
+
}
|
|
407
|
+
return card;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const Base = typeof HTMLElement === 'undefined' ? class {} : HTMLElement;
|
|
411
|
+
|
|
412
|
+
export class SnapwondersReport extends Base {
|
|
413
|
+
static get observedAttributes() {
|
|
414
|
+
return ['mode', 'report-url', 'file-index', 'link-params', 'check-another', 'hide-location', 'release-notes-url', 'dismissed-update'];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
constructor() {
|
|
418
|
+
super();
|
|
419
|
+
this._result = null;
|
|
420
|
+
this._assetUrl = null;
|
|
421
|
+
this._updateAnnounced = false;
|
|
422
|
+
this._dismissedHere = null;
|
|
423
|
+
this.attachShadow({ mode: 'open' });
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
get result() {
|
|
427
|
+
return this._result;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
set result(value) {
|
|
431
|
+
this._result = value;
|
|
432
|
+
this._updateAnnounced = false;
|
|
433
|
+
this._render();
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
get assetUrl() {
|
|
437
|
+
return this._assetUrl;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
set assetUrl(fn) {
|
|
441
|
+
this._assetUrl = typeof fn === 'function' ? fn : null;
|
|
442
|
+
if (this.isConnected) this._render();
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
connectedCallback() {
|
|
446
|
+
// A result can arrive inline as JSON data (static pages, e.g. WordPress)
|
|
447
|
+
if (this._result === null) {
|
|
448
|
+
const inline = this.querySelector('script[type="application/json"]');
|
|
449
|
+
if (inline) {
|
|
450
|
+
try {
|
|
451
|
+
this._result = JSON.parse(inline.textContent);
|
|
452
|
+
} catch {
|
|
453
|
+
this._result = null;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
this._render();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
attributeChangedCallback() {
|
|
461
|
+
if (this.isConnected) this._render();
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
_render() {
|
|
465
|
+
const model = buildCardModel(this._result, {
|
|
466
|
+
fileIndex: Number.parseInt(this.getAttribute('file-index') ?? '0', 10) || 0,
|
|
467
|
+
mode: this.getAttribute('mode') === 'full' ? 'full' : 'card',
|
|
468
|
+
assetUrl: this._assetUrl,
|
|
469
|
+
linkParams: this.getAttribute('link-params') ?? '',
|
|
470
|
+
hideLocation: this.hasAttribute('hide-location'),
|
|
471
|
+
dismissedUpdate: this.getAttribute('dismissed-update') ?? this._dismissedHere,
|
|
472
|
+
});
|
|
473
|
+
const style = document.createElement('style');
|
|
474
|
+
style.textContent = STYLES;
|
|
475
|
+
const card = renderCard(model, {
|
|
476
|
+
reportUrl: this.getAttribute('report-url'),
|
|
477
|
+
releaseNotesUrl: this.getAttribute('release-notes-url'),
|
|
478
|
+
onDismissUpdate: (schemaVersion) => {
|
|
479
|
+
// Hide it here at once; the host stores the version so it stays hidden next time
|
|
480
|
+
this._dismissedHere = schemaVersion ?? '999.999';
|
|
481
|
+
this.dispatchEvent(new CustomEvent('snapwonders-update-dismissed', { bubbles: true, composed: true, detail: { schemaVersion } }));
|
|
482
|
+
this._render();
|
|
483
|
+
},
|
|
484
|
+
onCheckAnother: this.hasAttribute('check-another')
|
|
485
|
+
? () => this.dispatchEvent(new CustomEvent('snapwonders-check-another', { bubbles: true, composed: true }))
|
|
486
|
+
: null,
|
|
487
|
+
});
|
|
488
|
+
this.shadowRoot.replaceChildren(style, card);
|
|
489
|
+
if (model.ok && model.updateAvailable && !this._updateAnnounced) {
|
|
490
|
+
this._updateAnnounced = true;
|
|
491
|
+
this.dispatchEvent(new CustomEvent('snapwonders-update-available', { bubbles: true, composed: true,
|
|
492
|
+
detail: model.update ? { level: model.update.level, schemaVersion: model.update.schemaVersion } : null }));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export function defineSnapwondersReport(tagName = 'snapwonders-report') {
|
|
498
|
+
if (typeof customElements !== 'undefined' && !customElements.get(tagName)) {
|
|
499
|
+
customElements.define(tagName, SnapwondersReport);
|
|
500
|
+
}
|
|
501
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* snapWONDERS API — Result renderer (JavaScript)
|
|
3
|
+
* API version: 1.0
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2026 Kenneth Springer @ snapWONDERS. MIT Licensed — see LICENSE.
|
|
6
|
+
* The MIT licence covers this client library only; the snapWONDERS API it calls is proprietary.
|
|
7
|
+
*
|
|
8
|
+
* Author: Kenneth Springer @ snapWONDERS <kenneth@snapwonders.com> (https://kennethbspringer.au)
|
|
9
|
+
*
|
|
10
|
+
* All the snapWONDERS API services are available over the Clearnet / **Web** and Dark Web **Tor** and **I2P**
|
|
11
|
+
* Read details: https://snapwonders.com/developers
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @snapwonders/report — draws a snapWONDERS analyse result as a card.
|
|
16
|
+
* Importing this module registers <snapwonders-report> in a browser.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { defineSnapwondersReport } from './element.js';
|
|
20
|
+
|
|
21
|
+
export * from './model.js';
|
|
22
|
+
export { SnapwondersReport, renderCard, defineSnapwondersReport } from './element.js';
|
|
23
|
+
|
|
24
|
+
defineSnapwondersReport();
|