Spaces:
Sleeping
Sleeping
File size: 8,887 Bytes
3a4efe4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
// Enhanced theme toggle with smooth transitions
const toggle = document.getElementById('themeToggle');
const root = document.documentElement;
const saved = localStorage.getItem('theme') || 'dark';
// Apply saved theme
if (saved === 'light') {
document.documentElement.classList.remove('dark');
} else {
document.documentElement.classList.add('dark');
}
// Update theme toggle icon
const updateThemeIcon = () => {
const icon = toggle?.querySelector('i');
if (icon) {
icon.setAttribute('data-lucide', document.documentElement.classList.contains('dark') ? 'sun-medium' : 'moon');
if (window.lucide) {
lucide.createIcons();
}
}
};
// Initialize theme icon
updateThemeIcon();
toggle?.addEventListener('click', () => {
const isDark = document.documentElement.classList.toggle('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
updateThemeIcon();
// Add smooth transition effect
document.body.style.transition = 'background-color 0.3s ease, color 0.3s ease';
setTimeout(() => {
document.body.style.transition = '';
}, 300);
});
// Enhanced tabs logic with smooth transitions and ARIA support
document.querySelectorAll('.tab').forEach(btn => {
btn.addEventListener('click', () => {
// Remove active class and ARIA attributes from all tabs
document.querySelectorAll('.tab').forEach(b => {
b.classList.remove('active');
b.setAttribute('aria-selected', 'false');
});
// Add active class and ARIA attributes to clicked tab
btn.classList.add('active');
btn.setAttribute('aria-selected', 'true');
// Get target diagram
const target = btn.getAttribute('data-target');
const targetDiagram = document.querySelector(target);
if (targetDiagram) {
// Hide all diagrams completely and update ARIA
document.querySelectorAll('.diagram').forEach(d => {
d.style.opacity = '0';
d.style.transform = 'translateY(20px)';
d.style.display = 'none';
d.setAttribute('aria-hidden', 'true');
d.classList.remove('visible');
});
// Show target diagram with fade in and update ARIA
setTimeout(() => {
targetDiagram.style.display = 'block';
targetDiagram.classList.add('visible');
targetDiagram.style.opacity = '1';
targetDiagram.style.transform = 'translateY(0)';
targetDiagram.setAttribute('aria-hidden', 'false');
}, 150);
}
});
});
// Initialize first tab as active and show first diagram
document.addEventListener('DOMContentLoaded', () => {
// Hide all diagrams except the first one
document.querySelectorAll('.diagram').forEach((diagram, index) => {
if (index === 0) {
// First diagram should be visible
diagram.style.display = 'block';
diagram.style.opacity = '1';
diagram.style.transform = 'translateY(0)';
diagram.classList.add('visible');
diagram.setAttribute('aria-hidden', 'false');
} else {
// Other diagrams should be hidden
diagram.style.display = 'none';
diagram.style.opacity = '0';
diagram.style.transform = 'translateY(20px)';
diagram.classList.remove('visible');
diagram.setAttribute('aria-hidden', 'true');
}
});
// Ensure Mermaid diagrams are properly initialized
if (window.mermaid) {
mermaid.init(undefined, document.querySelectorAll('.mermaid'));
}
});
// Enhanced metric counters with better performance
const counters = document.querySelectorAll('.metric-value');
const easeOutCubic = t => 1 - Math.pow(1 - t, 3);
const easeOutQuart = t => 1 - Math.pow(1 - t, 4);
const animateCount = (el, to, duration = 1200) => {
const start = performance.now();
const from = 0;
const isLargeNumber = to > 1000;
const easing = isLargeNumber ? easeOutQuart : easeOutCubic;
// Ensure the element has proper positioning
el.style.position = 'relative';
el.style.zIndex = '2';
el.style.width = '100%';
el.style.textAlign = 'center';
el.style.display = 'block';
const step = (now) => {
const p = Math.min(1, (now - start) / duration);
const v = Math.floor(from + (to - from) * easing(p));
// Format number with appropriate separators
if (to >= 1000000) {
el.textContent = (v / 1000000).toFixed(1) + 'M';
} else if (to >= 1000) {
el.textContent = (v / 1000).toFixed(1) + 'K';
} else {
el.textContent = v.toLocaleString();
}
if (p < 1) {
requestAnimationFrame(step);
} else {
// Ensure final value is exact
if (to >= 1000000) {
el.textContent = (to / 1000000).toFixed(1) + 'M';
} else if (to >= 1000) {
el.textContent = (to / 1000).toFixed(1) + 'K';
} else {
el.textContent = to.toLocaleString();
}
}
};
requestAnimationFrame(step);
};
// Enhanced intersection observer with better performance
const observer = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
const el = e.target;
const count = parseInt(el.dataset.count, 10) || 0;
// Add loading state
el.classList.add('loading');
// Animate with slight delay for better visual effect
setTimeout(() => {
animateCount(el, count);
el.classList.remove('loading');
}, 200);
observer.unobserve(el);
}
});
}, {
threshold: 0.3,
rootMargin: '0px 0px -50px 0px'
});
// Observe counters
counters.forEach(c => observer.observe(c));
// Enhanced VanillaTilt initialization with error handling
const initTilt = () => {
if (window.VanillaTilt) {
try {
document.querySelectorAll('[data-tilt]').forEach(el => {
VanillaTilt.init(el, {
max: 6,
speed: 400,
glare: true,
'max-glare': 0.1,
scale: 1.02,
gyroscope: false
});
});
} catch (error) {
console.warn('VanillaTilt initialization failed:', error);
}
}
};
// Initialize tilt effects
initTilt();
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const headerHeight = document.querySelector('header')?.offsetHeight || 0;
const targetPosition = targetElement.offsetTop - headerHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Enhanced error handling for external resources
const handleResourceError = (resource, fallback) => {
resource.addEventListener('error', () => {
console.warn(`Failed to load resource, using fallback`);
if (fallback) {
resource.src = fallback;
}
});
};
// Handle external script loading errors
window.addEventListener('error', (e) => {
if (e.target.tagName === 'SCRIPT' && e.target.src) {
console.warn(`Script failed to load: ${e.target.src}`);
}
});
// Performance monitoring
const logPerformance = () => {
if ('performance' in window) {
window.addEventListener('load', () => {
setTimeout(() => {
const perfData = performance.getEntriesByType('navigation')[0];
console.log(`Page load time: ${perfData.loadEventEnd - perfData.loadEventStart}ms`);
}, 0);
});
}
};
// Initialize performance monitoring
logPerformance();
// Add keyboard navigation support
document.addEventListener('keydown', (e) => {
// Tab navigation for architecture tabs
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
const activeTab = document.querySelector('.tab.active');
if (activeTab) {
const tabs = Array.from(document.querySelectorAll('.tab'));
const currentIndex = tabs.indexOf(activeTab);
let nextIndex;
if (e.key === 'ArrowLeft') {
nextIndex = currentIndex > 0 ? currentIndex - 1 : tabs.length - 1;
} else {
nextIndex = currentIndex < tabs.length - 1 ? currentIndex + 1 : 0;
}
tabs[nextIndex].click();
tabs[nextIndex].focus();
}
}
});
// Add loading states for dynamic content
const addLoadingState = (element, duration = 1000) => {
element.classList.add('loading');
setTimeout(() => {
element.classList.remove('loading');
}, duration);
};
// Initialize all interactive elements
document.addEventListener('DOMContentLoaded', () => {
// Add loading states to cards that might load content dynamically
document.querySelectorAll('.card').forEach(card => {
card.addEventListener('mouseenter', () => {
addLoadingState(card, 500);
});
});
// Initialize tooltips for chips
document.querySelectorAll('.chip').forEach(chip => {
chip.setAttribute('title', chip.textContent);
});
});
|