هوش مصنوعی سازنده HTML

توضیح بده چی میخوای، کد HTML کامل تحویل بگیر — بدون اینترنت، بدون کلید API

۱. توضیحت رو بنویس

رنگ:

۲. نتیجه

`; } /* ---------- UI ---------- */ const $ = s => document.querySelector(s); const toastEl = $('#toast'); let toastTimer; function toast(msg){ toastEl.textContent = msg; toastEl.classList.add('show'); clearTimeout(toastTimer); toastTimer = setTimeout(()=>toastEl.classList.remove('show'), 2000); } /* چیپ‌ها */ const chipsEl = $('#chips'); EXAMPLES.forEach(ex=>{ const b = document.createElement('button'); b.className = 'chip'; b.textContent = ex; b.onclick = ()=>{ $('#prompt').value = ex; $('#prompt').focus(); }; chipsEl.appendChild(b); }); /* رنگ‌ها */ const swEl = $('#swatches'); Object.keys(PALETTES).forEach((k,i)=>{ const d = document.createElement('div'); const P = PALETTES[k]; d.className = 'sw' + (i===0?' active':''); d.style.background = `linear-gradient(135deg,${P.a},${P.b},${P.c})`; d.title = k; d.onclick = ()=>{ document.querySelectorAll('.sw').forEach(x=>x.classList.remove('active')); d.classList.add('active'); current.palette = k; }; swEl.appendChild(d); }); /* تب‌ها */ document.querySelectorAll('.tab').forEach(t=>{ t.onclick = ()=>{ document.querySelectorAll('.tab').forEach(x=>x.classList.remove('active')); t.classList.add('active'); const isPreview = t.dataset.tab === 'preview'; $('#preview').classList.toggle('hidden', !isPreview); $('#code').classList.toggle('hidden', isPreview); }; }); /* تولید */ $('#genBtn').onclick = ()=>{ const p = $('#prompt').value.trim(); if(!p){ toast('اول یه توضیح بنویس 🙂'); $('#prompt').focus(); return; } const btn = $('#genBtn'); btn.disabled = true; btn.textContent = '⏳ در حال ساخت...'; setTimeout(()=>{ const type = detect(p); const code = build(type, p, current.palette); current.code = code; $('#preview').srcdoc = code; $('#code').textContent = code; // نمایش تب پیش‌نمایش document.querySelectorAll('.tab').forEach(x=>x.classList.remove('active')); document.querySelector('[data-tab="preview"]').classList.add('active'); $('#preview').classList.remove('hidden'); $('#code').classList.add('hidden'); $('#stats').textContent = `قالب: ${type} · ${code.length.toLocaleString('fa-IR')} کاراکتر`; addHistory(p, code); btn.disabled = false; btn.textContent = '✨ بساز'; toast('ساخته شد ✅'); }, 450); }; /* تاریخچه */ function addHistory(prompt, code){ current.history.unshift({prompt, code}); if(current.history.length > 6) current.history.pop(); renderHistory(); } function renderHistory(){ const h = $('#history'); h.innerHTML = current.history.length ? '

ساخته‌های قبلی

' : ''; current.history.forEach((item, i)=>{ const div = document.createElement('div'); div.className = 'hitem'; const span = document.createElement('span'); span.textContent = item.prompt; const btn = document.createElement('button'); btn.textContent = 'بازگردانی'; btn.onclick = ()=>{ current.code = item.code; $('#preview').srcdoc = item.code; $('#code').textContent = item.code; $('#prompt').value = item.prompt; toast('بازگردانی شد'); }; div.appendChild(span); div.appendChild(btn); h.appendChild(div); }); } /* پاک کردن */ $('#clearBtn').onclick = ()=>{ $('#prompt').value = ''; $('#preview').srcdoc = ''; $('#code').textContent = ''; $('#stats').textContent = ''; current.code = ''; }; /* کپی */ $('#copyBtn').onclick = async ()=>{ if(!current.code){ toast('اول بساز!'); return; } try{ await navigator.clipboard.writeText(current.code); toast('کد کپی شد 📋'); }catch(e){ const ta = document.createElement('textarea'); ta.value = current.code; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); ta.remove(); toast('کد کپی شد 📋'); } }; /* دانلود */ $('#dlBtn').onclick = ()=>{ if(!current.code){ toast('اول بساز!'); return; } const blob = new Blob([current.code], {type:'text/html;charset=utf-8'}); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'generated-page.html'; a.click(); URL.revokeObjectURL(a.href); toast('دانلود شد ⬇️'); };