class StatsCounter extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); const value = this.getAttribute('value') || '0'; const label = this.getAttribute('label') || 'Stat'; const icon = this.getAttribute('icon') || 'trending-up'; const color = this.getAttribute('color') || 'blue'; const colors = { blue: 'from-blue-500 to-cyan-500', green: 'from-emerald-500 to-green-500', purple: 'from-purple-500 to-pink-500', orange: 'from-orange-500 to-amber-500' }; const gradient = colors[color] || colors.blue; this.shadowRoot.innerHTML = `
0
${label}
`; // Animate counter this.animateCounter(value); // Replace feather icon if (typeof feather !== 'undefined') { feather.replace(); } } animateCounter(target) { const counter = this.shadowRoot.getElementById('counter'); const numTarget = parseInt(target.replace(/,/g, '')); let count = 0; const increment = Math.max(1, Math.floor(numTarget / 100)); const timer = setInterval(() => { count += increment; if (count >= numTarget) { count = numTarget; clearInterval(timer); } counter.textContent = count.toLocaleString(); }, 20); } } customElements.define('stats-counter', StatsCounter);