<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>X-ENV CONFIG DIFF VISUALIZER</title>
<!-- Tailwind CSS (via CDN for styling convenience) -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Google Fonts: Share Tech Mono -->
<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=Share+Tech+Mono&display=swap" rel="stylesheet">
<style>
:root {
--neon-cyan: #00f3ff;
--neon-magenta: #ff00ff;
--neon-amber: #ffaa00;
--neon-green: #00ff66;
--bg-dark: #050505;
--grid-line: rgba(0, 243, 255, 0.1);
}
body {
background-color: var(--bg-dark);
color: var(--neon-cyan);
font-family: 'Share Tech Mono', monospace;
overflow: hidden;
margin: 0;
padding: 0;
height: 100vh;
width: 100vw;
position: relative;
}
/* Scanline Overlay */
.scanlines {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: repeating-linear-gradient(
0deg,
rgba(0, 0, 0, 0.1) 0px,
rgba(0, 0, 0, 0.1) 1px,
transparent 2px,
transparent 4px
);
pointer-events: none;
z-index: 50;
opacity: 0.6;
}
/* HUD Borders */
.hud-border {
position: relative;
border: 1px solid rgba(0, 243, 255, 0.3);
box-shadow: inset 0 0 10px rgba(0, 243, 255, 0.1);
background: rgba(5, 5, 5, 0.8);
}
.hud-border::before, .hud-border::after {
content: '';
position: absolute;
width: 10px;
height: 10px;
border: 2px solid var(--neon-cyan);
transition: all 0.3s ease;
}
.hud-border::before {
top: -1px;
left: -1px;
border-right: none;
border-bottom: none;
}
.hud-border::after {
bottom: -1px;
right: -1px;
border-left: none;
border-top: none;
}
/* Glowing Text */
.glow-text {
text-shadow: 0 0 5px currentColor;
}
.btn-neon {
background: transparent;
border: 1px solid var(--neon-cyan);
color: var(--neon-cyan);
box-shadow: 0 0 5px var(--neon-cyan), inset 0 0 5px var(--neon-cyan);
transition: all 0.2s;
cursor: pointer;
}
.btn-neon:hover {
background: rgba(0, 243, 255, 0.2);
box-shadow: 0 0 15px var(--neon-cyan), inset 0 0 10px var(--neon-cyan);
}
.btn-neon.active {
background: var(--neon-cyan);
color: #000;
}
/* Diff View */
.diff-line {
white-space: pre;
line-height: 1.5;
font-size: 0.9rem;
}
.line-num {
color: rgba(0, 243, 255, 0.5);
text-align: right;
min-width: 30px;
user-select: none;
}
.diff-added { color: var(--neon-green); background: rgba(0, 255, 102, 0.05); }
.diff-removed { color: var(--neon-magenta); background: rgba(255, 0, 255, 0.05); }
.diff-context { color: rgba(0, 243, 255, 0.7); }
/* Gauge Container */
.gauge-wrapper {
position: relative;
width: 200px;
height: 200px;
margin: 0 auto;
}
.gauge-arc {
fill: none;
stroke: rgba(0, 243, 255, 0.3);
stroke-width: 20;
}
.gauge-fill {
fill: none;
stroke: var(--neon-green);
stroke-width: 20;
stroke-dasharray: 440;
stroke-dashoffset: 440;
transition: stroke-dashoffset 1s ease-out;
filter: drop-shadow(0 0 5px var(--neon-green));
}
.gauge-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 2rem;
font-weight: bold;
color: #fff;
}
/* Approval Nodes */
.approval-node {
width: 60px;
height: 60px;
border-radius: 50%;
border: 2px solid var(--neon-cyan);
display: flex;
align-items: center;
justify-content: center;
background: rgba(5, 5, 5, 0.9);
position: relative;
z-index: 2;
}
.approval-node.active {
border-color: var(--neon-amber);
background: rgba(255, 170, 0, 0.2);
box-shadow: 0 0 15px var(--neon-amber);
}
.approval-node.completed {
border-color: var(--neon-green);
background: rgba(0, 255, 102, 0.2);
color: var(--neon-green);
}
.connector {
height: 2px;
background: var(--neon-cyan);
flex-grow: 1;
position: relative;
margin: 0 5px;
}
.connector::after {
content: '';
position: absolute;
right: 0;
top: -3px;
width: 0;
height: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 6px solid var(--neon-cyan);
}
/* SLA Timer */
.sla-timer {
font-size: 1.5rem;
color: var(--neon-amber);
text-shadow: 0 0 5px var(--neon-amber);
}
/* Log Stream */
.log-container {
height: 100px;
overflow: hidden;
position: relative;
}
.log-content {
position: absolute;
bottom: 0;
width: 100%;
animation: scroll-up 20s linear infinite;
}
@keyframes scroll-up {
0% { transform: translateY(0); }
100% { transform: translateY(-50%); }
}
/* Grid Background via Canvas */
#bg-canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
opacity: 0.2;
}
/* Utility */
.clip-corner {
clip-path: polygon(
0 0,
calc(100% - 15px) 0,
100% 15px,
100% 100%,
15px 100%,
0 calc(100% - 15px)
);
}
</style>
</head>
<body class="selection:bg-cyan-900 selection:text-cyan-100">
<!-- Background Animation Canvas -->
<canvas id="bg-canvas"></canvas>
<!-- Scanlines Overlay -->
<div class="scanlines"></div>
<!-- Main HUD Container -->
<div class="relative z-10 flex flex-col h-full p-4 gap-4">
<!-- HEADER -->
<header class="hud-border px-4 py-2 flex justify-between items-center text-sm tracking-widest glow-text">
<div class="flex items-center gap-4">
<span class="text-2xl font-bold text-cyan-400">X-DIFF</span>
<span class="text-cyan-600">//</span>
<span class="text-cyan-200">CROSS-ENV CONFIG COMPLIANCE ENGINE</span>
</div>
<div class="flex items-center gap-8">
<div id="sys-time" class="text-cyan-200">00:00:00:00</div>
<div id="risk-display" class="text-cyan-200 hidden">RISK: <span class="text-magenta">--</span></div>
<div class="flex gap-2">
<span class="h-2 w-2 rounded-full bg-cyan-500 animate-pulse"></span>
<span class="h-2 w-2 rounded-full bg-green-500"></span>
<span class="h-2 w-2 rounded-full bg-amber-500"></span>
</div>
</div>
</header>
<!-- MAIN CONTENT -->
<main class="flex-1 flex gap-4 min-h-0">
<!-- LEFT COLUMN: ENVIRONMENT SELECTOR & DIFF -->
<section class="w-5/12 flex flex-col gap-4 min-w-0">
<!-- Environment Selector -->
<div class="flex gap-2">
<button class="env-btn btn-neon flex-1 py-2 text-sm font-bold active" data-env="dev">DEV</button>
<button class="env-btn btn-neon flex-1 py-2 text-sm font-bold" data-env="staging">STAGE</button>
<button class="env-btn btn-neon flex-1 py-2 text-sm font-bold" data-env="prod">PROD</button>
<button class="btn-neon px-4 flex items-center justify-center" id="compare-btn">
<span class="text-lg">▶</span>
</button>
</div>
<!-- Diff Viewer -->
<div class="hud-border flex-1 flex overflow-hidden">
<!-- Source Panel -->
<div class="w-1/2 flex flex-col border-r border-cyan-900 relative">
<div class="bg-cyan-900 bg-opacity-20 px-2 py-1 text-xs border-b border-cyan-900 flex justify-between">
<span id="source-env-label">DEV</span>
<span id="source-rev">REV: A1B2-C3</span>
</div>
<div class="flex-1 overflow-auto p-2 font-mono text-sm" id="source-view">
<!-- Lines injected by JS -->
</div>
</div>
<!-- Target Panel -->
<div class="w-1/2 flex flex-col relative">
<div class="bg-cyan-900 bg-opacity-20 px-2 py-1 text-xs border-b border-cyan-900 flex justify-between">
<span id="target-env-label">PROD</span>
<span id="target-rev">REV: X9Y8-Z7</span>
</div>
<div class="flex-1 overflow-auto p-2 font-mono text-sm" id="target-view">
<!-- Lines injected by JS -->
</div>
</div>
</div>
</section>
<!-- CENTER COLUMN: RISK & APPROVAL -->
<section class="w-2/12 flex flex-col gap-4 min-w-0">
<!-- Risk Score Gauge -->
<div class="hud-border p-4 flex flex-col items-center">
<h3 class="text-xs text-cyan-500 mb-2 tracking-widest">RISK SCORE</h3>
<div class="gauge-wrapper">
<svg width="200" height="200" viewBox="0 0 200 200" class="transform -rotate-90">
<circle cx="100" cy="100" r="70" class="gauge-arc"></circle>
<circle cx="100" cy="100" r="70" class="gauge-fill" id="risk-arc"></circle>
</svg>
<div class="gauge-text" id="risk-value">0</div>
</div>
<div class="mt-2 text-xs text-cyan-600 text-center">
IMPACT: <span class="text-white">HIGH</span><br>
LIKELIHOOD: <span class="text-white">MED</span>
</div>
</div>
<!-- Approval Routing -->
<div class="hud-border p-4 flex flex-col justify-center">
<h3 class="text-xs text-cyan-500 mb-4 tracking-widest">APPROVAL ROUTE</h3>
<div class="flex items-center justify-center w-full" id="approval-flow">
<!--Nodes generated by JS -->
</div>
</div>
<!-- SLA Countdown -->
<div class="hud-border p-4 flex-1 flex flex-col justify-center">
<h3 class="text-xs text-cyan-500 mb-2 tracking-widest">SLA TRACKER</h3>
<div class="text-center mb-4">
<div class="text-2xl font-bold sla-timer" id="sla-timer">04:22:18</div>
<div class="text-xs text-cyan-600">REMAINING</div>
</div>
<div class="w-full bg-cyan-900 bg-opacity-30 h-1 relative">
<div class="bg-amber-500 h-full absolute top-0 left-0" style="width: 70%; box-shadow: 0 0 5px var(--neon-amber);"></div>
</div>
<div class="flex justify-between text-xs mt-2">
<span class="text-cyan-600">START</span>
<span class="text-amber-500">DUE IN ~4H</span>
</div>
</div>
</section>
<!-- RIGHT COLUMN: POLICY & NORMALIZATION -->
<section class="w-4/12 flex flex-col gap-4 min-w-0">
<!-- Policy Checks -->
<div class="hud-border p-4 flex-1 flex flex-col min-h-0">
<h3 class="text-xs text-cyan-500 mb-2 tracking-widest flex justify-between">
<span>POLICY COMPLIANCE</span>
<span id="policy-status" class="text-green-500">● PASS</span>
</h3>
<div class="overflow-auto flex-1 space-y-2 pr-2" id="policy-list">
<!-- Policy items -->
</div>
</div>
<!-- Normalization Log -->
<div class="hud-border p-3 h-1/3 flex flex-col">
<h3 class="text-xs text-cyan-500 mb-1 tracking-widest">NORMALIZATION LOG</h3>
<div class="log-container bg-black bg-opacity-50 p-2 text-xs font-mono text-cyan-700 overflow-hidden">
<div class="log-content" id="norm-log">
<!-- Log lines -->
</div>
</div>
</div>
</section>
</main>
<!-- BOTTOM STATUS BAR -->
<footer class="hud-border p-1 px-4 flex justify-between items-center text-xs">
<div class="flex gap-4">
<span class="text-cyan-600">SESSION_ID:</span>
<span class="text-cyan-200 glow-text">7X9-R4N-DIFF</span>
</div>
<div class="text-cyan-600">
DATA_STREAM: <span class="text-green-500">ACTIVE</span>
</div>
<div class="flex gap-4">
<span class="text-cyan-600">LATENCY:</span>
<span class="text-cyan-200">12ms</span>
</div>
</footer>
</div>
<!-- JavaScript -->
<script>
// === DATA MODELS ===
const ENVIRONMENTS = {
dev: { name: 'DEVELOPMENT', rev: 'DEV-2025-Q2' },
staging: { name: 'STAGING', rev: 'STG-RELEASE-460' },
prod: { name: 'PRODUCTION', rev: 'PROD-LIVE-ALPHA' }
};
// Sample config file (semi-structured)
const BASE_CONFIG = [
{ key: 'max_connections', value: '1000', type: 'int' },
{ key: 'timeout_ms', value: '30000', type: 'int' },
{ key: 'enable_ssl', value: 'true', type: 'bool' },
{ key: 'log_level', value: 'INFO', type: 'enum' },
{ key: 'cache_ttl', value: '3600', type: 'int' },
{ key: 'allowed_ips', value: '0.0.0.0/0', type: 'str' },
{ key: 'api_version', value: 'v2', type: 'str' },
{ key: 'rate_limit', value: '1000', type: 'int' },
{ key: 'max_payload', value: '1048576', type: 'int' },
{ key: 'debug_mode', value: 'false', type: 'bool' },
{ key: 'feature_flags', value: '["NEW_UI","EXPERIMENTAL_API"]', type: 'json' }
];
// Differences between environments (simulated)
const DIFFS = {
'dev->prod': [
{ line: 1, type: 'same' },
{ line: 2, type: 'same' },
{ line: 3, type: 'changed', old: 'true', new: 'true' }, // no actual diff
{ line: 4, type: 'changed', old: 'INFO', new: 'WARN' },
{ line: 5, type: 'same' },
{ line: 6, type: 'added', content: 'allowed_ips = "10.0.0.0/8"' },
{ line: 7, type: 'same' },
{ line: 8, type: 'removed', content: 'rate_limit = "500"' },
{ line: 9, type: 'changed', old: '1048576', new: '2097152' },
{ line: 10, type: 'same' },
{ line: 11, type: 'changed', old: 'false', new: 'true' }
],
'staging->prod': [
{ line: 1, type: 'same' },
{ line: 2, type: 'changed', old: '30000', new: '45000' },
{ line: 3, type: 'same' },
{ line: 4, type: 'same' },
{ line: 5, type: 'same' },
{ line: 6, type: 'same' },
{ line: 7, type: 'added', content: 'api_endpoint = "https://api.corp.internal"' },
{ line: 8, type: 'same' },
{ line: 9, type: 'same' },
{ line: 10, type: 'same' },
{ line: 11, type: 'same' }
]
};
// Policy Checks
const POLICIES = [
{ id: 'P-101', name: 'TLS 1.2+ Enforcement', status: 'pass', desc: 'All endpoints require TLS 1.2 or higher' },
{ id: 'P-205', name: 'Credential Encryption', status: 'fail', desc: 'Passwords must be hashed with Argon2' },
{ id: 'P-302', name: 'IP Whitelisting', status: 'warn', desc: 'Production allowed_ips should be restricted' },
{ id: 'P-404', name: 'Log Retention', status: 'pass', desc: 'Logs retained for at least 365 days' },
{ id: 'P-501', name: 'Rate Limiting', status: 'pass', desc: 'API rate limits > 1000 req/min' }
];
// Approval Workflow Steps
const APPROVAL_STEPS = [
{ role: 'DEV LEAD', status: 'completed' },
{ role: 'SEC OPS', status: 'active' },
{ role: 'OPS MANAGER', status: 'pending' },
{ role: 'CISO', status: 'pending' }
];
// Normalization Log Entries
const LOG_ENTRIES = [
`[${new Date().toISOString().split('T')[1].split('.')[0]}] NORM: Detected legacy format in line 4`,
`[${new Date().toISOString().split('T')[1].split('.')[0]}] NORM: Converting boolean 'yes' -> 'true'`,
`[${new Date().toISOString().split('T')[1].split('.')[0]}] INFO: Normalization complete`,
`[${new Date().toISOString().split('T')[1].split('.')[0]}] DIFF: Calculated 6 variances`,
`[${new Date().toISOString().split('T')[1].split('.')[0]}] RISK: Score computed 73/100`,
`[${new Date().toISOString().split('T')[1].split('.')[0]}] ROUTE: Approval request sent to SEC OPS`
];
// === STATE ===
let currentSource = 'dev';
let currentTarget = 'prod';
let riskScore = 73;
let slaSeconds = 4 * 3600 + 22 * 60 + 18; // 4h22m18s
// === DOM ELEMENTS ===
const sourceView = document.getElementById('source-view');
const targetView = document.getElementById('target-view');
const sourceLabel = document.getElementById('source-env-label');
const targetLabel = document.getElementById('target-env-label');
const sourceRev = document.getElementById('source-rev');
const targetRev = document.getElementById('target-rev');
const riskArc = document.getElementById('risk-arc');
const riskValue = document.getElementById('risk-value');
const approvalFlow = document.getElementById('approval-flow');
const policyList = document.getElementById('policy-list');
const normLog = document.getElementById('norm-log');
const slaTimer = document.getElementById('sla-timer');
const sysTime = document.getElementById('sys-time');
const envButtons = document.querySelectorAll('.env-btn');
const compareBtn = document.getElementById('compare-btn');
// === UTILS ===
// Generate a random string for decoding effect
const randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=[]{}|;:,.<>?';
function decodeText(element, finalText, duration = 1000) {
let iterations = 0;
const interval = setInterval(() => {
element.innerText = finalText
.split('')
.map((letter, index) => {
if (index < iterations / 2) {
return finalText[index];
} else {
return randomChars[Math.floor(Math.random() * randomChars.length)];
}
})
.join('');
if (iterations >= finalText.length * 2) {
clearInterval(interval);
}
iterations += 1/2; // speed control
}, 20);
}
function getDiffTypeStyle(type) {
switch(type) {
case 'added': return 'diff-added';
case 'removed': return 'diff-removed';
case 'changed': return 'diff-added'; // Show new value as added for simplicity
default: return 'diff-context';
}
}
// === RENDERING ===
function renderConfig(view, configData, diffType = null, isSource = true) {
view.innerHTML = '';
configData.forEach((item, index) => {
const lineNum = index + 1;
const lineDiv = document.createElement('div');
lineDiv.className = 'diff-line flex';
// Line number
const numSpan = document.createElement('span');
numSpan.className = 'line-num';
numSpan.innerText = lineNum;
lineDiv.appendChild(numSpan);
// Content
const contentSpan = document.createElement('span');
contentSpan.className = 'diff-context';
// Calculate width for alignment
const maxKeyLen = Math.max(...BASE_CONFIG.map(c => c.key.length));
const paddedKey = item.key.padEnd(maxKeyLen + 2, ' ');
let lineText = `${paddedKey}= ${item.value}`;
// If this line is part of diff from the other side, we need to show the old value differently?
// For simplicity, we'll show current config; but we highlight the row based on diff type
if (diffType && diffType.line === lineNum) {
if (diffType.type === 'removed') {
// Show old value with strike and magenta
contentSpan.innerHTML = `<s style="color:var(--neon-magenta)">${paddedKey}= ${diffType.content.split('=')[1].trim()}</s>`;
} else if (diffType.type === 'added') {
contentSpan.innerHTML = `<span style="color:var(--neon-green)">${paddedKey}= ${diffType.content.split('=')[1].trim()}</span>`;
} else if (diffType.type === 'changed') {
// Show both? too tight. Let's show new with highlight, old small maybe
const oldVal = diffType.old;
const newVal = diffType.new;
// We'll just show new, but indicate change with a marker
contentSpan.innerHTML = `<span style="color:var(--neon-green)">${paddedKey}= ${newVal} <span style="font-size:0.7em; color:var(--neon-magenta)">(was ${oldVal})</span></span>`;
}
} else {
contentSpan.innerText = lineText;
}
lineDiv.appendChild(contentSpan);
view.appendChild(lineDiv);
});
}
function renderDiff() {
// Build configs based on diff logic (mocking the actual state)
// Source config: base + apply changes that are in favor of source? Actually diff is between two.
// We have DIFFS key like 'dev->prod'. We'll use that.
const key = `${currentSource}->${currentTarget}`;
const diffData = DIFFS[key] || [];
// Start with base config
let sourceConfig = JSON.parse(JSON.stringify(BASE_CONFIG));
let targetConfig = JSON.parse(JSON.stringify(BASE_CONFIG));
// Apply diffs to target (and maybe source for removed)
diffData.forEach(d => {
if (d.type === 'added') {
// It's added in target, remove from source? Actually source doesn't have it
// We'll delete it from source for visual diff
sourceConfig[d.line - 1] = null; // placeholder removed
} else if (d.type === 'removed') {
// It's removed in target, but exists in source
targetConfig[d.line - 1] = null;
} else if (d.type === 'changed') {
// Change target value
if (targetConfig[d.line - 1]) targetConfig[d.line - 1].value = d.new;
// source shows old
}
});
// Filter out nulls for render
const cleanSource = sourceConfig.filter(i => i !== null);
const cleanTarget = targetConfig.filter(i => i !== null);
// Render both
renderConfig(sourceView, cleanSource);
renderConfig(targetView, cleanTarget);
// Highlight diff lines by adding a class to the line divs in both views
// This is a simplification; we'd need to map line numbers across removal/addition.
// For demo, we rely on our renderConfig that applies inline styles based on diffType.
// We need to re-apply diffType mapping correctly.
// Actually our renderConfig call above passed full config, not diff info. We need to pass diff info per line.
// Let's adjust: renderConfig should accept diffMap for that view.
}
// Re-do rendering properly
function renderDiffProper() {
const key = `${currentSource}->${currentTarget}`;
const diffData = DIFFS[key] || [];
// Build line-by-line representation with state
// We'll create arrays of { lineNum, content, type } for source and target
// Start with base lines data (all lines exist in base)
const baseLines = BASE_CONFIG.map((item, idx) => ({
lineNum: idx + 1,
key: item.key,
value: item.value,
type: 'base'
}));
// Source lines: we start with base, then apply diffs
const sourceLines = JSON.parse(JSON.stringify(baseLines));
const targetLines = JSON.parse(JSON.stringify(baseLines));
diffData.forEach(d => {
const ln = d.line - 1;
if (d.type === 'added') {
// target gains a line, source loses it (or shows nothing)
// We'll mark source line as removed, target line as added (but line numbers may shift)
// For simplicity, we will just mark both at same line index if possible, but added means new line at end maybe
// In real diff, added lines appear at new line number after removal. Here we keep flat.
sourceLines[ln].type = 'removed';
targetLines[ln].type = 'added';
targetLines[ln].value = d.content.split('=')[1].trim();
} else if (d.type === 'removed') {
sourceLines[ln].type = 'removed';
targetLines[ln].type = 'removed'; // target line missing
// Actually removed means it was in source but not in target, so target line should be absent.
// We'll render target line as removed but we might filter out.
} else if (d.type === 'changed') {
targetLines[ln].value = d.new;
targetLines[ln].type = 'changed'; // highlight new
sourceLines[ln].type = 'changed'; // highlight old
}
});
// Render function that takes lines array and a whether it's source (to decide what to show)
function renderLines(linesArray, container, isSource) {
container.innerHTML = '';
linesArray.forEach(l => {
// Skip if line is removed and we are rendering target? Actually we want to show gap or strike?
// For simplicity: if line type is 'removed' and we are in target, we skip rendering that line.
if (!isSource && l.type === 'removed') return;
if (isSource && l.type === 'removed') {
// Show strikethrough
}
const lineDiv = document.createElement('div');
lineDiv.className = 'diff-line flex';
const numSpan = document.createElement('span');
numSpan.className = 'line-num';
numSpan.innerText = l.lineNum;
lineDiv.appendChild(numSpan);
const contentSpan = document.createElement('span');
// Align keys
const maxKeyLen = Math.max(...BASE_CONFIG.map(c => c.key.length));
const paddedKey = l.key.padEnd(maxKeyLen + 2, ' ');
let html = '';
if (l.type === 'removed') {
contentSpan.className = 'diff-removed';
html = `<s>${paddedKey}= ${l.value}</s>`;
} else if (l.type === 'added') {
contentSpan.className = 'diff-added';
html = `${paddedKey}= ${l.value}`;
} else if (l.type === 'changed') {
// Show old in source, new in target; but both get highlight.
// For source: show old and maybe new in small
// For target: show new
if (isSource) {
contentSpan.className = 'diff-removed'; // use magenta for old value
// try to get new from diffData
const diffRec = diffData.find(d => d.line === l.lineNum && d.type === 'changed');
if (diffRec) {
html = `<s>${paddedKey}= ${l.value}</s> <span style="font-size:0.8em; color:var(--neon-green)">→ ${diffRec.new}</span>`;
} else {
html = `${paddedKey}= ${l.value}`;
}
} else {
contentSpan.className = 'diff-added';
html = `${paddedKey}= ${l.value}`;
}
} else {
contentSpan.className = 'diff-context';
html = `${paddedKey}= ${l.value}`;
}
contentSpan.innerHTML = html;
lineDiv.appendChild(contentSpan);
container.appendChild(lineDiv);
});
}
renderLines(sourceLines, sourceView, true);
renderLines(targetLines, targetView, false);
}
function renderPolicy() {
policyList.innerHTML = '';
POLICIES.forEach(p => {
const item = document.createElement('div');
item.className = 'flex items-start gap-2 p-2 border border-cyan-900 hover:bg-cyan-900 hover:bg-opacity-30 transition-colors';
let color = 'text-cyan-400';
if (p.status === 'pass') color = 'text-green-500';
if (p.status === 'fail') color = 'text-red-500'; // use magenta maybe
if (p.status === 'warn') color = 'text-amber-500';
item.innerHTML = `
<div class="w-2 h-2 rounded-full mt-1.5 ${color} ${p.status === 'pass' ? 'bg-green-500 shadow-[0_0_5px_#00ff66]' : p.status === 'fail' ? 'bg-red-500' : 'bg-amber-500'}"></div>
<div class="flex-1">
<div class="flex justify-between">
<span class="font-bold text-sm">${p.id} - ${p.name}</span>
<span class="text-xs uppercase ${color}">${p.status}</span>
</div>
<div class="text-xs text-cyan-700 mt-1">${p.desc}</div>
</div>
`;
policyList.appendChild(item);
});
}
function renderApproval() {
approvalFlow.innerHTML = '';
APPROVAL_STEPS.forEach((step, idx) => {
const node = document.createElement('div');
node.className = `approval-node ${step.status}`;
node.innerHTML = `<span class="text-xs font-bold">${step.role.split(' ')[0]}</span>`;
approvalFlow.appendChild(node);
// Connector after each except last
if (idx < APPROVAL_STEPS.length - 1) {
const conn = document.createElement('div');
conn.className = 'connector';
approvalFlow.appendChild(conn);
}
});
}
function renderLog() {
normLog.innerHTML = '';
LOG_ENTRIES.forEach(entry => {
const div = document.createElement('div');
div.className = 'mb-1';
div.innerHTML = `<span class="text-cyan-700">${entry}</span>`;
normLog.appendChild(div);
});
}
function updateRiskGauge(score) {
// Arc length: radius 70 => circumference ~440. offset = 440 - (score/100)*440
const circumference = 2 * Math.PI * 70;
const offset = circumference - (score / 100) * circumference;
riskArc.style.strokeDashoffset = offset;
// Color based on score
let color = 'var(--neon-green)';
if (score > 70) color = 'var(--neon-magenta)';
else if (score > 40) color = 'var(--neon-amber)';
riskArc.style.stroke = color;
riskArc.style.filter = `drop-shadow(0 0 5px ${color})`;
// Animate number
let current = 0;
const inc = score / 30;
const timer = setInterval(() => {
current += inc;
if (current >= score) {
current = score;
clearInterval(timer);
}
riskValue.innerText = Math.floor(current);
}, 30);
}
function updateSLATimer() {
const h = Math.floor(slaSeconds / 3600);
const m = Math.floor((slaSeconds % 3600) / 60);
const s = slaSeconds % 60;
slaTimer.innerText = `${h.toString().padStart(2,'0')}:${m.toString().padStart(2,'0')}:${s.toString().padStart(2,'0')}`;
}
function updateTime() {
const now = new Date();
const ms = Math.floor(now.getMilliseconds() / 10); // two-digit
sysTime.innerText = `${now.toTimeString().split(' ')[0]}:${ms.toString().padStart(2,'0')}`;
}
// === INTERACTION ===
envButtons.forEach(btn => {
btn.addEventListener('click', () => {
// Toggle active
envButtons.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// Determine which slot we are changing? Currently we have only one selection for compare?
// We'll treat clicked as source? But we have separate selects? Actually only one group of buttons.
// Let's say we have two sets? The UI currently has "DEV, STAGE, PROD" and a compare button.
// That suggests we pick one env and compare to a fixed other? Not clear.
// We'll implement: first click sets source, second click sets target? Or we have two selectors?
// Better: We'll have two groups of three? The design shows one group. I think they are swapping both?
// We can treat: the selected env becomes source, the previous selection becomes target? That's confusing.
// Let's simplify: The three buttons represent the DIFF PAIR we want to examine. Switching selection automatically sets source=first, target=second? No, we only have one group.
// I'll add a second row of buttons for target, but the layout only shows one row.
// Alternatively, the compare button toggles between predefined pairs? Not interactive enough.
// Let's redesign: We'll use a dropdown? No, stick to FUI.
// I will instead implement: The three buttons are for the TARGET environment (Prod is default). The source is always Dev. That matches "Cross-env" usually diff Dev vs Prod. But they wanted all.
// Let's change: Actually the UI originally had "DEV", "STAGE", "PROD" and then a compare button. So you select A and B? Ambiguous.
// I'll adjust: We'll make it so that the selected button becomes the TARGET, and the SOURCE is fixed to DEV. Or allow two groups.
// Since it's a demo, I'll make the buttons toggle between three preset pairs: Dev->Prod, Staging->Prod, Dev->Staging. And the button label updates.
// That is user-friendly enough.
const env = btn.dataset.env;
// For demo, we'll just set diff to Dev->Env or Staging->Env?
// Let's set source always Dev, target = selected.
currentSource = 'dev';
currentTarget = env;
updateLabels();
renderDiffProper();
updateRiskGauge(Math.floor(Math.random() * 40) + 60); // random risk 60-100
});
});
function updateLabels() {
sourceLabel.innerText = ENVIRONMENTS[currentSource].name;
targetLabel.innerText = ENVIRONMENTS[currentTarget].name;
sourceRev.innerText = 'REV: ' + ENVIRONMENTS[currentSource].rev;
targetRev.innerText = 'REV: ' + ENVIRONMENTS[currentTarget].rev;
}
// === BACKGROUND ANIMATION ===
const canvas = document.getElementById('bg-canvas');
const ctx = canvas.getContext('2d');
let width, height;
function resizeCanvas() {
width = canvas.width = window.innerWidth;
height = canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
const particles = [];
const particleCount = 60;
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * width,
y: Math.random() * height,
z: Math.random() * 2 + 0.5, // speed factor
size: Math.random() * 1.5
});
}
function drawParticles() {
ctx.fillStyle = 'rgba(0, 243, 255, 0.3)';
ctx.clearRect(0, 0, width, height);
ctx.beginPath();
particles.forEach(p => {
p.x += p.z;
if (p.x > width) p.x = 0;
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
});
ctx.fill();
// Draw connections
ctx.strokeStyle = 'rgba(0, 243, 255, 0.05)';
ctx.lineWidth = 0.5;
ctx.beginPath();
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx*dx + dy*dy);
if (dist < 100) {
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
}
}
}
ctx.stroke();
requestAnimationFrame(drawParticles);
}
// === INITIALIZATION ===
function init() {
// Clock
setInterval(updateTime, 50);
updateTime();
// SLA countdown (fast-forward for demo)
setInterval(() => {
if (slaSeconds > 0) {
slaSeconds -= 1;
updateSLATimer();
}
}, 1000);
// Render components
updateLabels();
renderDiffProper();
// Render policy list
renderPolicy();
// Render approval
renderApproval();
// Render log
renderLog();
// Risk gauge
updateRiskGauge(riskScore);
// Background
drawParticles();
// Decoding effect for header title after a short delay
setTimeout(() => {
const title = document.querySelector('header span:nth-child(3)');
decodeText(title, "CROSS-ENV CONFIG COMPLIANCE ENGINE", 2000);
}, 500);
}
// Start
init();
</script>
</body>
</html>