@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
|
@@ -0,0 +1,1061 @@
|
|
|
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
|
+
/* @snapwonders/report 0.2.1 — single-file build. Generated by scripts/build.mjs; edit src/, not this file. */
|
|
15
|
+
(function () {
|
|
16
|
+
'use strict';
|
|
17
|
+
/**
|
|
18
|
+
* Turns one analyse result (GET /api/analyse/result/{job_uid}) into a plain view model, for the
|
|
19
|
+
* card or the full report. No DOM and no network here, so it runs (and is tested) anywhere. The
|
|
20
|
+
* wording mirrors the snapWONDERS report page, so every surface says the same thing.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// The result contract this renderer understands. A result with any newer version, minor too, gets a
|
|
24
|
+
// non-blocking "new version available" note; everything this renderer knows is still drawn.
|
|
25
|
+
const SUPPORTED_SCHEMA_MAJOR = 1;
|
|
26
|
+
const SUPPORTED_SCHEMA_MINOR = 4;
|
|
27
|
+
const SUPPORTED_SCHEMA = `${SUPPORTED_SCHEMA_MAJOR}.${SUPPORTED_SCHEMA_MINOR}`;
|
|
28
|
+
|
|
29
|
+
// Where the note links unless the host (extension, plugin, app) passes its own release notes
|
|
30
|
+
const DEFAULT_RELEASE_NOTES_URL = 'https://github.com/snapWONDERS/snapWONDERS-Report/blob/main/CHANGELOG.md';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* True when a result is newer than this renderer (any bump, minor too) or its version is unreadable.
|
|
34
|
+
*/
|
|
35
|
+
function isNewerSchema(version) {
|
|
36
|
+
if (version === null) return true;
|
|
37
|
+
if (version.major !== SUPPORTED_SCHEMA_MAJOR) return version.major > SUPPORTED_SCHEMA_MAJOR;
|
|
38
|
+
return version.minor > SUPPORTED_SCHEMA_MINOR;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The update note's wording: gentle for a minor bump (fields only added), firmer for a major one
|
|
42
|
+
// (a field changed meaning or was removed) or an unreadable version (owner 2026-11-20)
|
|
43
|
+
const UPDATE_NOTE = Object.freeze({
|
|
44
|
+
minor: 'A new version is available, with more in this report.',
|
|
45
|
+
major: 'Update needed: this report comes from a newer snapWONDERS version, so some parts may be missing or shown wrongly.',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The update note for a result, or null when none is due. The note is dismissable: the host keeps the
|
|
50
|
+
* version the user dismissed (`dismissedUpdate`, e.g. in extension storage) and the note stays hidden
|
|
51
|
+
* for that version and older ones, and comes back on the next version.
|
|
52
|
+
*/
|
|
53
|
+
function updateNote(version, dismissedUpdate) {
|
|
54
|
+
if (!isNewerSchema(version)) return null;
|
|
55
|
+
const level = version === null || version.major > SUPPORTED_SCHEMA_MAJOR ? 'major' : 'minor';
|
|
56
|
+
const dismissed = typeof dismissedUpdate === 'string' ? parseSchemaVersion(dismissedUpdate) : null;
|
|
57
|
+
if (version !== null && dismissed !== null
|
|
58
|
+
&& (dismissed.major > version.major || (dismissed.major === version.major && dismissed.minor >= version.minor))) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
level,
|
|
63
|
+
text: UPDATE_NOTE[level],
|
|
64
|
+
schemaVersion: version === null ? null : `${version.major}.${version.minor}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Grade words, as on the report page
|
|
69
|
+
const GRADE_WORDS = Object.freeze({
|
|
70
|
+
A: 'Nothing significant found',
|
|
71
|
+
B: 'Low risk',
|
|
72
|
+
C: 'Moderate risk',
|
|
73
|
+
D: 'High risk',
|
|
74
|
+
F: 'Critical',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const CONFIDENCE_WORDS = Object.freeze({ high: 'High', medium: 'Medium', low: 'Low' });
|
|
78
|
+
|
|
79
|
+
// AI generation verdicts, as on the report page's AI card
|
|
80
|
+
const AI_VERDICT_WORDS = Object.freeze({
|
|
81
|
+
likely_authentic: 'Verified camera capture',
|
|
82
|
+
likely_real: 'Likely real (camera signals)',
|
|
83
|
+
real_edited: 'Real capture, edited',
|
|
84
|
+
no_evidence: 'No AI-generation evidence found',
|
|
85
|
+
inconclusive: 'Inconclusive',
|
|
86
|
+
ai_edited: 'AI-edited',
|
|
87
|
+
ai_processed: 'Processed by an AI image generator',
|
|
88
|
+
possible_aigc: 'Possible AI generation',
|
|
89
|
+
declared_ai: 'Declared AI-generated or AI-edited',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const PIXEL_ANALYSIS_WORDS = Object.freeze({
|
|
93
|
+
flagged: 'Signs of AI generation detected',
|
|
94
|
+
clear: 'No signs found at this image quality',
|
|
95
|
+
not_assessable: 'Not yet calibrated for this file type or size',
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Hidden content — never names the checks that ran
|
|
99
|
+
const HIDDEN_CONTENT_WORDS = Object.freeze({
|
|
100
|
+
not_analysed: 'Not checked',
|
|
101
|
+
none: 'Nothing found by the checks that ran',
|
|
102
|
+
anomalies: 'Irregularities found — not conclusive on their own',
|
|
103
|
+
unusual_reading: 'An unusual reading — not evidence of hidden content',
|
|
104
|
+
watermark_pattern_unconfirmed: 'A pattern was flagged but not confirmed',
|
|
105
|
+
generator_watermark_matched: 'A known AI image generator watermark was found',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const CHECK_WORDS = Object.freeze({
|
|
109
|
+
clean: 'Nothing found',
|
|
110
|
+
possible: 'Possible signs found',
|
|
111
|
+
suspect: 'Signs found',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Analysis images the full report shows, in order, with their titles
|
|
115
|
+
const IMAGE_TITLES = Object.freeze({
|
|
116
|
+
display_image: 'Your file',
|
|
117
|
+
face_map: 'Faces found',
|
|
118
|
+
text_map: 'Readable text found',
|
|
119
|
+
forensic_ela: 'Error Level Analysis',
|
|
120
|
+
forensic_ela_anomaly: 'Error Level Analysis — areas that stand out',
|
|
121
|
+
forensic_noise_map: 'Noise map',
|
|
122
|
+
forensic_clone: 'Copied areas',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Evidence maps, in the web report's order, with its titles and the line each panel opens with.
|
|
126
|
+
// The NSS chart is not a map, but sits in the same group (approved design). Never the ghost curve.
|
|
127
|
+
const EVIDENCE_MAPS = Object.freeze({
|
|
128
|
+
forensic_roi: { title: 'Regions', text: 'Boxes show areas where a check found something. Each box has a number. A box is something to look at, not proof of editing.' },
|
|
129
|
+
forensic_noise_field: { title: 'Noise', text: 'Colour shows areas with less camera grain than expected. Stronger colour means less grain. Smooth things like sky, water and skin can show colour on their own.' },
|
|
130
|
+
forensic_ela_field: { title: 'Compression', text: 'Colour shows areas that change differently when the photo is saved again. Sharp edges and text often differ. Look for a solid patch that stands out from what is around it.' },
|
|
131
|
+
forensic_dct_map: { title: 'Save history', text: 'This photo was saved as a JPEG more than once. Colour shows areas that do not share that save history, as a part pasted in from another picture often does. Many edits do not show here, and busy detail can show colour on its own.' },
|
|
132
|
+
forensic_nss_chart: { title: 'Natural Scene Statistics Check', text: null },
|
|
133
|
+
forensic_ghost_map: { title: 'Earlier save', text: 'Colour marks an area that looks like it was saved as a JPEG at a lower quality before the rest of the photo. A piece pasted in from another photo can do this. Smooth, very bright and very dark areas cannot be read.' },
|
|
134
|
+
forensic_camera_map: { title: 'Since the camera', text: 'Your camera saved a small preview inside the file when the photo was taken. Colour marks areas that now look different from that preview. Something added or removed after the photo was taken can show here. Many editing apps replace the preview, and then nothing shows. This is evidence, not a verdict.' },
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// The maps replace these older pictures, as on the web report
|
|
138
|
+
const REPLACED_BY_MAPS = Object.freeze(['forensic_ela', 'forensic_ela_anomaly', 'forensic_noise_map']);
|
|
139
|
+
|
|
140
|
+
const EVIDENCE_INTRO = 'These maps look for signs of editing only. Your grade also looks at AI, origin and metadata. A quiet map does not mean a good grade.';
|
|
141
|
+
const NO_REGIONS = 'No check marked an area in this photo. This is not proof the photo is unedited. Some edits leave no trace these checks can see.';
|
|
142
|
+
const NO_REGIONS_DCT = 'No check flagged an area in this photo. The Save history map below shows colour on its own terms. This is not proof the photo is unedited. Some edits leave no trace these checks can see.';
|
|
143
|
+
|
|
144
|
+
// The five categories behind the two grades, in the web report's order
|
|
145
|
+
const CATEGORY_WORDS = Object.freeze({
|
|
146
|
+
origin: 'Origin', manipulation: 'Manipulation', ai_generation: 'AI generation',
|
|
147
|
+
privacy: 'Privacy', security: 'Security',
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// "Also noted" (schema 1.3), worded as the web report's box under each category
|
|
151
|
+
const ALSO_NOTED_TITLE = 'Also noted - not used for your grade';
|
|
152
|
+
function alsoNotedText(media) {
|
|
153
|
+
return `These checks picked something up, but they do the same on most ${media === 'video' ? 'videos' : 'photos'}, including untouched ones. On their own they tell us very little, so they don't change your grade.`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// When, where and what took it (schema 1.4): the line tags, as on the web report's card
|
|
157
|
+
const CAPTURE_LINES = Object.freeze(['when', 'where', 'what', 'apps']);
|
|
158
|
+
const CAPTURE_SOURCES = Object.freeze({
|
|
159
|
+
file: 'From the file',
|
|
160
|
+
file_name: 'Inferred from the file name',
|
|
161
|
+
fingerprint: 'Inferred from the compression',
|
|
162
|
+
});
|
|
163
|
+
const CAPTURE_TITLE = 'When, where and what took it';
|
|
164
|
+
const MAP_LINK_TEXT = 'View on map';
|
|
165
|
+
const OSM_CREDIT_URL = 'https://www.openstreetmap.org/copyright';
|
|
166
|
+
|
|
167
|
+
// "Since the camera": the preview stored in the file does not line up with the photo
|
|
168
|
+
const CAMERA_NO_MATCH = "The camera's preview does not match this photo. This can happen when a photo is heavily changed or swapped, or when an app crops or rotates it. This is evidence, not a verdict.";
|
|
169
|
+
|
|
170
|
+
const PARTIAL_CARD ="some checks couldn't run.";
|
|
171
|
+
const PARTIAL_FULL = "some checks couldn't run, so this isn't a clean bill of health.";
|
|
172
|
+
const SOFTENED = "Softened by a step because we're less sure about this finding.";
|
|
173
|
+
const WARNING_TAIL = "We've eased this grade because we're not sure. Check the matching card in the report below before relying on it.";
|
|
174
|
+
|
|
175
|
+
// Findings are listed most serious first; the card shows the top few
|
|
176
|
+
const SEVERITY_ORDER = Object.freeze({ critical: 0, high: 1, medium: 2, low: 3, info: 4 });
|
|
177
|
+
const MAX_FINDINGS = 5;
|
|
178
|
+
|
|
179
|
+
// Attribution links are drawn only when they point at snapWONDERS
|
|
180
|
+
const ATTRIBUTION_HOSTS = Object.freeze(['snapwonders.com']);
|
|
181
|
+
|
|
182
|
+
// Link parameters a host may add to the attribution links (e.g. ?src=wp&site=…)
|
|
183
|
+
const LINK_PARAM_KEYS = Object.freeze(['src', 'site', 'r']);
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Reads `schema_version` ("major.minor"). A result from before versioning carries none and is the
|
|
187
|
+
* 1.0 contract. Anything unreadable returns null.
|
|
188
|
+
*/
|
|
189
|
+
function parseSchemaVersion(value) {
|
|
190
|
+
if (value === undefined || value === null) {
|
|
191
|
+
return { major: 1, minor: 0 };
|
|
192
|
+
}
|
|
193
|
+
const match = /^(\d+)\.(\d+)$/.exec(String(value));
|
|
194
|
+
if (!match) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
return { major: Number(match[1]), minor: Number(match[2]) };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Parses a host's link parameters ("src=wp&site=abc") keeping only the allowed keys and plain
|
|
202
|
+
* values, so nothing a host passes can turn a snapWONDERS link into something else.
|
|
203
|
+
*/
|
|
204
|
+
function parseLinkParams(value) {
|
|
205
|
+
const out = [];
|
|
206
|
+
if (typeof value !== 'string' || value === '') {
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
for (const pair of value.split('&')) {
|
|
210
|
+
const [key, val] = pair.split('=');
|
|
211
|
+
if (LINK_PARAM_KEYS.includes(key) && typeof val === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(val)) {
|
|
212
|
+
out.push([key, val]);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** An https link on a snapWONDERS host, with the host's link parameters added; otherwise null. */
|
|
219
|
+
function snapwondersLink(value, linkParams = []) {
|
|
220
|
+
let url;
|
|
221
|
+
try {
|
|
222
|
+
url = new URL(String(value));
|
|
223
|
+
} catch {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const host = url.hostname.toLowerCase();
|
|
227
|
+
const ours = ATTRIBUTION_HOSTS.some((h) => host === h || host.endsWith(`.${h}`));
|
|
228
|
+
if (url.protocol !== 'https:' || !ours || url.username || url.password) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
for (const [key, val] of linkParams) {
|
|
232
|
+
url.searchParams.set(key, val);
|
|
233
|
+
}
|
|
234
|
+
return url.href;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function has(map, key) {
|
|
238
|
+
return typeof key === 'string' && Object.prototype.hasOwnProperty.call(map, key);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function textLink(block, linkParams) {
|
|
242
|
+
if (!block || typeof block !== 'object' || typeof block.text !== 'string' || block.text === '') {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
const url = snapwondersLink(block.url, linkParams);
|
|
246
|
+
return url ? { text: block.text, url } : null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Why a headline grade is what it is (schema 1.2). Missing or unreadable: nothing is said.
|
|
250
|
+
function explained(file, kind) {
|
|
251
|
+
const e = file.explanation && typeof file.explanation === 'object' ? file.explanation[kind] : null;
|
|
252
|
+
if (!e || typeof e !== 'object') {
|
|
253
|
+
return { weakestArea: null, softened: false, warnings: [], notAssessed: false };
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
weakestArea: has(CATEGORY_WORDS, e.decided_by) ? CATEGORY_WORDS[e.decided_by] : null,
|
|
257
|
+
softened: e.softened === true,
|
|
258
|
+
warnings: Array.isArray(e.warnings) ? e.warnings.filter((w) => typeof w === 'string' && w.trim() !== '').map((w) => w.trim()) : [],
|
|
259
|
+
notAssessed: Array.isArray(e.not_assessed) && e.not_assessed.some((c) => has(CATEGORY_WORDS, c)),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// A check's label as a list item: the report's row labels are questions ("Noise level inconsistency?")
|
|
264
|
+
function itemLabel(value) {
|
|
265
|
+
return typeof value === 'string' ? value.trim().replace(/\?+$/, '').trim() : '';
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// The five categories, each with its reasons and (1.3) the checks only noted. Full mode only.
|
|
269
|
+
function categories(file) {
|
|
270
|
+
const c = file.explanation && file.explanation.categories && typeof file.explanation.categories === 'object' ? file.explanation.categories : {};
|
|
271
|
+
return Object.keys(CATEGORY_WORDS)
|
|
272
|
+
.filter((k) => c[k] && typeof c[k] === 'object' && has(GRADE_WORDS, c[k].grade))
|
|
273
|
+
.map((k) => ({
|
|
274
|
+
name: CATEGORY_WORDS[k],
|
|
275
|
+
grade: c[k].grade,
|
|
276
|
+
reasons: (Array.isArray(c[k].reasons) ? c[k].reasons : [])
|
|
277
|
+
.filter((r) => r && itemLabel(r.label) !== '')
|
|
278
|
+
.map((r) => ({ label: itemLabel(r.label), reassuring: r.effect === 'reassuring' })),
|
|
279
|
+
alsoNoted: (Array.isArray(c[k].also_noted) ? c[k].also_noted : [])
|
|
280
|
+
.map((r) => (r ? itemLabel(r.label) : ''))
|
|
281
|
+
.filter((l) => l !== ''),
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The evidence maps the host supplies, in order, with what each shows. When no map marks an area,
|
|
287
|
+
* the report says so, and that it is not proof of an unedited photo: an absent Regions map is never
|
|
288
|
+
* shown as a clean result.
|
|
289
|
+
*/
|
|
290
|
+
function evidenceMaps(file, assetUrl) {
|
|
291
|
+
if (typeof assetUrl !== 'function' || !Array.isArray(file.assets)) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
const isImage = (a) => a && typeof a.mime_type === 'string' && a.mime_type.startsWith('image/');
|
|
295
|
+
const order = Object.keys(EVIDENCE_MAPS);
|
|
296
|
+
const maps = file.assets
|
|
297
|
+
.filter((a) => isImage(a) && has(EVIDENCE_MAPS, a.category))
|
|
298
|
+
.sort((a, b) => order.indexOf(a.category) - order.indexOf(b.category))
|
|
299
|
+
.map((a) => ({ category: a.category, ...EVIDENCE_MAPS[a.category], src: assetUrl(a) }))
|
|
300
|
+
.filter((m) => typeof m.src === 'string' && m.src !== '');
|
|
301
|
+
|
|
302
|
+
// Since the camera (schema 1.4): whether the map marked anything, and whether the preview lined up
|
|
303
|
+
const cam = file.verdicts && file.verdicts.forensic && file.verdicts.forensic.camera_map;
|
|
304
|
+
const camKnown = cam && typeof cam === 'object' && typeof cam.marked === 'boolean';
|
|
305
|
+
let noMatch = null;
|
|
306
|
+
if (cam && cam.matched === false) {
|
|
307
|
+
const thumb = file.assets.find((a) => isImage(a) && a.category === 'exif_thumbnail');
|
|
308
|
+
const src = thumb ? assetUrl(thumb) : null;
|
|
309
|
+
if (typeof src === 'string' && src !== '') {
|
|
310
|
+
noMatch = { text: CAMERA_NO_MATCH, preview: { title: "The camera's preview, stored in the file", src } };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (!maps.length && !noMatch) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
const shown = (c) => maps.some((m) => m.category === c);
|
|
317
|
+
// Before 1.4 a Since-the-camera map may have marked areas we cannot see, so it keeps the note off
|
|
318
|
+
const camMarked = shown('forensic_camera_map') && (!camKnown || cam.marked === true);
|
|
319
|
+
const marked = shown('forensic_roi') || shown('forensic_ghost_map') || camMarked || noMatch !== null;
|
|
320
|
+
return {
|
|
321
|
+
intro: EVIDENCE_INTRO,
|
|
322
|
+
note: marked ? null : (shown('forensic_dct_map') ? NO_REGIONS_DCT : NO_REGIONS),
|
|
323
|
+
noMatch,
|
|
324
|
+
maps,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// A map link built from the numbers only, never from a name or a URL in the result
|
|
329
|
+
function mapUrl(lat, lng) {
|
|
330
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lng) || Math.abs(lat) > 90 || Math.abs(lng) > 180) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
const la = lat.toFixed(5);
|
|
334
|
+
const lo = lng.toFixed(5);
|
|
335
|
+
return `https://www.openstreetmap.org/?mlat=${la}&mlon=${lo}#map=15/${la}/${lo}`;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* When, where and what took it (schema 1.4): the web report's card, line for line. Null on older
|
|
340
|
+
* results, where the section is hidden. `hideLocation` drops the Where line (public pages).
|
|
341
|
+
*/
|
|
342
|
+
function capture(file, full, hideLocation) {
|
|
343
|
+
const c = file.capture;
|
|
344
|
+
if (!c || typeof c !== 'object') {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
const str = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
348
|
+
const lines = [];
|
|
349
|
+
for (const id of CAPTURE_LINES) {
|
|
350
|
+
const l = c[id];
|
|
351
|
+
if (!l || typeof l !== 'object' || str(l.label) === '' || str(l.value) === '') continue;
|
|
352
|
+
if (id === 'where' && hideLocation) continue;
|
|
353
|
+
const line = {
|
|
354
|
+
id,
|
|
355
|
+
label: str(l.label),
|
|
356
|
+
value: str(l.value),
|
|
357
|
+
why: full && str(l.why) !== '' ? str(l.why) : null,
|
|
358
|
+
recorded: l.recorded === true,
|
|
359
|
+
sources: full && Array.isArray(l.sources) ? [...new Set(l.sources.filter((s) => has(CAPTURE_SOURCES, s)))].map((s) => ({ key: s, text: CAPTURE_SOURCES[s] })) : [],
|
|
360
|
+
map: null,
|
|
361
|
+
credit: null,
|
|
362
|
+
};
|
|
363
|
+
if (id === 'where' && l.state === 'location') {
|
|
364
|
+
line.map = mapUrl(l.lat, l.lng);
|
|
365
|
+
// OpenStreetMap's credit goes wherever the place is shown; only its own copyright page is linked
|
|
366
|
+
const credit = l.credit && typeof l.credit === 'object' ? l.credit : null;
|
|
367
|
+
line.credit = {
|
|
368
|
+
text: credit && str(credit.text) !== '' ? str(credit.text) : 'Map data from OpenStreetMap',
|
|
369
|
+
url: OSM_CREDIT_URL,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
lines.push(line);
|
|
373
|
+
}
|
|
374
|
+
if (!lines.length) {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
// Card only: when, where and the camera all say the same "not recorded", say it once
|
|
378
|
+
const blank = lines.filter((l) => ['when', 'where', 'what'].includes(l.id) && !l.recorded);
|
|
379
|
+
if (!full && blank.length === 3 && blank.every((l) => l.value === blank[0].value)) {
|
|
380
|
+
const merged = { ...blank[0], id: 'when_where_what', label: blank.map((l) => l.label).join(' · ') };
|
|
381
|
+
lines.splice(lines.indexOf(blank[0]), 3, merged);
|
|
382
|
+
}
|
|
383
|
+
return { title: CAPTURE_TITLE, lines, tip: full && str(c.tip) !== '' ? str(c.tip) : null };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function headline(kind, grade, confidence, file = {}) {
|
|
387
|
+
const graded = has(GRADE_WORDS, grade);
|
|
388
|
+
const why = graded ? explained(file, kind) : explained({}, kind);
|
|
389
|
+
const flag = file[kind === 'authenticity' ? 'grade_partial_coverage' : 'exposure_partial_coverage'] === true;
|
|
390
|
+
return {
|
|
391
|
+
weakestArea: why.weakestArea,
|
|
392
|
+
softened: why.softened,
|
|
393
|
+
warnings: why.warnings,
|
|
394
|
+
partial: graded && (flag || why.notAssessed),
|
|
395
|
+
kind,
|
|
396
|
+
title: kind === 'authenticity' ? 'Authenticity' : 'Exposure',
|
|
397
|
+
question: kind === 'authenticity' ? 'Has this file been edited or AI-generated?' : 'What does this file give away?',
|
|
398
|
+
grade: graded ? grade : null,
|
|
399
|
+
word: graded ? GRADE_WORDS[grade] : "Couldn't tell",
|
|
400
|
+
note: graded ? null : "We couldn't check this side of the file. That isn't the same as a clean result.",
|
|
401
|
+
confidence: graded && has(CONFIDENCE_WORDS, confidence) ? CONFIDENCE_WORDS[confidence] : null,
|
|
402
|
+
lowConfidence: graded && confidence === 'low',
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function plural(n, one, many) {
|
|
407
|
+
return `${n} ${n === 1 ? one : many}`;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function evidence(file, full, version) {
|
|
411
|
+
const rows = [];
|
|
412
|
+
const verdicts = file.verdicts && typeof file.verdicts === 'object' ? file.verdicts : {};
|
|
413
|
+
|
|
414
|
+
// AI generation, and the pixel analysis beside it
|
|
415
|
+
const ai = verdicts.ai_generation;
|
|
416
|
+
if (ai && has(AI_VERDICT_WORDS, ai.verdict)) {
|
|
417
|
+
rows.push({ label: 'AI generation', value: AI_VERDICT_WORDS[ai.verdict] });
|
|
418
|
+
}
|
|
419
|
+
if (ai && has(PIXEL_ANALYSIS_WORDS, ai.pixel_analysis)) {
|
|
420
|
+
rows.push({ label: 'Pixel analysis', value: PIXEL_ANALYSIS_WORDS[ai.pixel_analysis] });
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Content Credentials (C2PA)
|
|
424
|
+
const c2pa = verdicts.c2pa;
|
|
425
|
+
if (c2pa && c2pa.has_manifest === true) {
|
|
426
|
+
rows.push({ label: 'Content Credentials', value: c2pa.trusted === true ? 'Present, trusted signer' : 'Present, signer not verified' });
|
|
427
|
+
} else if (full && c2pa && c2pa.has_manifest === false) {
|
|
428
|
+
rows.push({ label: 'Content Credentials', value: 'None present' });
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Faces — low-confidence detections are possible faces, never dropped
|
|
432
|
+
if (Number.isInteger(file.face_count)) {
|
|
433
|
+
const split = file.face_count_by_confidence;
|
|
434
|
+
const low = split && Number.isInteger(split.low) ? split.low : 0;
|
|
435
|
+
const sure = Math.max(0, file.face_count - low);
|
|
436
|
+
const parts = [];
|
|
437
|
+
if (sure > 0) parts.push(plural(sure, 'face', 'faces'));
|
|
438
|
+
if (low > 0) parts.push(plural(low, 'possible face', 'possible faces'));
|
|
439
|
+
rows.push({ label: 'Faces', value: parts.length ? parts.join(', ') : 'None found' });
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Readable text
|
|
443
|
+
if (Number.isInteger(file.text_region_count)) {
|
|
444
|
+
rows.push({ label: 'Readable text', value: file.text_region_count === 0 ? 'None found' : plural(file.text_region_count, 'area', 'areas') });
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Watermark — the web report's top-card wording, sent by the API as a label
|
|
448
|
+
const wm = verdicts.watermark;
|
|
449
|
+
if (wm && typeof wm.label === 'string' && wm.label.trim() !== '') {
|
|
450
|
+
rows.push({ label: 'Watermark', value: wm.label.trim() });
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (!full) {
|
|
454
|
+
return rows;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// Hidden content
|
|
458
|
+
const stego = verdicts.steganography;
|
|
459
|
+
if (stego && has(HIDDEN_CONTENT_WORDS, stego.verdict)) {
|
|
460
|
+
rows.push({ label: 'Hidden content', value: HIDDEN_CONTENT_WORDS[stego.verdict] });
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Encoder fingerprint
|
|
464
|
+
const fp = verdicts.camera_fingerprint;
|
|
465
|
+
if (fp && fp.applicable === true) {
|
|
466
|
+
const name = typeof fp.encoder_name === 'string' && fp.encoder_name !== '' ? fp.encoder_name : null;
|
|
467
|
+
rows.push({ label: 'Encoder fingerprint', value: fp.matched === true ? (name ? `Matches ${name}` : 'Matched') : 'No known match' });
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Compression and noise differences — counts only
|
|
471
|
+
const ela = verdicts.forensic && verdicts.forensic.ela;
|
|
472
|
+
if (ela && typeof ela.high_fraction === 'number' && ela.high_fraction >= 0 && ela.high_fraction <= 1) {
|
|
473
|
+
rows.push({ label: 'Compression differences', value: `${Math.round(ela.high_fraction * 100)}% of the image` });
|
|
474
|
+
}
|
|
475
|
+
// Noise differences: only from schema 1.2, where anomaly_tile_count counts the same tiles as the
|
|
476
|
+
// web report. Before 1.2 it was an older count that could contradict the Regions map.
|
|
477
|
+
const noise = verdicts.forensic && verdicts.forensic.noise_inconsistency;
|
|
478
|
+
const sameCountAsWeb = version !== null && (version.major > 1 || version.minor >= 2);
|
|
479
|
+
if (sameCountAsWeb && noise && Number.isInteger(noise.anomaly_tile_count)) {
|
|
480
|
+
rows.push({ label: 'Noise differences', value: noise.anomaly_tile_count === 0 ? 'None found' : plural(noise.anomaly_tile_count, 'area', 'areas') });
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Video and audio checks
|
|
484
|
+
const audio = verdicts.audio_splice;
|
|
485
|
+
if (audio && has(CHECK_WORDS, audio.verdict)) {
|
|
486
|
+
rows.push({ label: 'Audio edits', value: CHECK_WORDS[audio.verdict] });
|
|
487
|
+
}
|
|
488
|
+
const video = verdicts.video_tamper || {};
|
|
489
|
+
if (video.inter_frame_tamper && has(CHECK_WORDS, video.inter_frame_tamper.verdict)) {
|
|
490
|
+
rows.push({ label: 'Frame-to-frame edits', value: CHECK_WORDS[video.inter_frame_tamper.verdict] });
|
|
491
|
+
}
|
|
492
|
+
if (video.frame_duplicate && has(CHECK_WORDS, video.frame_duplicate.dup_verdict)) {
|
|
493
|
+
rows.push({ label: 'Repeated frames', value: CHECK_WORDS[video.frame_duplicate.dup_verdict] });
|
|
494
|
+
}
|
|
495
|
+
return rows;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function findings(file, full) {
|
|
499
|
+
const list = file.verdicts && Array.isArray(file.verdicts.findings) ? file.verdicts.findings : [];
|
|
500
|
+
const clean = list
|
|
501
|
+
.filter((f) => f && typeof f.label === 'string' && f.label !== '')
|
|
502
|
+
.map((f) => ({ label: f.label, severity: has(SEVERITY_ORDER, f.severity) ? f.severity : 'info' }))
|
|
503
|
+
.sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
|
|
504
|
+
const cap = full ? clean.length : MAX_FINDINGS;
|
|
505
|
+
return { shown: clean.slice(0, cap), more: Math.max(0, clean.length - cap) };
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* The analysis images, in display order. The renderer never fetches anything itself: the host's
|
|
510
|
+
* `assetUrl(asset)` maps each asset to where the host keeps it (its own server, its uploads
|
|
511
|
+
* folder). Assets it returns nothing for are left out.
|
|
512
|
+
*/
|
|
513
|
+
function images(file, assetUrl, mapsShown) {
|
|
514
|
+
if (typeof assetUrl !== 'function' || !Array.isArray(file.assets)) {
|
|
515
|
+
return [];
|
|
516
|
+
}
|
|
517
|
+
const order = Object.keys(IMAGE_TITLES);
|
|
518
|
+
return file.assets
|
|
519
|
+
.filter((a) => a && has(IMAGE_TITLES, a.category) && typeof a.mime_type === 'string' && a.mime_type.startsWith('image/'))
|
|
520
|
+
.filter((a) => !(mapsShown && REPLACED_BY_MAPS.includes(a.category)))
|
|
521
|
+
.sort((a, b) => order.indexOf(a.category) - order.indexOf(b.category))
|
|
522
|
+
.map((a) => ({ title: IMAGE_TITLES[a.category], category: a.category, src: assetUrl(a) }))
|
|
523
|
+
.filter((i) => typeof i.src === 'string' && i.src !== '');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Builds the view model.
|
|
528
|
+
*
|
|
529
|
+
* @param {object} result the JSON from GET /api/analyse/result/{job_uid}
|
|
530
|
+
* @param {{fileIndex?: number, mode?: 'card'|'full', assetUrl?: function, linkParams?: string}} [options]
|
|
531
|
+
* @returns {object} `{ok: false, message}` when there is nothing to show
|
|
532
|
+
*/
|
|
533
|
+
function buildCardModel(result, options = {}) {
|
|
534
|
+
if (!result || typeof result !== 'object' || !Array.isArray(result.files)) {
|
|
535
|
+
return { ok: false, message: 'No result to show.' };
|
|
536
|
+
}
|
|
537
|
+
const fileIndex = Number.isInteger(options.fileIndex) ? options.fileIndex : 0;
|
|
538
|
+
const file = result.files[fileIndex];
|
|
539
|
+
if (!file || typeof file !== 'object') {
|
|
540
|
+
return { ok: false, message: 'No result to show.' };
|
|
541
|
+
}
|
|
542
|
+
const full = options.mode === 'full';
|
|
543
|
+
const linkParams = parseLinkParams(options.linkParams);
|
|
544
|
+
const version = parseSchemaVersion(result.schema_version);
|
|
545
|
+
const maps = full ? evidenceMaps(file, options.assetUrl) : null;
|
|
546
|
+
const media = file.verdicts && file.verdicts.video_tamper ? 'video' : 'photo';
|
|
547
|
+
return {
|
|
548
|
+
ok: true,
|
|
549
|
+
mode: full ? 'full' : 'card',
|
|
550
|
+
updateAvailable: isNewerSchema(version),
|
|
551
|
+
// Null when none is due or the user dismissed it for this version
|
|
552
|
+
update: updateNote(version, options.dismissedUpdate),
|
|
553
|
+
name: typeof file.name === 'string' ? file.name : '',
|
|
554
|
+
headlines: [
|
|
555
|
+
headline('authenticity', file.grade, file.confidence, file),
|
|
556
|
+
headline('exposure', file.exposure_grade, file.exposure_confidence, file),
|
|
557
|
+
],
|
|
558
|
+
capture: capture(file, full, options.hideLocation === true),
|
|
559
|
+
evidence: evidence(file, full, version),
|
|
560
|
+
findings: findings(file, full),
|
|
561
|
+
categories: full ? categories(file) : [],
|
|
562
|
+
alsoNoted: { title: ALSO_NOTED_TITLE, text: alsoNotedText(media) },
|
|
563
|
+
evidenceMaps: maps,
|
|
564
|
+
images: full ? images(file, options.assetUrl, maps !== null && maps.maps.some((m) => m.category !== 'forensic_nss_chart')) : [],
|
|
565
|
+
// Service output only (schema 1.1): the renderer never adds a credit of its own
|
|
566
|
+
attribution: textLink(result.attribution, linkParams),
|
|
567
|
+
vaultifyCta: textLink(file.vaultify_cta, linkParams),
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* <snapwonders-report> — draws one analyse result as a card.
|
|
573
|
+
*
|
|
574
|
+
* el.result = json; // the JSON from GET /api/analyse/result/{job_uid}
|
|
575
|
+
* <snapwonders-report report-url="…"> // adds "Open full report"
|
|
576
|
+
* <script type="application/json">{…}</script> // or the result inline (static pages)
|
|
577
|
+
* </snapwonders-report>
|
|
578
|
+
*
|
|
579
|
+
* Attributes: mode ("card" or "full"), report-url, file-index, link-params ("src=wp&site=…", added to the
|
|
580
|
+
* snapWONDERS links), check-another (adds a "Check another" button), hide-location (leaves out
|
|
581
|
+
* where the file was taken: set it on public pages unless the owner chose to show it),
|
|
582
|
+
* release-notes-url (where "See what's new" links when a result is newer than this renderer;
|
|
583
|
+
* the extension or plugin passes its own release notes, else the renderer's changelog).
|
|
584
|
+
* Property: assetUrl = (asset) => url — full mode only: where the host keeps each analysis image. The
|
|
585
|
+
* renderer makes no network calls of its own.
|
|
586
|
+
* dismissed-update (the result version whose update note the user dismissed; the host keeps it,
|
|
587
|
+
* e.g. in extension storage, so the note stays hidden for that version and returns on the next).
|
|
588
|
+
* Events: snapwonders-check-another; snapwonders-update-available (result newer than this renderer,
|
|
589
|
+
* detail { level: 'minor' | 'major', schemaVersion }); snapwonders-update-dismissed (detail
|
|
590
|
+
* { schemaVersion }: store it and pass it back as dismissed-update).
|
|
591
|
+
* Attribution and the snapWONDERS Vaultify link come from the result itself (schema 1.1) and are drawn
|
|
592
|
+
* only when they point at snapwonders.com; the renderer never adds a credit of its own.
|
|
593
|
+
* Theming: --sw-font, --sw-bg, --sw-text, --sw-muted, --sw-border, --sw-accent, --sw-radius.
|
|
594
|
+
*
|
|
595
|
+
* Every value is written with textContent — nothing from a result is ever parsed as HTML.
|
|
596
|
+
*/
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
// Grade colours, as on the report page
|
|
600
|
+
const GRADE_COLOURS = {
|
|
601
|
+
A: ['#dcfce7', '#166534', '#86efac'],
|
|
602
|
+
B: ['#ccfbf1', '#115e59', '#5eead4'],
|
|
603
|
+
C: ['#fef3c7', '#92400e', '#fcd34d'],
|
|
604
|
+
D: ['#ffedd5', '#9a3412', '#fdba74'],
|
|
605
|
+
F: ['#fee2e2', '#991b1b', '#fca5a5'],
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const STYLES = `
|
|
609
|
+
:host { display: block; font-family: var(--sw-font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
|
|
610
|
+
color: var(--sw-text, #111827); max-width: 34rem; }
|
|
611
|
+
.card { background: var(--sw-bg, #fff); border: 1px solid var(--sw-border, #e5e7eb); border-radius: var(--sw-radius, 14px);
|
|
612
|
+
padding: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
|
|
613
|
+
.name { font-size: .8rem; color: var(--sw-muted, #4b5563); margin: 0 0 .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
614
|
+
.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; }
|
|
615
|
+
.update.major { background: #fffbeb; border-color: #fcd34d; color: #92400e; font-weight: 600; }
|
|
616
|
+
.update > span { flex: 1; }
|
|
617
|
+
.update-close { font: inherit; background: none; border: 0; color: inherit; cursor: pointer; padding: 0 .2rem; line-height: 1; }
|
|
618
|
+
.grades { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
|
|
619
|
+
@media (max-width: 26rem) { .grades { grid-template-columns: 1fr; } }
|
|
620
|
+
.tile { border: 1px solid var(--sw-border, #e5e7eb); border-radius: 10px; padding: .7rem; }
|
|
621
|
+
.tile-head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
|
|
622
|
+
.title { font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; margin: 0; }
|
|
623
|
+
.question { font-size: .75rem; color: var(--sw-muted, #4b5563); margin: .15rem 0 0; }
|
|
624
|
+
.letter { flex: none; width: 2.4rem; height: 2.4rem; border: 2px solid; border-radius: 9px; display: flex; align-items: center;
|
|
625
|
+
justify-content: center; font-weight: 800; font-size: 1.35rem; }
|
|
626
|
+
.letter.none { border-style: dashed; border-color: #d1d5db; color: #6b7280; }
|
|
627
|
+
.word { font-size: .95rem; font-weight: 700; margin: .5rem 0 0; }
|
|
628
|
+
.sure { font-size: .75rem; color: var(--sw-muted, #4b5563); margin: .1rem 0 0; }
|
|
629
|
+
.warn { font-size: .75rem; background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; border-radius: 7px; padding: .3rem .45rem; margin-top: .4rem; }
|
|
630
|
+
.rows { margin: .9rem 0 0; display: grid; grid-template-columns: auto 1fr; gap: .3rem .8rem; font-size: .85rem; }
|
|
631
|
+
.rows dt { color: var(--sw-muted, #4b5563); }
|
|
632
|
+
.rows dd { margin: 0; font-weight: 600; }
|
|
633
|
+
h3 { font-size: .8rem; margin: .9rem 0 .35rem; }
|
|
634
|
+
ul { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
|
|
635
|
+
li { display: flex; gap: .5rem; align-items: baseline; padding: .15rem 0; }
|
|
636
|
+
.sev { flex: none; font-size: .65rem; font-weight: 700; text-transform: uppercase; border-radius: 5px; padding: .05rem .35rem; background: #f3f4f6; color: #374151; }
|
|
637
|
+
.sev.critical, .sev.high { background: #fee2e2; color: #991b1b; }
|
|
638
|
+
.sev.medium { background: #fef3c7; color: #92400e; }
|
|
639
|
+
.more { font-size: .75rem; color: var(--sw-muted, #4b5563); margin-top: .25rem; }
|
|
640
|
+
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
|
|
641
|
+
.btn { font: inherit; font-size: .85rem; font-weight: 600; border-radius: 9px; padding: .5rem .85rem; cursor: pointer; text-decoration: none;
|
|
642
|
+
border: 1px solid var(--sw-accent, #4f46e5); }
|
|
643
|
+
.btn.primary { background: var(--sw-accent, #4f46e5); color: #fff; }
|
|
644
|
+
.btn.secondary { background: transparent; color: var(--sw-accent, #4f46e5); }
|
|
645
|
+
.btn:focus-visible { outline: 2px solid var(--sw-accent, #4f46e5); outline-offset: 2px; }
|
|
646
|
+
.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; margin-top: .9rem; padding-top: .7rem;
|
|
647
|
+
border-top: 1px solid var(--sw-border, #e5e7eb); font-size: .75rem; color: var(--sw-muted, #4b5563); }
|
|
648
|
+
.foot a { color: var(--sw-accent, #4f46e5); }
|
|
649
|
+
.empty { font-size: .85rem; color: var(--sw-muted, #4b5563); }
|
|
650
|
+
.cta { margin-top: .9rem; font-size: .85rem; background: #f5f3ff; border: 1px solid #ddd6fe; color: #4c1d95; border-radius: 9px; padding: .55rem .7rem; }
|
|
651
|
+
.cta a { color: #6d28d9; font-weight: 600; }
|
|
652
|
+
.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .7rem; margin-top: .4rem; }
|
|
653
|
+
figure { margin: 0; }
|
|
654
|
+
figure img { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--sw-border, #e5e7eb); background: #f9fafb; }
|
|
655
|
+
figcaption { font-size: .75rem; color: var(--sw-muted, #4b5563); margin-top: .25rem; }
|
|
656
|
+
.warn-head { font-weight: 600; margin: 0; }
|
|
657
|
+
.warn-tail { margin: .15rem 0 0; }
|
|
658
|
+
.partial { color: #92400e; font-weight: 600; }
|
|
659
|
+
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: .5rem; }
|
|
660
|
+
.cat { border: 1px solid var(--sw-border, #e5e7eb); border-radius: 10px; padding: .55rem .7rem; }
|
|
661
|
+
.cat-head { display: flex; gap: .5rem; align-items: center; font-weight: 600; margin: 0; }
|
|
662
|
+
.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; }
|
|
663
|
+
.reasons { margin: .35rem 0 0 2.1rem; font-size: .8rem; }
|
|
664
|
+
.reasons li { display: list-item; padding: .1rem 0; }
|
|
665
|
+
.noted { margin-top: .5rem; padding: .45rem .6rem; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; font-size: .75rem; color: #475569; }
|
|
666
|
+
.noted p { margin: .1rem 0 0; }
|
|
667
|
+
.noted .noted-title { font-weight: 700; color: #334155; margin: 0; }
|
|
668
|
+
.noted .noted-why { color: #64748b; margin-top: .25rem; }
|
|
669
|
+
.capture { margin-top: .75rem; border: 1px solid var(--sw-border, #e5e7eb); border-radius: 10px; padding: .6rem .75rem; }
|
|
670
|
+
.cap-line + .cap-line { margin-top: .55rem; padding-top: .55rem; border-top: 1px solid #f3f4f6; }
|
|
671
|
+
.cap-label { font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--sw-muted, #6b7280); margin: 0; }
|
|
672
|
+
.cap-value { font-size: .9rem; font-weight: 600; margin: .1rem 0 0; }
|
|
673
|
+
.cap-value.unrecorded { color: var(--sw-muted, #6b7280); }
|
|
674
|
+
.cap-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin: .25rem 0; }
|
|
675
|
+
.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; }
|
|
676
|
+
.cap-tag.file { background: #eef2ff; color: #4338ca; box-shadow: inset 0 0 0 1px #c7d2fe; }
|
|
677
|
+
.cap-map { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .75rem; margin: .2rem 0 0; }
|
|
678
|
+
.cap-map a { color: var(--sw-accent, #4f46e5); font-weight: 600; }
|
|
679
|
+
.cap-map a.cap-credit { color: var(--sw-muted, #6b7280); font-weight: 400; }
|
|
680
|
+
.cap-tip { font-size: .78rem; background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; border-radius: 8px; padding: .4rem .6rem; margin: .6rem 0 0; }
|
|
681
|
+
.nomatch { font-size: .8rem; font-weight: 500; background: #fff7ed; border: 1px solid #fed7aa; color: #7c2d12; border-radius: 8px; padding: .4rem .6rem; }
|
|
682
|
+
.preview { max-width: 14rem; margin-top: .4rem; }
|
|
683
|
+
.ev-head { display: flex; gap: .5rem; align-items: center; }
|
|
684
|
+
.badge { font-size: .7rem; font-weight: 500; background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe; border-radius: 999px; padding: .05rem .5rem; }
|
|
685
|
+
.ev-note { font-size: .8rem; margin: .4rem 0 0; }
|
|
686
|
+
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .8rem; margin-top: .5rem; }
|
|
687
|
+
.maps figure img { background: #111827; }
|
|
688
|
+
.maps figcaption strong { display: block; color: var(--sw-text, #111827); font-size: .8rem; }
|
|
689
|
+
.map-text { display: block; margin-top: .15rem; }
|
|
690
|
+
:host([mode="full"]) { max-width: 60rem; }
|
|
691
|
+
`;
|
|
692
|
+
|
|
693
|
+
// Small DOM helper — text only, never HTML
|
|
694
|
+
function el(tag, className, text) {
|
|
695
|
+
const node = document.createElement(tag);
|
|
696
|
+
if (className) node.className = className;
|
|
697
|
+
if (text !== undefined && text !== null) node.textContent = String(text);
|
|
698
|
+
return node;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function link(className, text, href) {
|
|
702
|
+
const a = el('a', className, text);
|
|
703
|
+
a.href = href;
|
|
704
|
+
a.target = '_blank';
|
|
705
|
+
a.rel = 'noopener';
|
|
706
|
+
return a;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// Image sources from the host: http(s), blob: or a relative path — never another scheme
|
|
710
|
+
function safeImageSrc(value) {
|
|
711
|
+
const s = String(value);
|
|
712
|
+
if (!/^[a-z][a-z0-9+.-]*:/i.test(s)) return s;
|
|
713
|
+
return /^(https?|blob):/i.test(s) ? s : null;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function safeHttpUrl(value) {
|
|
717
|
+
try {
|
|
718
|
+
const url = new URL(String(value));
|
|
719
|
+
return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : null;
|
|
720
|
+
} catch {
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function letterBox(className, grade) {
|
|
726
|
+
const box = el('span', className, grade);
|
|
727
|
+
const [bg, fg, border] = GRADE_COLOURS[grade];
|
|
728
|
+
box.style.background = bg;
|
|
729
|
+
box.style.color = fg;
|
|
730
|
+
box.style.borderColor = border;
|
|
731
|
+
box.setAttribute('aria-hidden', 'true');
|
|
732
|
+
return box;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function renderTile(h, full) {
|
|
736
|
+
const tile = el('section', 'tile');
|
|
737
|
+
tile.setAttribute('aria-label', `${h.title} grade`);
|
|
738
|
+
const head = el('div', 'tile-head');
|
|
739
|
+
const text = el('div');
|
|
740
|
+
text.append(el('p', 'title', h.title), el('p', 'question', h.question));
|
|
741
|
+
const letter = el('div', h.grade ? 'letter' : 'letter none', h.grade ?? '—');
|
|
742
|
+
if (h.grade) {
|
|
743
|
+
const [bg, fg, border] = GRADE_COLOURS[h.grade];
|
|
744
|
+
letter.style.background = bg;
|
|
745
|
+
letter.style.color = fg;
|
|
746
|
+
letter.style.borderColor = border;
|
|
747
|
+
}
|
|
748
|
+
letter.setAttribute('aria-hidden', 'true');
|
|
749
|
+
head.append(text, letter);
|
|
750
|
+
tile.append(head, el('p', 'word', h.word));
|
|
751
|
+
if (h.confidence) tile.append(el('p', 'sure', `How sure we are: ${h.confidence}`));
|
|
752
|
+
if (h.note) tile.append(el('p', 'sure', h.note));
|
|
753
|
+
// Full view, in the web report's order: weakest area, softened or warnings, partial coverage
|
|
754
|
+
if (full && h.weakestArea) tile.append(el('p', 'sure', `Weakest area: ${h.weakestArea}`));
|
|
755
|
+
if (full && h.softened && !h.warnings.length) tile.append(el('p', 'sure', SOFTENED));
|
|
756
|
+
if (full) {
|
|
757
|
+
h.warnings.forEach((w) => {
|
|
758
|
+
const box = el('div', 'warn');
|
|
759
|
+
box.setAttribute('role', 'note');
|
|
760
|
+
box.append(el('p', 'warn-head', `⚠ ${w}`), el('p', 'warn-tail', WARNING_TAIL));
|
|
761
|
+
tile.append(box);
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
if (h.lowConfidence && !(full && h.warnings.length)) tile.append(el('p', 'warn', 'Low confidence. Open the full report before relying on it.'));
|
|
765
|
+
if (h.partial) {
|
|
766
|
+
const p = el('p', 'sure');
|
|
767
|
+
p.append(el('strong', 'partial', full ? 'Partial coverage' : 'Partly checked'), document.createTextNode(` — ${full ? PARTIAL_FULL : PARTIAL_CARD}`));
|
|
768
|
+
tile.append(p);
|
|
769
|
+
}
|
|
770
|
+
return tile;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// Why these grades: one box per category, its reasons, and the checks only noted (full view)
|
|
774
|
+
function renderCategories(model) {
|
|
775
|
+
const wrap = el('div', 'cats');
|
|
776
|
+
model.categories.forEach((c) => {
|
|
777
|
+
const box = el('section', 'cat');
|
|
778
|
+
box.setAttribute('aria-label', `${c.name} grade ${c.grade}`);
|
|
779
|
+
const head = el('p', 'cat-head');
|
|
780
|
+
head.append(letterBox('cat-letter', c.grade), el('span', null, c.name));
|
|
781
|
+
box.append(head);
|
|
782
|
+
if (c.reasons.length) {
|
|
783
|
+
const ul = el('ul', 'reasons');
|
|
784
|
+
c.reasons.forEach((r) => ul.append(el('li', null, r.label + (r.reassuring ? ' (reassuring)' : ''))));
|
|
785
|
+
box.append(ul);
|
|
786
|
+
}
|
|
787
|
+
if (c.alsoNoted.length) {
|
|
788
|
+
const noted = el('div', 'noted');
|
|
789
|
+
noted.append(el('p', 'noted-title', model.alsoNoted.title), el('p', null, c.alsoNoted.join(', ')), el('p', 'noted-why', model.alsoNoted.text));
|
|
790
|
+
box.append(noted);
|
|
791
|
+
}
|
|
792
|
+
wrap.append(box);
|
|
793
|
+
});
|
|
794
|
+
return wrap;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// When, where and what took it: each line says where it comes from
|
|
798
|
+
function renderCapture(cap) {
|
|
799
|
+
const part = el('section', 'capture');
|
|
800
|
+
part.setAttribute('aria-label', cap.title);
|
|
801
|
+
cap.lines.forEach((l) => {
|
|
802
|
+
const line = el('div', 'cap-line');
|
|
803
|
+
line.append(el('p', 'cap-label', l.label), el('p', l.recorded ? 'cap-value' : 'cap-value unrecorded', l.value));
|
|
804
|
+
if (l.sources.length) {
|
|
805
|
+
const tags = el('p', 'cap-tags');
|
|
806
|
+
l.sources.forEach((s) => tags.append(el('span', `cap-tag ${s.key}`, s.text)));
|
|
807
|
+
line.append(tags);
|
|
808
|
+
}
|
|
809
|
+
if (l.why) line.append(el('p', 'sure', l.why));
|
|
810
|
+
if (l.map || l.credit) {
|
|
811
|
+
const where = el('p', 'cap-map');
|
|
812
|
+
if (l.map) where.append(link(null, `${MAP_LINK_TEXT} ›`, l.map));
|
|
813
|
+
if (l.credit) where.append(link('cap-credit', l.credit.text, l.credit.url));
|
|
814
|
+
line.append(where);
|
|
815
|
+
}
|
|
816
|
+
part.append(line);
|
|
817
|
+
});
|
|
818
|
+
if (cap.tip) part.append(el('p', 'cap-tip', cap.tip));
|
|
819
|
+
return part;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// Evidence maps, each with what it shows (full view)
|
|
823
|
+
function renderEvidenceMaps(ev) {
|
|
824
|
+
const part = el('section', 'evidence');
|
|
825
|
+
const head = el('h3', 'ev-head', 'Evidence maps ');
|
|
826
|
+
head.append(el('span', 'badge', 'Evidence, not a verdict'));
|
|
827
|
+
part.append(head, el('p', 'sure', ev.intro));
|
|
828
|
+
if (ev.note) part.append(el('p', 'ev-note', ev.note));
|
|
829
|
+
if (ev.noMatch) {
|
|
830
|
+
part.append(el('p', 'nomatch', ev.noMatch.text));
|
|
831
|
+
const src = safeImageSrc(ev.noMatch.preview.src);
|
|
832
|
+
if (src) {
|
|
833
|
+
const fig = el('figure', 'preview');
|
|
834
|
+
const img = el('img');
|
|
835
|
+
img.src = src;
|
|
836
|
+
img.alt = ev.noMatch.preview.title;
|
|
837
|
+
fig.append(img, el('figcaption', null, ev.noMatch.preview.title));
|
|
838
|
+
part.append(fig);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
const grid = el('div', 'maps');
|
|
842
|
+
ev.maps.forEach((m) => {
|
|
843
|
+
const src = safeImageSrc(m.src);
|
|
844
|
+
if (!src) return;
|
|
845
|
+
const fig = el('figure');
|
|
846
|
+
const img = el('img');
|
|
847
|
+
img.src = src;
|
|
848
|
+
img.alt = `Evidence map: ${m.title}`;
|
|
849
|
+
img.loading = 'lazy';
|
|
850
|
+
const cap = el('figcaption');
|
|
851
|
+
cap.append(el('strong', null, m.title));
|
|
852
|
+
if (m.text) cap.append(el('span', 'map-text', m.text));
|
|
853
|
+
fig.append(img, cap);
|
|
854
|
+
grid.append(fig);
|
|
855
|
+
});
|
|
856
|
+
part.append(grid);
|
|
857
|
+
return part;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function renderCard(model, options = {}) {
|
|
861
|
+
const card = el('article', 'card');
|
|
862
|
+
if (!model.ok) {
|
|
863
|
+
card.append(el('p', 'empty', model.message));
|
|
864
|
+
return card;
|
|
865
|
+
}
|
|
866
|
+
if (model.update) {
|
|
867
|
+
// Non-blocking and dismissable: the rest of the card is still drawn from what this version understands
|
|
868
|
+
const note = el('p', `update ${model.update.level}`);
|
|
869
|
+
note.setAttribute('role', 'status');
|
|
870
|
+
const words = el('span', null, `${model.update.text} `);
|
|
871
|
+
const notes = safeHttpUrl(options.releaseNotesUrl) ?? DEFAULT_RELEASE_NOTES_URL;
|
|
872
|
+
words.append(link('update-link', 'See what’s new', notes));
|
|
873
|
+
note.append(words);
|
|
874
|
+
if (options.onDismissUpdate) {
|
|
875
|
+
const close = el('button', 'update-close', '×');
|
|
876
|
+
close.type = 'button';
|
|
877
|
+
close.setAttribute('aria-label', 'Dismiss');
|
|
878
|
+
close.addEventListener('click', () => options.onDismissUpdate(model.update.schemaVersion));
|
|
879
|
+
note.append(close);
|
|
880
|
+
}
|
|
881
|
+
card.append(note);
|
|
882
|
+
}
|
|
883
|
+
if (model.name) card.append(el('p', 'name', model.name));
|
|
884
|
+
|
|
885
|
+
// The two headline grades — never combined
|
|
886
|
+
const grades = el('div', 'grades');
|
|
887
|
+
model.headlines.forEach((h) => grades.append(renderTile(h, model.mode === 'full')));
|
|
888
|
+
card.append(grades);
|
|
889
|
+
|
|
890
|
+
// When, where and what took it (schema 1.4)
|
|
891
|
+
if (model.capture) card.append(renderCapture(model.capture));
|
|
892
|
+
|
|
893
|
+
// Evidence rows
|
|
894
|
+
if (model.evidence.length) {
|
|
895
|
+
const rows = el('dl', 'rows');
|
|
896
|
+
model.evidence.forEach((r) => rows.append(el('dt', null, r.label), el('dd', null, r.value)));
|
|
897
|
+
card.append(rows);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// Key findings
|
|
901
|
+
if (model.findings.shown.length) {
|
|
902
|
+
card.append(el('h3', null, 'What we found'));
|
|
903
|
+
const ul = el('ul');
|
|
904
|
+
model.findings.shown.forEach((f) => {
|
|
905
|
+
const li = el('li');
|
|
906
|
+
li.append(el('span', `sev ${f.severity}`, f.severity), el('span', null, f.label));
|
|
907
|
+
ul.append(li);
|
|
908
|
+
});
|
|
909
|
+
card.append(ul);
|
|
910
|
+
if (model.findings.more) card.append(el('p', 'more', `+${model.findings.more} more in the full report`));
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
if (model.categories.length) {
|
|
914
|
+
card.append(el('h3', null, 'Why these grades'), renderCategories(model));
|
|
915
|
+
}
|
|
916
|
+
if (model.evidenceMaps) {
|
|
917
|
+
card.append(renderEvidenceMaps(model.evidenceMaps));
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// Analysis images (full mode)
|
|
921
|
+
if (model.images.length) {
|
|
922
|
+
card.append(el('h3', null, 'Analysis images'));
|
|
923
|
+
const grid = el('div', 'images');
|
|
924
|
+
model.images.forEach((img) => {
|
|
925
|
+
const src = safeImageSrc(img.src);
|
|
926
|
+
if (!src) return;
|
|
927
|
+
const fig = el('figure');
|
|
928
|
+
const tag = el('img');
|
|
929
|
+
tag.src = src;
|
|
930
|
+
tag.alt = img.title;
|
|
931
|
+
tag.loading = 'lazy';
|
|
932
|
+
fig.append(tag, el('figcaption', null, img.title));
|
|
933
|
+
grid.append(fig);
|
|
934
|
+
});
|
|
935
|
+
card.append(grid);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// The snapWONDERS Vaultify call to action, from the result
|
|
939
|
+
if (model.vaultifyCta) {
|
|
940
|
+
const cta = el('p', 'cta', `${model.vaultifyCta.text} `);
|
|
941
|
+
cta.append(link(null, 'Hide it →', model.vaultifyCta.url));
|
|
942
|
+
card.append(cta);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// Actions
|
|
946
|
+
const actions = el('div', 'actions');
|
|
947
|
+
const reportUrl = options.reportUrl ? safeHttpUrl(options.reportUrl) : null;
|
|
948
|
+
if (reportUrl) actions.append(link('btn primary', 'Open full report', reportUrl));
|
|
949
|
+
if (options.onCheckAnother) {
|
|
950
|
+
const again = el('button', 'btn secondary', 'Check another');
|
|
951
|
+
again.type = 'button';
|
|
952
|
+
again.addEventListener('click', options.onCheckAnother);
|
|
953
|
+
actions.append(again);
|
|
954
|
+
}
|
|
955
|
+
if (actions.childNodes.length) card.append(actions);
|
|
956
|
+
|
|
957
|
+
// Attribution, from the result
|
|
958
|
+
if (model.attribution) {
|
|
959
|
+
const foot = el('div', 'foot');
|
|
960
|
+
foot.append(link(null, model.attribution.text, model.attribution.url));
|
|
961
|
+
card.append(foot);
|
|
962
|
+
}
|
|
963
|
+
return card;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const Base = typeof HTMLElement === 'undefined' ? class {} : HTMLElement;
|
|
967
|
+
|
|
968
|
+
class SnapwondersReport extends Base {
|
|
969
|
+
static get observedAttributes() {
|
|
970
|
+
return ['mode', 'report-url', 'file-index', 'link-params', 'check-another', 'hide-location', 'release-notes-url', 'dismissed-update'];
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
constructor() {
|
|
974
|
+
super();
|
|
975
|
+
this._result = null;
|
|
976
|
+
this._assetUrl = null;
|
|
977
|
+
this._updateAnnounced = false;
|
|
978
|
+
this._dismissedHere = null;
|
|
979
|
+
this.attachShadow({ mode: 'open' });
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
get result() {
|
|
983
|
+
return this._result;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
set result(value) {
|
|
987
|
+
this._result = value;
|
|
988
|
+
this._updateAnnounced = false;
|
|
989
|
+
this._render();
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
get assetUrl() {
|
|
993
|
+
return this._assetUrl;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
set assetUrl(fn) {
|
|
997
|
+
this._assetUrl = typeof fn === 'function' ? fn : null;
|
|
998
|
+
if (this.isConnected) this._render();
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
connectedCallback() {
|
|
1002
|
+
// A result can arrive inline as JSON data (static pages, e.g. WordPress)
|
|
1003
|
+
if (this._result === null) {
|
|
1004
|
+
const inline = this.querySelector('script[type="application/json"]');
|
|
1005
|
+
if (inline) {
|
|
1006
|
+
try {
|
|
1007
|
+
this._result = JSON.parse(inline.textContent);
|
|
1008
|
+
} catch {
|
|
1009
|
+
this._result = null;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
this._render();
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
attributeChangedCallback() {
|
|
1017
|
+
if (this.isConnected) this._render();
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
_render() {
|
|
1021
|
+
const model = buildCardModel(this._result, {
|
|
1022
|
+
fileIndex: Number.parseInt(this.getAttribute('file-index') ?? '0', 10) || 0,
|
|
1023
|
+
mode: this.getAttribute('mode') === 'full' ? 'full' : 'card',
|
|
1024
|
+
assetUrl: this._assetUrl,
|
|
1025
|
+
linkParams: this.getAttribute('link-params') ?? '',
|
|
1026
|
+
hideLocation: this.hasAttribute('hide-location'),
|
|
1027
|
+
dismissedUpdate: this.getAttribute('dismissed-update') ?? this._dismissedHere,
|
|
1028
|
+
});
|
|
1029
|
+
const style = document.createElement('style');
|
|
1030
|
+
style.textContent = STYLES;
|
|
1031
|
+
const card = renderCard(model, {
|
|
1032
|
+
reportUrl: this.getAttribute('report-url'),
|
|
1033
|
+
releaseNotesUrl: this.getAttribute('release-notes-url'),
|
|
1034
|
+
onDismissUpdate: (schemaVersion) => {
|
|
1035
|
+
// Hide it here at once; the host stores the version so it stays hidden next time
|
|
1036
|
+
this._dismissedHere = schemaVersion ?? '999.999';
|
|
1037
|
+
this.dispatchEvent(new CustomEvent('snapwonders-update-dismissed', { bubbles: true, composed: true, detail: { schemaVersion } }));
|
|
1038
|
+
this._render();
|
|
1039
|
+
},
|
|
1040
|
+
onCheckAnother: this.hasAttribute('check-another')
|
|
1041
|
+
? () => this.dispatchEvent(new CustomEvent('snapwonders-check-another', { bubbles: true, composed: true }))
|
|
1042
|
+
: null,
|
|
1043
|
+
});
|
|
1044
|
+
this.shadowRoot.replaceChildren(style, card);
|
|
1045
|
+
if (model.ok && model.updateAvailable && !this._updateAnnounced) {
|
|
1046
|
+
this._updateAnnounced = true;
|
|
1047
|
+
this.dispatchEvent(new CustomEvent('snapwonders-update-available', { bubbles: true, composed: true,
|
|
1048
|
+
detail: model.update ? { level: model.update.level, schemaVersion: model.update.schemaVersion } : null }));
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
function defineSnapwondersReport(tagName = 'snapwonders-report') {
|
|
1054
|
+
if (typeof customElements !== 'undefined' && !customElements.get(tagName)) {
|
|
1055
|
+
customElements.define(tagName, SnapwondersReport);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
defineSnapwondersReport();
|
|
1060
|
+
globalThis.snapwondersReport = Object.freeze({ version: "0.2.1", buildCardModel, parseSchemaVersion, SUPPORTED_SCHEMA_MAJOR, SUPPORTED_SCHEMA });
|
|
1061
|
+
})();
|