Create a render parity watchdog: screenshots diffs, DOM invariants, and regressions.
- User
Create a render parity watchdog: screenshots diffs, DOM invariants, and regressions.
Assistant
Create a render parity watchdog: screenshots diffs, DOM invariants, and regressions.
The user wants a "render parity watchdog" - essentially a visual regression and DOM monitoring tool. This should:
Since this needs to be a single HTML file with good visual design, I'll create:
Design approach:
Features to include:
Let me build this with:
A visual regression and DOM monitoring dashboard with:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Render Parity Watchdog</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0e14;
--bg-elevated: #0f1419;
--fg: #e6e6e6;
--muted: #5c6773;
--accent: #00e5c7;
--accent-dim: rgba(0, 229, 199, 0.15);
--danger: #ff6b6b;
--danger-dim: rgba(255, 107, 107, 0.15);
--warning: #ffcc00;
--warning-dim: rgba(255, 204, 0, 0.15);
--card: #141a22;
--border: #1f2937;
--diff-added: #00e5c7;
--diff-removed: #ff6b6b;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
}
.font-mono {
font-family: 'JetBrains Mono', monospace;
}
/* Background pattern */
.bg-grid {
background-image:
linear-gradient(rgba(0, 229, 199, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 229, 199, 0.03) 1px, transparent 1px);
background-size: 32px 32px;
}
/* Glow effects */
.glow-accent {
box-shadow: 0 0 20px rgba(0, 229, 199, 0.2), 0 0 40px rgba(0, 229, 199, 0.1);
}
.glow-danger {
box-shadow: 0 0 20px rgba(255, 107, 107, 0.2), 0 0 40px rgba(255, 107, 107, 0.1);
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg);
}
::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--muted);
}
/* Diff slider */
.diff-container {
position: relative;
overflow: hidden;
}
.diff-slider {
position: absolute;
top: 0;
bottom: 0;
width: 4px;
background: var(--accent);
cursor: ew-resize;
z-index: 20;
}
.diff-slider::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 40px;
height: 40px;
background: var(--accent);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.diff-slider::after {
content: '⟷';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--bg);
font-weight: 700;
font-size: 16px;
}
/* Animations */
@keyframes pulse-ring {
0% { transform: scale(1); opacity: 1; }
100% { transform: scale(1.5); opacity: 0; }
}
@keyframes scan-line {
0% { transform: translateY(-100%); }
100% { transform: translateY(100%); }
}
@keyframes fade-in-up {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes count-up {
from { opacity: 0; transform: scale(0.8); }
to { opacity: 1; transform: scale(1); }
}
.animate-fade-in-up {
animation: fade-in-up 0.5s ease-out forwards;
opacity: 0;
}
.pulse-ring::before {
content: '';
position: absolute;
inset: 0;
border-radius: 50%;
background: currentColor;
animation: pulse-ring 2s ease-out infinite;
}
.scan-effect {
position: relative;
overflow: hidden;
}
.scan-effect::after {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(180deg, transparent 0%, rgba(0, 229, 199, 0.1) 50%, transparent 100%);
animation: scan-line 3s ease-in-out infinite;
pointer-events: none;
}
/* Status badges */
.status-pass {
background: var(--accent-dim);
color: var(--accent);
border: 1px solid rgba(0, 229, 199, 0.3);
}
.status-fail {
background: var(--danger-dim);
color: var(--danger);
border: 1px solid rgba(255, 107, 107, 0.3);
}
.status-warn {
background: var(--warning-dim);
color: var(--warning);
border: 1px solid rgba(255, 204, 0, 0.3);
}
/* Focus states */
button:focus-visible, [tabindex]:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* Hover interactions */
.hover-lift {
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.hover-lift:hover {
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
/* Progress bar */
.progress-bar {
background: linear-gradient(90deg, var(--accent) 0%, rgba(0, 229, 199, 0.5) 100%);
}
</style>
</head>
<body class="bg-grid">
<!-- Header -->
<header class="border-b border-[--border] bg-[--bg-elevated]/80 backdrop-blur-sm sticky top-0 z-50">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-16">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-lg bg-[--accent-dim] border border-[--accent]/30 flex items-center justify-center">
<svg class="w-5 h-5 text-[--accent]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
<div>
<h1 class="text-lg font-semibold tracking-tight">Render Parity Watchdog</h1>
<p class="text-xs text-[--muted]">Visual regression monitor</p>
</div>
</div>
<div class="flex items-center gap-4">
<div id="liveIndicator" class="flex items-center gap-2 px-3 py-1.5 rounded-full bg-[--accent-dim] border border-[--accent]/30">
<span class="relative flex h-2 w-2">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-[--accent] opacity-75"></span>
<span class="relative inline-flex rounded-full h-2 w-2 bg-[--accent]"></span>
</span>
<span class="text-xs font-medium text-[--accent]">LIVE</span>
</div>
<button id="runTestsBtn" class="px-4 py-2 bg-[--accent] text-[--bg] rounded-lg font-medium text-sm hover:opacity-90 transition-opacity flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
Run Suite
</button>
</div>
</div>
</div>
</header>
<main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Stats Overview -->
<section class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">
<div class="animate-fade-in-up bg-[--card] rounded-xl p-4 border border-[--border] hover-lift" style="animation-delay: 0.1s">
<div class="flex items-center justify-between mb-2">
<span class="text-[--muted] text-sm">Tests Run</span>
<svg class="w-4 h-4 text-[--muted]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
</svg>
</div>
<div class="text-3xl font-bold text-[--fg] font-mono" id="statTests">247</div>
<div class="text-xs text-[--accent] mt-1">+12 today</div>
</div>
<div class="animate-fade-in-up bg-[--card] rounded-xl p-4 border border-[--border] hover-lift" style="animation-delay: 0.2s">
<div class="flex items-center justify-between mb-2">
<span class="text-[--muted] text-sm">Passing</span>
<svg class="w-4 h-4 text-[--accent]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
</div>
<div class="text-3xl font-bold text-[--accent] font-mono" id="statPassing">238</div>
<div class="text-xs text-[--muted] mt-1">96.4% rate</div>
</div>
<div class="animate-fade-in-up bg-[--card] rounded-xl p-4 border border-[--border] hover-lift" style="animation-delay: 0.3s">
<div class="flex items-center justify-between mb-2">
<span class="text-[--muted] text-sm">Regressions</span>
<svg class="w-4 h-4 text-[--danger]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
<div class="text-3xl font-bold text-[--danger] font-mono" id="statRegressions">3</div>
<div class="text-xs text-[--danger] mt-1">2 critical</div>
</div>
<div class="animate-fade-in-up bg-[--card] rounded-xl p-4 border border-[--border] hover-lift" style="animation-delay: 0.4s">
<div class="flex items-center justify-between mb-2">
<span class="text-[--muted] text-sm">Diff Coverage</span>
<svg class="w-4 h-4 text-[--muted]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
</div>
<div class="text-3xl font-bold text-[--fg] font-mono">89<span class="text-lg">%</span></div>
<div class="w-full bg-[--border] rounded-full h-1.5 mt-2">
<div class="progress-bar h-1.5 rounded-full" style="width: 89%"></div>
</div>
</div>
</section>
<!-- Main Content Grid -->
<div class="grid lg:grid-cols-3 gap-6">
<!-- Screenshot Diff Viewer -->
<section class="lg:col-span-2 animate-fade-in-up" style="animation-delay: 0.5s">
<div class="bg-[--card] rounded-xl border border-[--border] overflow-hidden">
<div class="px-5 py-4 border-b border-[--border] flex items-center justify-between">
<div>
<h2 class="font-semibold">Screenshot Diff Viewer</h2>
<p class="text-xs text-[--muted] mt-0.5">Baseline vs Current Render</p>
</div>
<div class="flex items-center gap-2">
<button class="view-toggle px-3 py-1.5 text-xs rounded-lg bg-[--accent-dim] text-[--accent] border border-[--accent]/30" data-view="slider">Slider</button>
<button class="view-toggle px-3 py-1.5 text-xs rounded-lg bg-[--bg] text-[--muted] border border-[--border]" data-view="overlay">Overlay</button>
<button class="view-toggle px-3 py-1.5 text-xs rounded-lg bg-[--bg] text-[--muted] border border-[--border]" data-view="side-by-side">Side by Side</button>
</div>
</div>
<div class="p-5">
<!-- Test selector -->
<div class="flex items-center gap-3 mb-4">
<select id="testSelector" class="bg-[--bg] border border-[--border] rounded-lg px-3 py-2 text-sm focus:border-[--accent] focus:outline-none flex-1">
<option value="hero">Hero Component - Desktop</option>
<option value="nav">Navigation - Mobile Menu</option>
<option value="form">Contact Form - Validation</option>
<option value="pricing">Pricing Table - Expanded</option>
</select>
<div class="status-fail px-2 py-1 rounded text-xs font-medium">DIFF DETECTED</div>
</div>
<!-- Diff viewer -->
<div id="diffViewer" class="diff-container rounded-lg overflow-hidden bg-[--bg] scan-effect" style="height: 320px;">
<canvas id="diffCanvas" class="w-full h-full"></canvas>
<div id="diffSlider" class="diff-slider" style="left: 50%;"></div>
<div class="absolute top-3 left-3 px-2 py-1 bg-[--bg]/80 backdrop-blur-sm rounded text-xs font-mono text-[--muted]">BASELINE</div>
<div class="absolute top-3 right-3 px-2 py-1 bg-[--bg]/80 backdrop-blur-sm rounded text-xs font-mono text-[--accent]">CURRENT</div>
</div>
<!-- Diff stats -->
<div class="grid grid-cols-3 gap-4 mt-4">
<div class="text-center p-3 bg-[--bg] rounded-lg">
<div class="text-lg font-bold font-mono text-[--diff-added]" id="diffAdded">+2,847</div>
<div class="text-xs text-[--muted]">Pixels Added</div>
</div>
<div class="text-center p-3 bg-[--bg] rounded-lg">
<div class="text-lg font-bold font-mono text-[--diff-removed]" id="diffRemoved">-1,203</div>
<div class="text-xs text-[--muted]">Pixels Removed</div>
</div>
<div class="text-center p-3 bg-[--bg] rounded-lg">
<div class="text-lg font-bold font-mono text-[--warning]" id="diffPercent">0.42%</div>
<div class="text-xs text-[--muted]">Diff Ratio</div>
</div>
</div>
</div>
</div>
</section>
<!-- DOM Invariants -->
<section class="animate-fade-in-up" style="animation-delay: 0.6s">
<div class="bg-[--card] rounded-xl border border-[--border] overflow-hidden h-full">
<div class="px-5 py-4 border-b border-[--border]">
<h2 class="font-semibold">DOM Invariants</h2>
<p class="text-xs text-[--muted] mt-0.5">Structural expectations validation</p>
</div>
<div class="p-4 space-y-3 max-h-[480px] overflow-y-auto" id="invariantsList">
<!-- Populated by JS -->
</div>
</div>
</section>
</div>
<!-- Regressions Timeline -->
<section class="mt-6 animate-fade-in-up" style="animation-delay: 0.7s">
<div class="bg-[--card] rounded-xl border border-[--border] overflow-hidden">
<div class="px-5 py-4 border-b border-[--border] flex items-center justify-between">
<div>
<h2 class="font-semibold">Regression Timeline</h2>
<p class="text-xs text-[--muted] mt-0.5">Detected anomalies and resolutions</p>
</div>
<div class="flex items-center gap-2">
<button class="filter-btn px-3 py-1.5 text-xs rounded-lg bg-[--accent-dim] text-[--accent] border border-[--accent]/30" data-filter="all">All</button>
<button class="filter-btn px-3 py-1.5 text-xs rounded-lg bg-[--bg] text-[--muted] border border-[--border]" data-filter="open">Open</button>
<button class="filter-btn px-3 py-1.5 text-xs rounded-lg bg-[--bg] text-[--muted] border border-[--border]" data-filter="resolved">Resolved</button>
</div>
</div>
<div class="p-5">
<div class="relative" id="timelineContainer">
<!-- Timeline line -->
<div class="absolute left-4 top-0 bottom-0 w-px bg-[--border]"></div>
<!-- Timeline items -->
<div class="space-y-6" id="timelineList">
<!-- Populated by JS -->
</div>
</div>
</div>
</div>
</section>
<!-- Test Runner Modal -->
<div id="testRunnerModal" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 hidden items-center justify-center p-4">
<div class="bg-[--card] rounded-2xl border border-[--border] max-w-md w-full p-6">
<div class="text-center">
<div class="w-16 h-16 mx-auto mb-4 rounded-full bg-[--accent-dim] flex items-center justify-center">
<svg class="w-8 h-8 text-[--accent] animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
</div>
<h3 class="text-lg font-semibold mb-2">Running Test Suite</h3>
<p class="text-sm text-[--muted] mb-4">Capturing screenshots and validating invariants...</p>
<div class="w-full bg-[--bg] rounded-full h-2 mb-2">
<div id="testProgress" class="progress-bar h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
</div>
<p class="text-xs font-mono text-[--muted]" id="testStatus">Initializing...</p>
</div>
</div>
</div>
</main>
<script>
// ===== Data =====
const invariantsData = [
{ id: 1, name: 'header.logo.visible', type: 'exists', selector: 'header .logo', status: 'pass', lastChecked: '2s ago' },
{ id: 2, name: 'nav.links.count', type: 'count', selector: 'nav a', expected: 8, actual: 8, status: 'pass', lastChecked: '2s ago' },
{ id: 3, name: 'hero.cta.bgColor', type: 'style', prop: 'background-color', expected: '#00e5c7', actual: '#00e5c7', status: 'pass', lastChecked: '2s ago' },
{ id: 4, name: 'form.email.required', type: 'attr', selector: 'input[type="email"]', attr: 'required', status: 'pass', lastChecked: '2s ago' },
{ id: 5, name: 'pricing.cards.zIndex', type: 'style', prop: 'z-index', expected: 'featured: 10', actual: 'featured: 5', status: 'fail', lastChecked: '2s ago' },
{ id: 6, name: 'footer.links.count', type: 'count', selector: 'footer a', expected: 12, actual: 12, status: 'pass', lastChecked: '3s ago' },
{ id: 7, name: 'modal.overlay.opacity', type: 'style', prop: 'opacity', expected: '0.8', actual: '0.8', status: 'pass', lastChecked: '3s ago' },
{ id: 8, name: 'button.borderRadius', type: 'style', prop: 'border-radius', expected: '8px', actual: '8px', status: 'pass', lastChecked: '3s ago' },
];
const timelineData = [
{ id: 1, type: 'regression', severity: 'critical', title: 'Hero section layout shift', component: 'Hero', branch: 'feature/new-hero', commit: 'a3f2c1', time: '2 hours ago', status: 'open', diff: '+4.2%' },
{ id: 2, type: 'regression', severity: 'warning', title: 'Navigation font weight change', component: 'Nav', branch: 'main', commit: 'b7d4e2', time: '5 hours ago', status: 'open', diff: '+0.8%' },
{ id: 3, type: 'resolved', title: 'Button padding inconsistency', component: 'Buttons', branch: 'fix/buttons', commit: 'c1a3f5', time: '1 day ago', status: 'resolved', diff: 'fixed' },
{ id: 4, type: 'regression', severity: 'critical', title: 'Pricing table overflow on mobile', component: 'Pricing', branch: 'feature/pricing-v2', commit: 'd5e7b9', time: '1 day ago', status: 'open', diff: '+12.1%' },
{ id: 5, type: 'resolved', title: 'Footer alignment issue', component: 'Footer', branch: 'hotfix/footer', commit: 'e9f1c3', time: '2 days ago', status: 'resolved', diff: 'fixed' },
{ id: 6, type: 'baseline', title: 'Baseline updated for v2.4.0', component: 'Global', branch: 'main', commit: 'f2a4d6', time: '3 days ago', status: 'baseline', diff: '' },
];
const screenshotTests = {
hero: { added: 2847, removed: 1203, percent: 0.42 },
nav: { added: 156, removed: 89, percent: 0.08 },
form: { added: 523, removed: 1024, percent: 0.31 },
pricing: { added: 8901, removed: 3456, percent: 2.15 }
};
// ===== DOM Elements =====
const diffCanvas = document.getElementById('diffCanvas');
const diffSlider = document.getElementById('diffSlider');
const diffViewer = document.getElementById('diffViewer');
const testSelector = document.getElementById('testSelector');
const invariantsList = document.getElementById('invariantsList');
const timelineList = document.getElementById('timelineList');
const runTestsBtn = document.getElementById('runTestsBtn');
const testRunnerModal = document.getElementById('testRunnerModal');
const testProgress = document.getElementById('testProgress');
const testStatus = document.getElementById('testStatus');
// ===== Canvas Setup =====
let ctx = null;
let isDragging = false;
let currentSliderPos = 50;
function initCanvas() {
if (!diffCanvas) return;
const rect = diffViewer.getBoundingClientRect();
diffCanvas.width = rect.width;
diffCanvas.height = rect.height;
ctx = diffCanvas.getContext('2d');
drawDiffView(currentSliderPos);
}
function drawDiffView(sliderPercent) {
if (!ctx || !diffCanvas) return;
const w = diffCanvas.width;
const h = diffCanvas.height;
const sliderX = (sliderPercent / 100) * w;
// Clear
ctx.clearRect(0, 0, w, h);
// Draw baseline (left side) - grayscale with noise
ctx.fillStyle = '#1a1f26';
ctx.fillRect(0, 0, sliderX, h);
// Add some "baseline" UI elements
ctx.fillStyle = '#2d3748';
ctx.fillRect(20, 30, sliderX - 40, 40);
ctx.fillRect(20, 90, Math.min(sliderX - 40, 150), 20);
ctx.fillRect(20, 130, Math.min(sliderX - 40, 200), 16);
ctx.fillRect(20, 170, Math.min(sliderX - 40, 100), 35);
// Baseline text
ctx.fillStyle = '#4a5568';
ctx.fillRect(sliderX - 80, 250, 60, 12);
ctx.fillRect(sliderX - 120, 280, 100, 12);
// Draw current (right side) - with color differences
ctx.fillStyle = '#0f1419';
ctx.fillRect(sliderX, 0, w - sliderX, h);
// Current UI elements (slightly different)
ctx.fillStyle = '#00e5c7';
ctx.fillRect(sliderX + 20, 30, w - sliderX - 40, 44); // Different height
ctx.fillRect(sliderX + 20, 94, 155, 18); // Slightly different
ctx.fillStyle = '#a0aec0';
ctx.fillRect(sliderX + 20, 132, 210, 14);
ctx.fillStyle = '#00e5c7';
ctx.fillRect(sliderX + 20, 168, 105, 38); // Different height
// Additional element in current
ctx.fillStyle = '#ff6b6b';
ctx.fillRect(w - 80, 250, 60, 60);
// Diff highlighting at slider edge
ctx.strokeStyle = '#00e5c7';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(sliderX, 0);
ctx.lineTo(sliderX, h);
ctx.stroke();
}
// ===== Diff Slider Interaction =====
function handleSliderStart(e) {
isDragging = true;
document.body.style.cursor = 'ew-resize';
e.preventDefault();
}
function handleSliderMove(e) {
if (!isDragging || !diffViewer) return;
const rect = diffViewer.getBoundingClientRect();
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
let percent = ((clientX - rect.left) / rect.width) * 100;
percent = Math.max(5, Math.min(95, percent));
currentSliderPos = percent;
diffSlider.style.left = `${percent}%`;
drawDiffView(percent);
}
function handleSliderEnd() {
isDragging = false;
document.body.style.cursor = '';
}
// ===== Render Functions =====
function renderInvariants() {
invariantsList.innerHTML = invariantsData.map(inv => {
const statusClass = inv.status === 'pass' ? 'status-pass' : 'status-fail';
const statusIcon = inv.status === 'pass'
? '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>'
: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>';
return `
<div class="p-3 bg-[--bg] rounded-lg hover:bg-[--bg-elevated] transition-colors group">
<div class="flex items-start justify-between gap-3">
<div class="flex-1 min-w-0">
<div class="flex items-center gap-2 mb-1">
<span class="font-mono text-xs text-[--fg] truncate">${inv.name}</span>
<span class="${statusClass} px-1.5 py-0.5 rounded text-[10px] font-medium uppercase">${inv.status}</span>
</div>
<div class="text-xs text-[--muted]">
${inv.type === 'count' ? `Expected: ${inv.expected}, Got: ${inv.actual}` : ''}
${inv.type === 'style' ? `${inv.prop}: ${inv.expected}` : ''}
${inv.type === 'exists' ? `Selector: ${inv.selector}` : ''}
${inv.type === 'attr' ? `${inv.attr} attribute` : ''}
</div>
</div>
<svg class="w-4 h-4 ${inv.status === 'pass' ? 'text-[--accent]' : 'text-[--danger]'} shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
${statusIcon}
</svg>
</div>
<div class="text-[10px] text-[--muted] mt-2 font-mono opacity-0 group-hover:opacity-100 transition-opacity">
Checked ${inv.lastChecked}
</div>
</div>
`;
}).join('');
}
function renderTimeline(filter = 'all') {
const filtered = filter === 'all'
? timelineData
: timelineData.filter(item => item.status === filter || (filter === 'open' && item.type === 'regression'));
timelineList.innerHTML = filtered.map(item => {
const isRegression = item.type === 'regression';
const severityClass = item.severity === 'critical' ? 'bg-[--danger]' : 'bg-[--warning]';
const dotClass = item.status === 'resolved' ? 'bg-[--accent]' : (item.status === 'baseline' ? 'bg-[--muted]' : severityClass);
return `
<div class="relative pl-10">
<div class="absolute left-2 top-1 w-5 h-5 rounded-full ${dotClass} flex items-center justify-center">
${isRegression && item.status === 'open' ? '<span class="w-2 h-2 rounded-full bg-white/80 pulse-ring"></span>' : ''}
${item.status === 'resolved' ? '<svg class="w-3 h-3 text-[--bg]" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/></svg>' : ''}
</div>
<div class="bg-[--bg] rounded-lg p-4 hover:bg-[--bg-elevated] transition-colors">
<div class="flex items-start justify-between gap-3">
<div class="flex-1">
<div class="flex items-center gap-2 mb-1">
<h4 class="font-medium text-sm">${item.title}</h4>
${isRegression && item.diff ? `<span class="text-xs font-mono ${item.severity === 'critical' ? 'text-[--danger]' : 'text-[--warning]'}">${item.diff}</span>` : ''}
</div>
<div class="flex items-center gap-3 text-xs text-[--muted]">
<span class="font-mono">${item.component}</span>
<span>·</span>
<span class="font-mono">${item.branch}</span>
<span>·</span>
<span>${item.time}</span>
</div>
</div>
<button class="px-3 py-1.5 text-xs rounded-lg ${item.status === 'open' ? 'bg-[--accent-dim] text-[--accent] border border-[--accent]/30 hover:bg-[--accent]/20' : 'bg-[--bg] text-[--muted] border border-[--border]'} transition-colors">
${item.status === 'open' ? 'View' : 'Details'}
</button>
</div>
</div>
</div>
`;
}).join('');
}
// ===== Test Runner Simulation =====
function runTestSuite() {
testRunnerModal.classList.remove('hidden');
testRunnerModal.classList.add('flex');
testProgress.style.width = '0%';
const steps = [
{ progress: 15, status: 'Capturing baseline screenshots...' },
{ progress: 35, status: 'Capturing current renders...' },
{ progress: 55, status: 'Computing pixel differences...' },
{ progress: 75, status: 'Validating DOM invariants...' },
{ progress: 90, status: 'Generating report...' },
{ progress: 100, status: 'Complete!' }
];
let i = 0;
const interval = setInterval(() => {
if (i < steps.length) {
testProgress.style.width = `${steps[i].progress}%`;
testStatus.textContent = steps[i].status;
i++;
} else {
clearInterval(interval);
setTimeout(() => {
testRunnerModal.classList.add('hidden');
testRunnerModal.classList.remove('flex');
// Update stats
document.getElementById('statTests').textContent = '259';
document.getElementById('statPassing').textContent = '241';
}, 500);
}
}, 600);
}
// ===== Event Listeners =====
if (diffSlider) {
diffSlider.addEventListener('mousedown', handleSliderStart);
diffSlider.addEventListener('touchstart', handleSliderStart, { passive: false });
}
document.addEventListener('mousemove', handleSliderMove);
document.addEventListener('touchmove', handleSliderMove, { passive: false });
document.addEventListener('mouseup', handleSliderEnd);
document.addEventListener('touchend', handleSliderEnd);
if (testSelector) {
testSelector.addEventListener('change', (e) => {
const test = screenshotTests[e.target.value];
if (test) {
document.getElementById('diffAdded').textContent = `+${test.added.toLocaleString()}`;
document.getElementById('diffRemoved').textContent = `-${test.removed.toLocaleString()}`;
document.getElementById('diffPercent').textContent = `${test.percent}%`;
// Redraw canvas
initCanvas();
}
});
}
// View toggles
document.querySelectorAll('.view-toggle').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.view-toggle').forEach(b => {
b.classList.remove('bg-[--accent-dim]', 'text-[--accent]', 'border-[--accent]/30');
b.classList.add('bg-[--bg]', 'text-[--muted]', 'border-[--border]');
});
btn.classList.remove('bg-[--bg]', 'text-[--muted]', 'border-[--border]');
btn.classList.add('bg-[--accent-dim]', 'text-[--accent]', 'border-[--accent]/30');
});
});
// Filter buttons
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.filter-btn').forEach(b => {
b.classList.remove('bg-[--accent-dim]', 'text-[--accent]', 'border-[--accent]/30');
b.classList.add('bg-[--bg]', 'text-[--muted]', 'border-[--border]');
});
btn.classList.remove('bg-[--bg]', 'text-[--muted]', 'border-[--border]');
btn.classList.add('bg-[--accent-dim]', 'text-[--accent]', 'border-[--accent]/30');
renderTimeline(btn.dataset.filter);
});
});
if (runTestsBtn) {
runTestsBtn.addEventListener('click', runTestSuite);
}
// ===== Initialize =====
function init() {
initCanvas();
renderInvariants();
renderTimeline();
}
// Wait for DOM
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
// Handle resize
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(initCanvas, 100);
});
</script>
</body>
</html>
Screenshot Diff Viewer
DOM Invariants Checker
Regression Timeline
Interactions
Design Decisions
prefers-reduced-motion