|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>Adaptive Tier Test — @annondeveloper/ui-kit</title> |
| 7 | + <style> |
| 8 | + /* Total CSS: ~3KB — loads instantly even on GPRS */ |
| 9 | + :root { |
| 10 | + --bg: #0f0f14; |
| 11 | + --bg-card: #1a1a24; |
| 12 | + --text: #e8e8f0; |
| 13 | + --text-dim: #8888a0; |
| 14 | + --brand: #6366f1; |
| 15 | + --success: #10b981; |
| 16 | + --warning: #f59e0b; |
| 17 | + --danger: #ef4444; |
| 18 | + --radius: 12px; |
| 19 | + } |
| 20 | + |
| 21 | + * { box-sizing: border-box; margin: 0; } |
| 22 | + |
| 23 | + body { |
| 24 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; |
| 25 | + background: var(--bg); |
| 26 | + color: var(--text); |
| 27 | + padding: 1.5rem; |
| 28 | + max-width: 600px; |
| 29 | + margin: 0 auto; |
| 30 | + line-height: 1.5; |
| 31 | + } |
| 32 | + |
| 33 | + h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; } |
| 34 | + h2 { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.75rem; color: var(--text-dim); } |
| 35 | + p { color: var(--text-dim); font-size: 0.875rem; margin-bottom: 1rem; } |
| 36 | + |
| 37 | + .card { |
| 38 | + background: var(--bg-card); |
| 39 | + border: 1px solid rgba(255,255,255,0.06); |
| 40 | + border-radius: var(--radius); |
| 41 | + padding: 1.25rem; |
| 42 | + margin-bottom: 1rem; |
| 43 | + } |
| 44 | + |
| 45 | + .tier-badge { |
| 46 | + display: inline-flex; |
| 47 | + align-items: center; |
| 48 | + gap: 0.375rem; |
| 49 | + padding: 0.375rem 1rem; |
| 50 | + border-radius: 999px; |
| 51 | + font-size: 0.8125rem; |
| 52 | + font-weight: 700; |
| 53 | + text-transform: uppercase; |
| 54 | + letter-spacing: 0.05em; |
| 55 | + } |
| 56 | + .tier-badge[data-tier="lite"] { background: rgba(16,185,129,0.15); color: #10b981; } |
| 57 | + .tier-badge[data-tier="standard"] { background: rgba(59,130,246,0.15); color: #3b82f6; } |
| 58 | + .tier-badge[data-tier="premium"] { background: rgba(139,92,246,0.15); color: #8b5cf6; } |
| 59 | + |
| 60 | + .info-row { |
| 61 | + display: flex; |
| 62 | + justify-content: space-between; |
| 63 | + padding: 0.5rem 0; |
| 64 | + border-bottom: 1px solid rgba(255,255,255,0.04); |
| 65 | + font-size: 0.8125rem; |
| 66 | + } |
| 67 | + .info-row:last-child { border-bottom: none; } |
| 68 | + .info-label { color: var(--text-dim); } |
| 69 | + .info-value { color: var(--text); font-weight: 600; font-family: 'SF Mono', monospace; } |
| 70 | + |
| 71 | + /* Demo components — visual tier differences */ |
| 72 | + .demo-button { |
| 73 | + display: inline-flex; |
| 74 | + align-items: center; |
| 75 | + gap: 0.5rem; |
| 76 | + padding: 0.625rem 1.25rem; |
| 77 | + border: none; |
| 78 | + border-radius: 8px; |
| 79 | + font-size: 0.875rem; |
| 80 | + font-weight: 600; |
| 81 | + cursor: pointer; |
| 82 | + background: var(--brand); |
| 83 | + color: white; |
| 84 | + margin: 0.25rem; |
| 85 | + } |
| 86 | + |
| 87 | + .demo-card-grid { |
| 88 | + display: grid; |
| 89 | + grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); |
| 90 | + gap: 0.75rem; |
| 91 | + margin: 0.75rem 0; |
| 92 | + } |
| 93 | + |
| 94 | + .demo-metric { |
| 95 | + background: var(--bg-card); |
| 96 | + border: 1px solid rgba(255,255,255,0.06); |
| 97 | + border-radius: 8px; |
| 98 | + padding: 1rem; |
| 99 | + text-align: center; |
| 100 | + } |
| 101 | + .demo-metric-value { font-size: 1.5rem; font-weight: 800; } |
| 102 | + .demo-metric-label { font-size: 0.6875rem; color: var(--text-dim); margin-top: 0.25rem; } |
| 103 | + |
| 104 | + /* Tier-specific visual treatments */ |
| 105 | + [data-tier="premium"] .demo-button { |
| 106 | + box-shadow: 0 0 20px rgba(99,102,241,0.4); |
| 107 | + transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease; |
| 108 | + } |
| 109 | + [data-tier="premium"] .demo-button:hover { |
| 110 | + transform: translateY(-2px) scale(1.02); |
| 111 | + box-shadow: 0 4px 30px rgba(99,102,241,0.5); |
| 112 | + } |
| 113 | + [data-tier="premium"] .demo-metric { |
| 114 | + box-shadow: 0 0 24px rgba(99,102,241,0.08); |
| 115 | + transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); |
| 116 | + } |
| 117 | + [data-tier="premium"] .demo-metric:hover { |
| 118 | + transform: translateY(-4px); |
| 119 | + } |
| 120 | + [data-tier="premium"] .card { |
| 121 | + border-color: rgba(99,102,241,0.15); |
| 122 | + box-shadow: 0 0 32px rgba(99,102,241,0.06); |
| 123 | + } |
| 124 | + |
| 125 | + [data-tier="standard"] .demo-button { |
| 126 | + transition: background 0.2s ease, transform 0.2s ease; |
| 127 | + } |
| 128 | + [data-tier="standard"] .demo-button:hover { |
| 129 | + transform: translateY(-1px); |
| 130 | + } |
| 131 | + [data-tier="standard"] .demo-metric { |
| 132 | + transition: box-shadow 0.2s ease; |
| 133 | + } |
| 134 | + |
| 135 | + [data-tier="lite"] .demo-button { transition: none; } |
| 136 | + [data-tier="lite"] .demo-metric { transition: none; } |
| 137 | + [data-tier="lite"] .card { border-color: rgba(255,255,255,0.04); } |
| 138 | + |
| 139 | + .btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 1rem 0; } |
| 140 | + .override-btn { |
| 141 | + padding: 0.5rem 1rem; |
| 142 | + border: 1px solid rgba(255,255,255,0.1); |
| 143 | + border-radius: 8px; |
| 144 | + background: transparent; |
| 145 | + color: var(--text-dim); |
| 146 | + font-size: 0.75rem; |
| 147 | + cursor: pointer; |
| 148 | + } |
| 149 | + .override-btn:hover { border-color: var(--brand); color: var(--brand); } |
| 150 | + .override-btn.active { background: var(--brand); color: white; border-color: var(--brand); } |
| 151 | + |
| 152 | + .timestamp { font-size: 0.6875rem; color: var(--text-dim); text-align: center; margin-top: 1.5rem; } |
| 153 | + </style> |
| 154 | +</head> |
| 155 | +<body> |
| 156 | + <div id="app" data-tier="standard"> |
| 157 | + <h1>Adaptive Tier Test</h1> |
| 158 | + <p>This page is ~4KB total (HTML+CSS+JS). It loads instantly on any connection and demonstrates bandwidth-adaptive rendering.</p> |
| 159 | + |
| 160 | + <div class="card"> |
| 161 | + <div class="tier-badge" id="tier-badge" data-tier="standard">Detecting...</div> |
| 162 | + <div style="margin-top: 1rem;"> |
| 163 | + <div class="info-row"> |
| 164 | + <span class="info-label">Detected Tier</span> |
| 165 | + <span class="info-value" id="info-tier">—</span> |
| 166 | + </div> |
| 167 | + <div class="info-row"> |
| 168 | + <span class="info-label">Motion Level</span> |
| 169 | + <span class="info-value" id="info-motion">—</span> |
| 170 | + </div> |
| 171 | + <div class="info-row"> |
| 172 | + <span class="info-label">Connection Type</span> |
| 173 | + <span class="info-value" id="info-type">—</span> |
| 174 | + </div> |
| 175 | + <div class="info-row"> |
| 176 | + <span class="info-label">Downlink</span> |
| 177 | + <span class="info-value" id="info-downlink">—</span> |
| 178 | + </div> |
| 179 | + <div class="info-row"> |
| 180 | + <span class="info-label">RTT</span> |
| 181 | + <span class="info-value" id="info-rtt">—</span> |
| 182 | + </div> |
| 183 | + <div class="info-row"> |
| 184 | + <span class="info-label">Save-Data</span> |
| 185 | + <span class="info-value" id="info-savedata">—</span> |
| 186 | + </div> |
| 187 | + <div class="info-row"> |
| 188 | + <span class="info-label">Reason</span> |
| 189 | + <span class="info-value" id="info-reason">—</span> |
| 190 | + </div> |
| 191 | + <div class="info-row"> |
| 192 | + <span class="info-label">Detection Time</span> |
| 193 | + <span class="info-value" id="info-time">—</span> |
| 194 | + </div> |
| 195 | + </div> |
| 196 | + </div> |
| 197 | + |
| 198 | + <h2>Manual Override</h2> |
| 199 | + <div class="btn-row"> |
| 200 | + <button class="override-btn" onclick="setTier('lite')">Lite (motion 0)</button> |
| 201 | + <button class="override-btn" onclick="setTier('standard')">Standard (motion 2)</button> |
| 202 | + <button class="override-btn" onclick="setTier('premium')">Premium (motion 3)</button> |
| 203 | + <button class="override-btn" onclick="detect()">Re-detect</button> |
| 204 | + </div> |
| 205 | + |
| 206 | + <h2>Demo Components</h2> |
| 207 | + <div class="demo-card-grid"> |
| 208 | + <div class="demo-metric"> |
| 209 | + <div class="demo-metric-value">1,284</div> |
| 210 | + <div class="demo-metric-label">Users</div> |
| 211 | + </div> |
| 212 | + <div class="demo-metric"> |
| 213 | + <div class="demo-metric-value">42</div> |
| 214 | + <div class="demo-metric-label">Active</div> |
| 215 | + </div> |
| 216 | + <div class="demo-metric"> |
| 217 | + <div class="demo-metric-value" style="color: var(--danger)">3</div> |
| 218 | + <div class="demo-metric-label">Errors</div> |
| 219 | + </div> |
| 220 | + <div class="demo-metric"> |
| 221 | + <div class="demo-metric-value" style="color: var(--success)">99.9%</div> |
| 222 | + <div class="demo-metric-label">Uptime</div> |
| 223 | + </div> |
| 224 | + </div> |
| 225 | + |
| 226 | + <div style="margin: 1rem 0;"> |
| 227 | + <button class="demo-button">Primary Button</button> |
| 228 | + <button class="demo-button" style="background: transparent; border: 1px solid rgba(255,255,255,0.15); color: var(--text)">Secondary</button> |
| 229 | + <button class="demo-button" style="background: var(--danger)">Danger</button> |
| 230 | + </div> |
| 231 | + |
| 232 | + <div class="card"> |
| 233 | + <h2 style="margin-top: 0">How to Test</h2> |
| 234 | + <p>On mobile: switch between WiFi and cellular, or enable Data Saver mode.</p> |
| 235 | + <p>On desktop: Chrome DevTools → Network → Throttle to GPRS/2G/3G and reload.</p> |
| 236 | + <p><strong>Premium:</strong> Cards glow, buttons have spring hover, metrics lift on hover.</p> |
| 237 | + <p><strong>Standard:</strong> Subtle transitions on hover.</p> |
| 238 | + <p><strong>Lite:</strong> No effects — instant, static rendering.</p> |
| 239 | + </div> |
| 240 | + |
| 241 | + <div class="timestamp" id="timestamp"></div> |
| 242 | + </div> |
| 243 | + |
| 244 | + <script> |
| 245 | + // Adaptive tier detection — same logic as useAdaptiveTier.ts |
| 246 | + function detect() { |
| 247 | + const start = performance.now() |
| 248 | + const conn = navigator.connection || navigator.mozConnection || navigator.webkitConnection |
| 249 | + let tier = 'standard', motion = 2, reason = 'default' |
| 250 | + |
| 251 | + // Check reduced motion preference |
| 252 | + if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) { |
| 253 | + tier = 'lite'; motion = 0; reason = 'prefers-reduced-motion' |
| 254 | + } |
| 255 | + // Check Save-Data |
| 256 | + else if (conn && conn.saveData) { |
| 257 | + tier = 'lite'; motion = 0; reason = 'Save-Data enabled' |
| 258 | + } |
| 259 | + // Check connection type |
| 260 | + else if (conn && conn.effectiveType) { |
| 261 | + const type = conn.effectiveType |
| 262 | + const downlink = conn.downlink || 10 |
| 263 | + const rtt = conn.rtt || 50 |
| 264 | + |
| 265 | + if (type === 'slow-2g' || type === '2g') { |
| 266 | + tier = 'lite'; motion = 0; reason = 'Slow: ' + type |
| 267 | + } else if (type === '3g' && downlink < 0.5) { |
| 268 | + tier = 'standard'; motion = 1; reason = 'Slow 3G: ' + downlink + 'Mbps' |
| 269 | + } else if (type === '3g') { |
| 270 | + tier = 'standard'; motion = 2; reason = '3G: ' + downlink + 'Mbps' |
| 271 | + } else if (downlink >= 1 || rtt < 100) { |
| 272 | + tier = 'premium'; motion = 3; reason = 'Fast: ' + downlink + 'Mbps, ' + rtt + 'ms RTT' |
| 273 | + } else if (downlink >= 0.4) { |
| 274 | + tier = 'standard'; motion = 2; reason = 'Moderate: ' + downlink + 'Mbps' |
| 275 | + } else { |
| 276 | + tier = 'standard'; motion = 1; reason = 'Slow 4G: ' + downlink + 'Mbps' |
| 277 | + } |
| 278 | + } |
| 279 | + // Fallback: performance timing |
| 280 | + else { |
| 281 | + const nav = performance.getEntriesByType('navigation')[0] |
| 282 | + if (nav) { |
| 283 | + const ttfb = nav.responseStart - nav.requestStart |
| 284 | + if (ttfb < 800) { tier = 'premium'; motion = 3; reason = 'TTFB: ' + Math.round(ttfb) + 'ms' } |
| 285 | + else if (ttfb < 2000) { tier = 'standard'; motion = 2; reason = 'TTFB: ' + Math.round(ttfb) + 'ms' } |
| 286 | + else { tier = 'lite'; motion = 0; reason = 'Slow TTFB: ' + Math.round(ttfb) + 'ms' } |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | + const elapsed = (performance.now() - start).toFixed(1) |
| 291 | + |
| 292 | + // Apply |
| 293 | + setTier(tier) |
| 294 | + |
| 295 | + // Update info |
| 296 | + document.getElementById('info-tier').textContent = tier |
| 297 | + document.getElementById('info-motion').textContent = motion |
| 298 | + document.getElementById('info-type').textContent = conn ? (conn.effectiveType || 'unknown') : 'API unavailable' |
| 299 | + document.getElementById('info-downlink').textContent = conn ? (conn.downlink + ' Mbps') : '—' |
| 300 | + document.getElementById('info-rtt').textContent = conn ? (conn.rtt + ' ms') : '—' |
| 301 | + document.getElementById('info-savedata').textContent = conn ? (conn.saveData ? 'Yes' : 'No') : '—' |
| 302 | + document.getElementById('info-reason').textContent = reason |
| 303 | + document.getElementById('info-time').textContent = elapsed + 'ms' |
| 304 | + |
| 305 | + const badge = document.getElementById('tier-badge') |
| 306 | + badge.textContent = (tier === 'premium' ? '✨ ' : tier === 'standard' ? '⚡ ' : '🪶 ') + tier.toUpperCase() |
| 307 | + badge.setAttribute('data-tier', tier) |
| 308 | + } |
| 309 | + |
| 310 | + function setTier(tier) { |
| 311 | + document.getElementById('app').setAttribute('data-tier', tier) |
| 312 | + // Update active button |
| 313 | + document.querySelectorAll('.override-btn').forEach(b => b.classList.remove('active')) |
| 314 | + } |
| 315 | + |
| 316 | + // Run detection on load |
| 317 | + detect() |
| 318 | + document.getElementById('timestamp').textContent = |
| 319 | + 'Page loaded: ' + new Date().toLocaleTimeString() + ' | Page size: ~4KB' |
| 320 | + </script> |
| 321 | +</body> |
| 322 | +</html> |
0 commit comments