@vizejs/vite-plugin-musea 0.0.1-alpha.100
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/README.md +56 -0
- package/dist/a11y-C6xqILwZ.js +305 -0
- package/dist/a11y-C6xqILwZ.js.map +1 -0
- package/dist/a11y-CHcxz6UR.d.ts +61 -0
- package/dist/a11y-CHcxz6UR.d.ts.map +1 -0
- package/dist/a11y.d.ts +3 -0
- package/dist/a11y.js +3 -0
- package/dist/autogen-D3Zjc3zI.d.ts +64 -0
- package/dist/autogen-D3Zjc3zI.d.ts.map +1 -0
- package/dist/autogen-ymQnARZK.js +193 -0
- package/dist/autogen-ymQnARZK.js.map +1 -0
- package/dist/autogen.d.ts +2 -0
- package/dist/autogen.js +3 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +399 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2760 -0
- package/dist/index.js.map +1 -0
- package/dist/vrt-DP87vGIA.js +706 -0
- package/dist/vrt-DP87vGIA.js.map +1 -0
- package/dist/vrt-m01uFerp.d.ts +439 -0
- package/dist/vrt-m01uFerp.d.ts.map +1 -0
- package/dist/vrt.d.ts +2 -0
- package/dist/vrt.js +3 -0
- package/package.json +99 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { PNG } from "pngjs";
|
|
4
|
+
|
|
5
|
+
//#region src/vrt.ts
|
|
6
|
+
/**
|
|
7
|
+
* VRT runner using Playwright.
|
|
8
|
+
*/
|
|
9
|
+
var MuseaVrtRunner = class {
|
|
10
|
+
options;
|
|
11
|
+
capture;
|
|
12
|
+
comparison;
|
|
13
|
+
ci;
|
|
14
|
+
browser = null;
|
|
15
|
+
startTime = 0;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.options = {
|
|
18
|
+
snapshotDir: options.snapshotDir ?? ".vize/snapshots",
|
|
19
|
+
threshold: options.threshold ?? .1,
|
|
20
|
+
viewports: options.viewports ?? [{
|
|
21
|
+
width: 1280,
|
|
22
|
+
height: 720,
|
|
23
|
+
name: "desktop"
|
|
24
|
+
}, {
|
|
25
|
+
width: 375,
|
|
26
|
+
height: 667,
|
|
27
|
+
name: "mobile"
|
|
28
|
+
}]
|
|
29
|
+
};
|
|
30
|
+
this.capture = {
|
|
31
|
+
fullPage: options.capture?.fullPage ?? false,
|
|
32
|
+
waitForNetwork: options.capture?.waitForNetwork ?? true,
|
|
33
|
+
settleTime: options.capture?.settleTime ?? 100,
|
|
34
|
+
waitSelector: options.capture?.waitSelector ?? ".musea-variant",
|
|
35
|
+
hideElements: options.capture?.hideElements ?? [],
|
|
36
|
+
maskElements: options.capture?.maskElements ?? []
|
|
37
|
+
};
|
|
38
|
+
this.comparison = options.comparison ?? {};
|
|
39
|
+
this.ci = options.ci ?? {};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Initialize Playwright browser.
|
|
43
|
+
*/
|
|
44
|
+
async init() {
|
|
45
|
+
const { chromium } = await import("playwright");
|
|
46
|
+
this.browser = await chromium.launch({ headless: true });
|
|
47
|
+
this.startTime = Date.now();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Close browser and cleanup.
|
|
51
|
+
*/
|
|
52
|
+
async close() {
|
|
53
|
+
if (this.browser) {
|
|
54
|
+
await this.browser.close();
|
|
55
|
+
this.browser = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Run VRT tests for all Art files.
|
|
60
|
+
*/
|
|
61
|
+
async runAllTests(artFiles, baseUrl) {
|
|
62
|
+
if (!this.browser) throw new Error("VRT runner not initialized. Call init() first.");
|
|
63
|
+
const results = [];
|
|
64
|
+
const retries = this.ci.retries ?? 0;
|
|
65
|
+
for (const art of artFiles) for (const variant of art.variants) {
|
|
66
|
+
if (variant.skipVrt) continue;
|
|
67
|
+
const viewports = variant.args?.viewport ? [variant.args.viewport] : this.options.viewports;
|
|
68
|
+
for (const viewport of viewports) {
|
|
69
|
+
let result = null;
|
|
70
|
+
let attempts = 0;
|
|
71
|
+
while (attempts <= retries) {
|
|
72
|
+
result = await this.captureAndCompare(art, variant.name, viewport, baseUrl);
|
|
73
|
+
if (result.passed || result.isNew || !result.error) break;
|
|
74
|
+
attempts++;
|
|
75
|
+
if (attempts <= retries) console.log(`[vrt] Retry ${attempts}/${retries}: ${path.basename(art.path)}/${variant.name}`);
|
|
76
|
+
}
|
|
77
|
+
if (result) results.push(result);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return results;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Capture screenshot and compare with baseline.
|
|
84
|
+
*/
|
|
85
|
+
async captureAndCompare(art, variantName, viewport, baseUrl) {
|
|
86
|
+
if (!this.browser) throw new Error("VRT runner not initialized. Call init() first.");
|
|
87
|
+
const snapshotDir = this.options.snapshotDir;
|
|
88
|
+
const artBaseName = path.basename(art.path, ".art.vue");
|
|
89
|
+
const viewportName = viewport.name || `${viewport.width}x${viewport.height}`;
|
|
90
|
+
const snapshotName = `${artBaseName}--${variantName}--${viewportName}.png`;
|
|
91
|
+
const snapshotPath = path.join(snapshotDir, snapshotName);
|
|
92
|
+
const currentPath = path.join(snapshotDir, "current", snapshotName);
|
|
93
|
+
const diffPath = path.join(snapshotDir, "diff", snapshotName);
|
|
94
|
+
await fs.promises.mkdir(path.dirname(snapshotPath), { recursive: true });
|
|
95
|
+
await fs.promises.mkdir(path.join(snapshotDir, "current"), { recursive: true });
|
|
96
|
+
await fs.promises.mkdir(path.join(snapshotDir, "diff"), { recursive: true });
|
|
97
|
+
let context = null;
|
|
98
|
+
let page = null;
|
|
99
|
+
try {
|
|
100
|
+
context = await this.browser.newContext({
|
|
101
|
+
viewport: {
|
|
102
|
+
width: viewport.width,
|
|
103
|
+
height: viewport.height
|
|
104
|
+
},
|
|
105
|
+
deviceScaleFactor: viewport.deviceScaleFactor ?? 1
|
|
106
|
+
});
|
|
107
|
+
page = await context.newPage();
|
|
108
|
+
const variantUrl = this.buildVariantUrl(baseUrl, art.path, variantName);
|
|
109
|
+
const waitUntil = this.capture.waitForNetwork ? "networkidle" : "load";
|
|
110
|
+
await page.goto(variantUrl, { waitUntil });
|
|
111
|
+
await page.waitForSelector(this.capture.waitSelector, { timeout: 1e4 });
|
|
112
|
+
await page.waitForTimeout(this.capture.settleTime);
|
|
113
|
+
if (this.capture.hideElements.length > 0) for (const selector of this.capture.hideElements) await page.evaluate((sel) => {
|
|
114
|
+
document.querySelectorAll(sel).forEach((el) => {
|
|
115
|
+
el.style.visibility = "hidden";
|
|
116
|
+
});
|
|
117
|
+
}, selector);
|
|
118
|
+
if (this.capture.maskElements.length > 0) for (const selector of this.capture.maskElements) await page.evaluate((sel) => {
|
|
119
|
+
document.querySelectorAll(sel).forEach((el) => {
|
|
120
|
+
const htmlEl = el;
|
|
121
|
+
htmlEl.style.background = "#ff00ff";
|
|
122
|
+
htmlEl.style.color = "transparent";
|
|
123
|
+
htmlEl.innerHTML = "";
|
|
124
|
+
});
|
|
125
|
+
}, selector);
|
|
126
|
+
await page.screenshot({
|
|
127
|
+
path: currentPath,
|
|
128
|
+
fullPage: this.capture.fullPage
|
|
129
|
+
});
|
|
130
|
+
const hasBaseline = await fileExists(snapshotPath);
|
|
131
|
+
if (!hasBaseline) {
|
|
132
|
+
await fs.promises.copyFile(currentPath, snapshotPath);
|
|
133
|
+
return {
|
|
134
|
+
artPath: art.path,
|
|
135
|
+
variantName,
|
|
136
|
+
viewport,
|
|
137
|
+
passed: true,
|
|
138
|
+
snapshotPath,
|
|
139
|
+
currentPath,
|
|
140
|
+
isNew: true
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const comparison = await this.compareImages(snapshotPath, currentPath, diffPath);
|
|
144
|
+
const passed = comparison.diffPercentage <= this.options.threshold;
|
|
145
|
+
return {
|
|
146
|
+
artPath: art.path,
|
|
147
|
+
variantName,
|
|
148
|
+
viewport,
|
|
149
|
+
passed,
|
|
150
|
+
snapshotPath,
|
|
151
|
+
currentPath,
|
|
152
|
+
diffPath: passed ? void 0 : diffPath,
|
|
153
|
+
diffPercentage: comparison.diffPercentage,
|
|
154
|
+
diffPixels: comparison.diffPixels,
|
|
155
|
+
totalPixels: comparison.totalPixels
|
|
156
|
+
};
|
|
157
|
+
} catch (error) {
|
|
158
|
+
return {
|
|
159
|
+
artPath: art.path,
|
|
160
|
+
variantName,
|
|
161
|
+
viewport,
|
|
162
|
+
passed: false,
|
|
163
|
+
snapshotPath,
|
|
164
|
+
error: error instanceof Error ? error.message : String(error)
|
|
165
|
+
};
|
|
166
|
+
} finally {
|
|
167
|
+
if (page) await page.close();
|
|
168
|
+
if (context) await context.close();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get the Playwright Page for external use (e.g., a11y auditing).
|
|
173
|
+
*/
|
|
174
|
+
async createPage(viewport) {
|
|
175
|
+
if (!this.browser) throw new Error("VRT runner not initialized. Call init() first.");
|
|
176
|
+
const context = await this.browser.newContext({
|
|
177
|
+
viewport: {
|
|
178
|
+
width: viewport.width,
|
|
179
|
+
height: viewport.height
|
|
180
|
+
},
|
|
181
|
+
deviceScaleFactor: viewport.deviceScaleFactor ?? 1
|
|
182
|
+
});
|
|
183
|
+
const page = await context.newPage();
|
|
184
|
+
return {
|
|
185
|
+
page,
|
|
186
|
+
context
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Update baseline snapshots with current screenshots.
|
|
191
|
+
*/
|
|
192
|
+
async updateBaselines(results) {
|
|
193
|
+
let updated = 0;
|
|
194
|
+
const snapshotDir = this.options.snapshotDir;
|
|
195
|
+
const currentDir = path.join(snapshotDir, "current");
|
|
196
|
+
for (const result of results) {
|
|
197
|
+
const currentPath = path.join(currentDir, path.basename(result.snapshotPath));
|
|
198
|
+
if (await fileExists(currentPath)) {
|
|
199
|
+
await fs.promises.copyFile(currentPath, result.snapshotPath);
|
|
200
|
+
updated++;
|
|
201
|
+
console.log(`[vrt] Updated: ${path.basename(result.snapshotPath)}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return updated;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Approve specific failed results (update their baselines).
|
|
208
|
+
*/
|
|
209
|
+
async approveResults(results, pattern) {
|
|
210
|
+
const toApprove = pattern ? results.filter((r) => {
|
|
211
|
+
const name = `${path.basename(r.artPath, ".art.vue")}/${r.variantName}`;
|
|
212
|
+
return name.includes(pattern) || matchGlob(name, pattern);
|
|
213
|
+
}) : results.filter((r) => !r.passed && !r.error);
|
|
214
|
+
return this.updateBaselines(toApprove);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Clean orphaned snapshots (no corresponding art/variant).
|
|
218
|
+
*/
|
|
219
|
+
async cleanOrphans(artFiles) {
|
|
220
|
+
const snapshotDir = this.options.snapshotDir;
|
|
221
|
+
let cleaned = 0;
|
|
222
|
+
try {
|
|
223
|
+
const files = await fs.promises.readdir(snapshotDir);
|
|
224
|
+
const validNames = new Set();
|
|
225
|
+
for (const art of artFiles) {
|
|
226
|
+
const artBaseName = path.basename(art.path, ".art.vue");
|
|
227
|
+
for (const variant of art.variants) {
|
|
228
|
+
if (variant.skipVrt) continue;
|
|
229
|
+
for (const viewport of this.options.viewports) {
|
|
230
|
+
const viewportName = viewport.name || `${viewport.width}x${viewport.height}`;
|
|
231
|
+
validNames.add(`${artBaseName}--${variant.name}--${viewportName}.png`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
for (const file of files) if (file.endsWith(".png") && !validNames.has(file)) {
|
|
236
|
+
await fs.promises.unlink(path.join(snapshotDir, file));
|
|
237
|
+
cleaned++;
|
|
238
|
+
console.log(`[vrt] Cleaned: ${file}`);
|
|
239
|
+
}
|
|
240
|
+
} catch {}
|
|
241
|
+
return cleaned;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get VRT summary statistics.
|
|
245
|
+
*/
|
|
246
|
+
getSummary(results) {
|
|
247
|
+
return {
|
|
248
|
+
total: results.length,
|
|
249
|
+
passed: results.filter((r) => r.passed && !r.isNew).length,
|
|
250
|
+
failed: results.filter((r) => !r.passed && !r.error).length,
|
|
251
|
+
new: results.filter((r) => r.isNew).length,
|
|
252
|
+
skipped: results.filter((r) => r.error).length,
|
|
253
|
+
duration: Date.now() - this.startTime
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Build URL for variant preview.
|
|
258
|
+
*/
|
|
259
|
+
buildVariantUrl(baseUrl, artPath, variantName) {
|
|
260
|
+
const encodedPath = encodeURIComponent(artPath);
|
|
261
|
+
const encodedVariant = encodeURIComponent(variantName);
|
|
262
|
+
return `${baseUrl}/__musea__/preview?art=${encodedPath}&variant=${encodedVariant}`;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Compare two PNG images and generate a diff image.
|
|
266
|
+
* Returns pixel difference statistics.
|
|
267
|
+
*/
|
|
268
|
+
async compareImages(baselinePath, currentPath, diffPath) {
|
|
269
|
+
const baseline = await readPng(baselinePath);
|
|
270
|
+
const current = await readPng(currentPath);
|
|
271
|
+
if (baseline.width !== current.width || baseline.height !== current.height) {
|
|
272
|
+
const width$1 = Math.max(baseline.width, current.width);
|
|
273
|
+
const height$1 = Math.max(baseline.height, current.height);
|
|
274
|
+
const diff$1 = new PNG({
|
|
275
|
+
width: width$1,
|
|
276
|
+
height: height$1
|
|
277
|
+
});
|
|
278
|
+
for (let i = 0; i < diff$1.data.length; i += 4) {
|
|
279
|
+
diff$1.data[i] = 255;
|
|
280
|
+
diff$1.data[i + 1] = 0;
|
|
281
|
+
diff$1.data[i + 2] = 0;
|
|
282
|
+
diff$1.data[i + 3] = 255;
|
|
283
|
+
}
|
|
284
|
+
await writePng(diff$1, diffPath);
|
|
285
|
+
return {
|
|
286
|
+
diffPixels: width$1 * height$1,
|
|
287
|
+
totalPixels: width$1 * height$1,
|
|
288
|
+
diffPercentage: 100
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const width = baseline.width;
|
|
292
|
+
const height = baseline.height;
|
|
293
|
+
const totalPixels = width * height;
|
|
294
|
+
const diff = new PNG({
|
|
295
|
+
width,
|
|
296
|
+
height
|
|
297
|
+
});
|
|
298
|
+
const useAntiAliasing = this.comparison.antiAliasing ?? true;
|
|
299
|
+
const useAlpha = this.comparison.alpha ?? true;
|
|
300
|
+
const diffColor = this.comparison.diffColor ?? {
|
|
301
|
+
r: 255,
|
|
302
|
+
g: 0,
|
|
303
|
+
b: 0
|
|
304
|
+
};
|
|
305
|
+
let diffPixels = 0;
|
|
306
|
+
const threshold = .1;
|
|
307
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
308
|
+
const idx = (y * width + x) * 4;
|
|
309
|
+
const r1 = baseline.data[idx];
|
|
310
|
+
const g1 = baseline.data[idx + 1];
|
|
311
|
+
const b1 = baseline.data[idx + 2];
|
|
312
|
+
const a1 = useAlpha ? baseline.data[idx + 3] : 255;
|
|
313
|
+
const r2 = current.data[idx];
|
|
314
|
+
const g2 = current.data[idx + 1];
|
|
315
|
+
const b2 = current.data[idx + 2];
|
|
316
|
+
const a2 = useAlpha ? current.data[idx + 3] : 255;
|
|
317
|
+
const delta = colorDelta(r1, g1, b1, a1, r2, g2, b2, a2);
|
|
318
|
+
if (delta > threshold * 255 * 255) if (useAntiAliasing && isAntiAliased(baseline, current, x, y, width, height)) {
|
|
319
|
+
diff.data[idx] = 255;
|
|
320
|
+
diff.data[idx + 1] = 200;
|
|
321
|
+
diff.data[idx + 2] = 0;
|
|
322
|
+
diff.data[idx + 3] = 128;
|
|
323
|
+
} else {
|
|
324
|
+
diffPixels++;
|
|
325
|
+
diff.data[idx] = diffColor.r;
|
|
326
|
+
diff.data[idx + 1] = diffColor.g;
|
|
327
|
+
diff.data[idx + 2] = diffColor.b;
|
|
328
|
+
diff.data[idx + 3] = 255;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
const gray = Math.round((r2 + g2 + b2) / 3);
|
|
332
|
+
diff.data[idx] = gray;
|
|
333
|
+
diff.data[idx + 1] = gray;
|
|
334
|
+
diff.data[idx + 2] = gray;
|
|
335
|
+
diff.data[idx + 3] = 128;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (diffPixels > 0) await writePng(diff, diffPath);
|
|
339
|
+
const diffPercentage = diffPixels / totalPixels * 100;
|
|
340
|
+
return {
|
|
341
|
+
diffPixels,
|
|
342
|
+
totalPixels,
|
|
343
|
+
diffPercentage
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Generate VRT report in HTML format.
|
|
349
|
+
* Supports side-by-side, overlay, and slider comparison modes.
|
|
350
|
+
*/
|
|
351
|
+
function generateVrtReport(results, summary) {
|
|
352
|
+
const formatDuration = (ms) => {
|
|
353
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
354
|
+
const seconds = Math.floor(ms / 1e3);
|
|
355
|
+
const minutes = Math.floor(seconds / 60);
|
|
356
|
+
if (minutes === 0) return `${seconds}s`;
|
|
357
|
+
return `${minutes}m ${seconds % 60}s`;
|
|
358
|
+
};
|
|
359
|
+
const timestamp = new Date().toLocaleString("ja-JP", {
|
|
360
|
+
year: "numeric",
|
|
361
|
+
month: "2-digit",
|
|
362
|
+
day: "2-digit",
|
|
363
|
+
hour: "2-digit",
|
|
364
|
+
minute: "2-digit"
|
|
365
|
+
});
|
|
366
|
+
const html = `<!DOCTYPE html>
|
|
367
|
+
<html lang="en">
|
|
368
|
+
<head>
|
|
369
|
+
<meta charset="UTF-8">
|
|
370
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
371
|
+
<title>VRT Report - Musea</title>
|
|
372
|
+
<style>
|
|
373
|
+
:root {
|
|
374
|
+
--musea-bg-primary: #0d0d0d;
|
|
375
|
+
--musea-bg-secondary: #1a1815;
|
|
376
|
+
--musea-bg-tertiary: #252220;
|
|
377
|
+
--musea-accent: #a34828;
|
|
378
|
+
--musea-accent-hover: #c45a32;
|
|
379
|
+
--musea-text: #e6e9f0;
|
|
380
|
+
--musea-text-muted: #7b8494;
|
|
381
|
+
--musea-border: #3a3530;
|
|
382
|
+
--musea-success: #4ade80;
|
|
383
|
+
--musea-error: #f87171;
|
|
384
|
+
--musea-info: #60a5fa;
|
|
385
|
+
--musea-warning: #fbbf24;
|
|
386
|
+
}
|
|
387
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
388
|
+
body {
|
|
389
|
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
390
|
+
background: var(--musea-bg-primary);
|
|
391
|
+
color: var(--musea-text);
|
|
392
|
+
min-height: 100vh;
|
|
393
|
+
line-height: 1.5;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.header {
|
|
397
|
+
background: var(--musea-bg-secondary);
|
|
398
|
+
border-bottom: 1px solid var(--musea-border);
|
|
399
|
+
padding: 1rem 2rem;
|
|
400
|
+
display: flex;
|
|
401
|
+
align-items: center;
|
|
402
|
+
justify-content: space-between;
|
|
403
|
+
position: sticky;
|
|
404
|
+
top: 0;
|
|
405
|
+
z-index: 100;
|
|
406
|
+
}
|
|
407
|
+
.header-left { display: flex; align-items: center; gap: 1rem; }
|
|
408
|
+
.logo { font-size: 1.25rem; font-weight: 700; color: var(--musea-accent); }
|
|
409
|
+
.header-title { color: var(--musea-text-muted); font-size: 0.875rem; }
|
|
410
|
+
.header-meta { display: flex; align-items: center; gap: 1.5rem; font-size: 0.8125rem; color: var(--musea-text-muted); }
|
|
411
|
+
.header-meta span { display: flex; align-items: center; gap: 0.375rem; }
|
|
412
|
+
|
|
413
|
+
.main { max-width: 1400px; margin: 0 auto; padding: 2rem; }
|
|
414
|
+
|
|
415
|
+
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
|
|
416
|
+
.stat { background: var(--musea-bg-secondary); border: 1px solid var(--musea-border); border-radius: 8px; padding: 1.25rem; position: relative; overflow: hidden; }
|
|
417
|
+
.stat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
|
|
418
|
+
.stat.passed::before { background: var(--musea-success); }
|
|
419
|
+
.stat.failed::before { background: var(--musea-error); }
|
|
420
|
+
.stat.new::before { background: var(--musea-info); }
|
|
421
|
+
.stat.skipped::before { background: var(--musea-warning); }
|
|
422
|
+
.stat-value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; margin-bottom: 0.25rem; }
|
|
423
|
+
.stat.passed .stat-value { color: var(--musea-success); }
|
|
424
|
+
.stat.failed .stat-value { color: var(--musea-error); }
|
|
425
|
+
.stat.new .stat-value { color: var(--musea-info); }
|
|
426
|
+
.stat.skipped .stat-value { color: var(--musea-warning); }
|
|
427
|
+
.stat-label { color: var(--musea-text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; }
|
|
428
|
+
|
|
429
|
+
.filters { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
|
|
430
|
+
.filter-btn { background: var(--musea-bg-secondary); border: 1px solid var(--musea-border); color: var(--musea-text); padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.8125rem; font-weight: 500; transition: all 0.15s ease; }
|
|
431
|
+
.filter-btn:hover { background: var(--musea-bg-tertiary); border-color: var(--musea-text-muted); }
|
|
432
|
+
.filter-btn.active { background: var(--musea-accent); border-color: var(--musea-accent); color: #fff; }
|
|
433
|
+
.filter-btn .count { opacity: 0.7; margin-left: 0.25rem; }
|
|
434
|
+
|
|
435
|
+
/* Comparison mode toggle */
|
|
436
|
+
.compare-modes { display: flex; gap: 0.25rem; margin-bottom: 1.5rem; background: var(--musea-bg-secondary); border-radius: 6px; padding: 0.25rem; width: fit-content; }
|
|
437
|
+
.compare-mode-btn { background: none; border: none; color: var(--musea-text-muted); padding: 0.375rem 0.75rem; border-radius: 4px; cursor: pointer; font-size: 0.75rem; font-weight: 500; transition: all 0.15s ease; }
|
|
438
|
+
.compare-mode-btn.active { background: var(--musea-bg-tertiary); color: var(--musea-text); }
|
|
439
|
+
|
|
440
|
+
.results { display: flex; flex-direction: column; gap: 0.75rem; }
|
|
441
|
+
.result { background: var(--musea-bg-secondary); border: 1px solid var(--musea-border); border-radius: 8px; overflow: hidden; transition: border-color 0.15s ease; }
|
|
442
|
+
.result:hover { border-color: var(--musea-text-muted); }
|
|
443
|
+
.result-header { padding: 1rem 1.25rem; display: flex; justify-content: space-between; align-items: center; cursor: pointer; border-left: 3px solid transparent; background: var(--musea-bg-tertiary); }
|
|
444
|
+
.result.passed .result-header { border-left-color: var(--musea-success); }
|
|
445
|
+
.result.failed .result-header { border-left-color: var(--musea-error); }
|
|
446
|
+
.result.new .result-header { border-left-color: var(--musea-info); }
|
|
447
|
+
.result.error .result-header { border-left-color: var(--musea-warning); }
|
|
448
|
+
|
|
449
|
+
.result-info { display: flex; align-items: center; gap: 1rem; }
|
|
450
|
+
.result-name { font-weight: 600; font-size: 0.9375rem; }
|
|
451
|
+
.result-meta { color: var(--musea-text-muted); font-size: 0.8125rem; padding: 0.125rem 0.5rem; background: var(--musea-bg-secondary); border-radius: 4px; }
|
|
452
|
+
.result-badge { padding: 0.25rem 0.625rem; border-radius: 4px; font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
453
|
+
.result.passed .result-badge { background: rgba(74, 222, 128, 0.15); color: var(--musea-success); }
|
|
454
|
+
.result.failed .result-badge { background: rgba(248, 113, 113, 0.15); color: var(--musea-error); }
|
|
455
|
+
.result.new .result-badge { background: rgba(96, 165, 250, 0.15); color: var(--musea-info); }
|
|
456
|
+
.result.error .result-badge { background: rgba(251, 191, 36, 0.15); color: var(--musea-warning); }
|
|
457
|
+
|
|
458
|
+
.result-body { border-top: 1px solid var(--musea-border); }
|
|
459
|
+
.result-details { padding: 0.875rem 1.25rem; font-size: 0.8125rem; color: var(--musea-text-muted); font-family: 'SF Mono', 'Fira Code', monospace; background: var(--musea-bg-primary); }
|
|
460
|
+
.result-details.error { color: var(--musea-error); }
|
|
461
|
+
|
|
462
|
+
.result-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; padding: 1.25rem; background: var(--musea-bg-primary); }
|
|
463
|
+
.result-images.overlay { grid-template-columns: 1fr; }
|
|
464
|
+
.image-container { background: var(--musea-bg-secondary); border: 1px solid var(--musea-border); border-radius: 6px; overflow: hidden; }
|
|
465
|
+
.image-label { padding: 0.625rem 0.875rem; font-size: 0.6875rem; font-weight: 600; color: var(--musea-text-muted); text-transform: uppercase; letter-spacing: 0.08em; background: var(--musea-bg-tertiary); border-bottom: 1px solid var(--musea-border); }
|
|
466
|
+
.image-wrapper { padding: 0.5rem; background: repeating-conic-gradient(var(--musea-bg-tertiary) 0% 25%, var(--musea-bg-secondary) 0% 50%) 50% / 16px 16px; }
|
|
467
|
+
.image-container img { width: 100%; height: auto; display: block; border-radius: 2px; }
|
|
468
|
+
|
|
469
|
+
/* Slider comparison */
|
|
470
|
+
.slider-compare { position: relative; overflow: hidden; }
|
|
471
|
+
.slider-compare img { display: block; width: 100%; }
|
|
472
|
+
.slider-overlay { position: absolute; top: 0; left: 0; bottom: 0; overflow: hidden; border-right: 2px solid var(--musea-accent); }
|
|
473
|
+
.slider-overlay img { display: block; min-width: 100%; height: 100%; object-fit: cover; }
|
|
474
|
+
|
|
475
|
+
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--musea-text-muted); }
|
|
476
|
+
.all-passed { background: rgba(74, 222, 128, 0.1); border: 1px solid rgba(74, 222, 128, 0.2); border-radius: 8px; padding: 1.5rem; text-align: center; margin-bottom: 1.5rem; }
|
|
477
|
+
.all-passed-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
|
|
478
|
+
.all-passed-text { color: var(--musea-success); font-weight: 600; }
|
|
479
|
+
</style>
|
|
480
|
+
</head>
|
|
481
|
+
<body>
|
|
482
|
+
<header class="header">
|
|
483
|
+
<div class="header-left">
|
|
484
|
+
<div class="logo">Musea</div>
|
|
485
|
+
<span class="header-title">Visual Regression Report</span>
|
|
486
|
+
</div>
|
|
487
|
+
<div class="header-meta">
|
|
488
|
+
<span>
|
|
489
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
490
|
+
<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>
|
|
491
|
+
</svg>
|
|
492
|
+
${formatDuration(summary.duration)}
|
|
493
|
+
</span>
|
|
494
|
+
<span>
|
|
495
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
496
|
+
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/>
|
|
497
|
+
</svg>
|
|
498
|
+
${timestamp}
|
|
499
|
+
</span>
|
|
500
|
+
</div>
|
|
501
|
+
</header>
|
|
502
|
+
|
|
503
|
+
<main class="main">
|
|
504
|
+
<div class="summary">
|
|
505
|
+
<div class="stat passed"><div class="stat-value">${summary.passed}</div><div class="stat-label">Passed</div></div>
|
|
506
|
+
<div class="stat failed"><div class="stat-value">${summary.failed}</div><div class="stat-label">Failed</div></div>
|
|
507
|
+
<div class="stat new"><div class="stat-value">${summary.new}</div><div class="stat-label">New</div></div>
|
|
508
|
+
<div class="stat skipped"><div class="stat-value">${summary.skipped}</div><div class="stat-label">Skipped</div></div>
|
|
509
|
+
</div>
|
|
510
|
+
|
|
511
|
+
${summary.failed === 0 && summary.skipped === 0 && summary.total > 0 ? `<div class="all-passed">
|
|
512
|
+
<div class="all-passed-icon">✓</div>
|
|
513
|
+
<div class="all-passed-text">All ${summary.total} visual tests passed</div>
|
|
514
|
+
</div>` : ""}
|
|
515
|
+
|
|
516
|
+
<div class="filters">
|
|
517
|
+
<button class="filter-btn active" data-filter="all">All<span class="count">(${summary.total})</span></button>
|
|
518
|
+
<button class="filter-btn" data-filter="failed">Failed<span class="count">(${summary.failed})</span></button>
|
|
519
|
+
<button class="filter-btn" data-filter="passed">Passed<span class="count">(${summary.passed})</span></button>
|
|
520
|
+
<button class="filter-btn" data-filter="new">New<span class="count">(${summary.new})</span></button>
|
|
521
|
+
</div>
|
|
522
|
+
|
|
523
|
+
<div class="compare-modes">
|
|
524
|
+
<button class="compare-mode-btn active" data-mode="side-by-side">Side by Side</button>
|
|
525
|
+
<button class="compare-mode-btn" data-mode="overlay">Overlay</button>
|
|
526
|
+
<button class="compare-mode-btn" data-mode="slider">Slider</button>
|
|
527
|
+
</div>
|
|
528
|
+
|
|
529
|
+
<div class="results">
|
|
530
|
+
${results.length === 0 ? `<div class="empty-state"><p>No visual tests found</p></div>` : results.map((r) => {
|
|
531
|
+
const status = r.error ? "error" : r.isNew ? "new" : r.passed ? "passed" : "failed";
|
|
532
|
+
const badge = r.error ? "Error" : r.isNew ? "New" : r.passed ? "Passed" : "Failed";
|
|
533
|
+
const artName = path.basename(r.artPath, ".art.vue");
|
|
534
|
+
const viewportName = r.viewport.name || `${r.viewport.width}×${r.viewport.height}`;
|
|
535
|
+
let details = "";
|
|
536
|
+
if (r.error) details = `<div class="result-details error">${escapeHtml(r.error)}</div>`;
|
|
537
|
+
else if (r.diffPercentage !== void 0) {
|
|
538
|
+
const diffFormatted = r.diffPercentage.toFixed(3);
|
|
539
|
+
const pixelsFormatted = r.diffPixels?.toLocaleString() ?? "0";
|
|
540
|
+
const totalFormatted = r.totalPixels?.toLocaleString() ?? "0";
|
|
541
|
+
details = `<div class="result-details">diff: ${diffFormatted}% (${pixelsFormatted} / ${totalFormatted} pixels)</div>`;
|
|
542
|
+
}
|
|
543
|
+
let images = "";
|
|
544
|
+
if (!r.error && !r.passed && r.diffPath) images = `<div class="result-images" data-baseline="file://${r.snapshotPath}" data-current="file://${r.currentPath}" data-diff="file://${r.diffPath}">
|
|
545
|
+
${r.snapshotPath ? `<div class="image-container"><div class="image-label">Baseline</div><div class="image-wrapper"><img src="file://${r.snapshotPath}" alt="Baseline" loading="lazy" /></div></div>` : ""}
|
|
546
|
+
${r.currentPath ? `<div class="image-container"><div class="image-label">Current</div><div class="image-wrapper"><img src="file://${r.currentPath}" alt="Current" loading="lazy" /></div></div>` : ""}
|
|
547
|
+
${r.diffPath ? `<div class="image-container"><div class="image-label">Diff</div><div class="image-wrapper"><img src="file://${r.diffPath}" alt="Diff" loading="lazy" /></div></div>` : ""}
|
|
548
|
+
</div>`;
|
|
549
|
+
const hasBody = details || images;
|
|
550
|
+
return `<div class="result ${status}" data-status="${status}">
|
|
551
|
+
<div class="result-header">
|
|
552
|
+
<div class="result-info">
|
|
553
|
+
<div class="result-name">${escapeHtml(artName)} / ${escapeHtml(r.variantName)}</div>
|
|
554
|
+
<div class="result-meta">${escapeHtml(viewportName)}</div>
|
|
555
|
+
</div>
|
|
556
|
+
<span class="result-badge">${badge}</span>
|
|
557
|
+
</div>
|
|
558
|
+
${hasBody ? `<div class="result-body">${details}${images}</div>` : ""}
|
|
559
|
+
</div>`;
|
|
560
|
+
}).join("")}
|
|
561
|
+
</div>
|
|
562
|
+
</main>
|
|
563
|
+
|
|
564
|
+
<script>
|
|
565
|
+
// Filter buttons
|
|
566
|
+
document.querySelectorAll('.filter-btn').forEach(btn => {
|
|
567
|
+
btn.addEventListener('click', () => {
|
|
568
|
+
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
|
|
569
|
+
btn.classList.add('active');
|
|
570
|
+
const filter = btn.dataset.filter;
|
|
571
|
+
document.querySelectorAll('.result').forEach(result => {
|
|
572
|
+
result.style.display = (filter === 'all' || result.dataset.status === filter) ? 'block' : 'none';
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// Compare mode buttons
|
|
578
|
+
document.querySelectorAll('.compare-mode-btn').forEach(btn => {
|
|
579
|
+
btn.addEventListener('click', () => {
|
|
580
|
+
document.querySelectorAll('.compare-mode-btn').forEach(b => b.classList.remove('active'));
|
|
581
|
+
btn.classList.add('active');
|
|
582
|
+
// Mode switching would update result-images display; this is a static report for now
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
</script>
|
|
586
|
+
</body>
|
|
587
|
+
</html>`;
|
|
588
|
+
return html;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Generate VRT JSON report for CI integration.
|
|
592
|
+
*/
|
|
593
|
+
function generateVrtJsonReport(results, summary) {
|
|
594
|
+
return JSON.stringify({
|
|
595
|
+
timestamp: new Date().toISOString(),
|
|
596
|
+
summary,
|
|
597
|
+
results: results.map((r) => ({
|
|
598
|
+
art: path.basename(r.artPath, ".art.vue"),
|
|
599
|
+
variant: r.variantName,
|
|
600
|
+
viewport: r.viewport.name || `${r.viewport.width}x${r.viewport.height}`,
|
|
601
|
+
status: r.error ? "error" : r.isNew ? "new" : r.passed ? "passed" : "failed",
|
|
602
|
+
diffPercentage: r.diffPercentage,
|
|
603
|
+
error: r.error
|
|
604
|
+
}))
|
|
605
|
+
}, null, 2);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Read PNG file and return PNG object.
|
|
609
|
+
*/
|
|
610
|
+
async function readPng(filepath) {
|
|
611
|
+
return new Promise((resolve, reject) => {
|
|
612
|
+
fs.createReadStream(filepath).pipe(new PNG()).on("parsed", function() {
|
|
613
|
+
resolve(this);
|
|
614
|
+
}).on("error", reject);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Write PNG object to file.
|
|
619
|
+
*/
|
|
620
|
+
async function writePng(png, filepath) {
|
|
621
|
+
return new Promise((resolve, reject) => {
|
|
622
|
+
png.pack().pipe(fs.createWriteStream(filepath)).on("finish", resolve).on("error", reject);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Calculate color delta using YIQ color space.
|
|
627
|
+
*/
|
|
628
|
+
function colorDelta(r1, g1, b1, a1, r2, g2, b2, a2) {
|
|
629
|
+
if (a1 !== 255) {
|
|
630
|
+
r1 = blend(r1, 255, a1 / 255);
|
|
631
|
+
g1 = blend(g1, 255, a1 / 255);
|
|
632
|
+
b1 = blend(b1, 255, a1 / 255);
|
|
633
|
+
}
|
|
634
|
+
if (a2 !== 255) {
|
|
635
|
+
r2 = blend(r2, 255, a2 / 255);
|
|
636
|
+
g2 = blend(g2, 255, a2 / 255);
|
|
637
|
+
b2 = blend(b2, 255, a2 / 255);
|
|
638
|
+
}
|
|
639
|
+
const y1 = r1 * .29889531 + g1 * .58662247 + b1 * .11448223;
|
|
640
|
+
const i1 = r1 * .59597799 - g1 * .2741761 - b1 * .32180189;
|
|
641
|
+
const q1 = r1 * .21147017 - g1 * .52261711 + b1 * .31114694;
|
|
642
|
+
const y2 = r2 * .29889531 + g2 * .58662247 + b2 * .11448223;
|
|
643
|
+
const i2 = r2 * .59597799 - g2 * .2741761 - b2 * .32180189;
|
|
644
|
+
const q2 = r2 * .21147017 - g2 * .52261711 + b2 * .31114694;
|
|
645
|
+
const dy = y1 - y2;
|
|
646
|
+
const di = i1 - i2;
|
|
647
|
+
const dq = q1 - q2;
|
|
648
|
+
return dy * dy * .5053 + di * di * .299 + dq * dq * .1957;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Blend foreground with background using alpha.
|
|
652
|
+
*/
|
|
653
|
+
function blend(fg, bg, alpha) {
|
|
654
|
+
return bg + (fg - bg) * alpha;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Check if file exists.
|
|
658
|
+
*/
|
|
659
|
+
async function fileExists(filepath) {
|
|
660
|
+
try {
|
|
661
|
+
await fs.promises.access(filepath);
|
|
662
|
+
return true;
|
|
663
|
+
} catch {
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Simple anti-aliasing detection.
|
|
669
|
+
* A pixel is likely anti-aliased if its neighbors have high contrast in opposite directions.
|
|
670
|
+
*/
|
|
671
|
+
function isAntiAliased(img1, img2, x, y, width, height) {
|
|
672
|
+
const minX = Math.max(0, x - 1);
|
|
673
|
+
const maxX = Math.min(width - 1, x + 1);
|
|
674
|
+
const minY = Math.max(0, y - 1);
|
|
675
|
+
const maxY = Math.min(height - 1, y + 1);
|
|
676
|
+
let zeroes = 0;
|
|
677
|
+
let positives = 0;
|
|
678
|
+
let negatives = 0;
|
|
679
|
+
for (let ny = minY; ny <= maxY; ny++) for (let nx = minX; nx <= maxX; nx++) {
|
|
680
|
+
if (nx === x && ny === y) continue;
|
|
681
|
+
const idx = (ny * width + nx) * 4;
|
|
682
|
+
const delta = colorDelta(img1.data[idx], img1.data[idx + 1], img1.data[idx + 2], img1.data[idx + 3], img2.data[idx], img2.data[idx + 1], img2.data[idx + 2], img2.data[idx + 3]);
|
|
683
|
+
if (delta === 0) zeroes++;
|
|
684
|
+
else if (delta > 0) positives++;
|
|
685
|
+
else negatives++;
|
|
686
|
+
}
|
|
687
|
+
return zeroes > 0 && (positives > 0 || negatives > 0) && positives + negatives < 4;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Simple glob matching for pattern-based filtering.
|
|
691
|
+
*/
|
|
692
|
+
function matchGlob(filepath, pattern) {
|
|
693
|
+
const regex = pattern.replace(/\./g, "\\.").replace(/\*\*/g, ".*").replace(/\*(?!\*)/g, "[^/]*");
|
|
694
|
+
return new RegExp(`^${regex}$`).test(filepath);
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Escape HTML special characters.
|
|
698
|
+
*/
|
|
699
|
+
function escapeHtml(str) {
|
|
700
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
701
|
+
}
|
|
702
|
+
var vrt_default = MuseaVrtRunner;
|
|
703
|
+
|
|
704
|
+
//#endregion
|
|
705
|
+
export { MuseaVrtRunner, generateVrtJsonReport, generateVrtReport, vrt_default };
|
|
706
|
+
//# sourceMappingURL=vrt-DP87vGIA.js.map
|