// Main JavaScript for CodeCanvas // Initialize tooltips for icons function initTooltips() { const tooltipElements = document.querySelectorAll('[data-tooltip]'); tooltipElements.forEach(element => { element.addEventListener('mouseenter', (e) => { const tooltipText = element.getAttribute('data-tooltip'); const tooltip = document.createElement('div'); tooltip.className = 'fixed z-50 px-3 py-2 text-sm bg-gray-900 text-white rounded-lg shadow-lg border border-gray-700 pointer-events-none'; tooltip.textContent = tooltipText; document.body.appendChild(tooltip); const rect = element.getBoundingClientRect(); tooltip.style.left = `${rect.left + rect.width / 2 - tooltip.offsetWidth / 2}px`; tooltip.style.top = `${rect.top - tooltip.offsetHeight - 10}px`; element._tooltip = tooltip; }); element.addEventListener('mouseleave', (e) => { if (element._tooltip) { element._tooltip.remove(); delete element._tooltip; } }); }); } // Dark/Light mode toggle function initThemeToggle() { const themeToggle = document.querySelector('[data-theme-toggle]'); if (!themeToggle) return; themeToggle.addEventListener('click', () => { const html = document.documentElement; const isDark = html.classList.contains('dark'); if (isDark) { html.classList.remove('dark'); localStorage.setItem('theme', 'light'); } else { html.classList.add('dark'); localStorage.setItem('theme', 'dark'); } // Update icon const icon = themeToggle.querySelector('i[data-feather]'); if (icon) { const newIcon = isDark ? 'sun' : 'moon'; icon.setAttribute('data-feather', newIcon); feather.replace(); } }); } // Project statistics from GitHub API async function loadGitHubStats() { try { const response = await fetch('https://api.github.com/repos/tailwindlabs/tailwindcss'); const data = await response.json(); const statsElement = document.querySelector('[data-github-stats]'); if (statsElement) { statsElement.innerHTML = `