SYSTEM BOOT // KERNEL v8.4.1
SYS_USR@PROMPT:>
INTRUSION_SEQUENCE: ACTIVE TIME: 60.00s
TARGET_SIGNATURE
01101
CURRENT_OUT: 00000

ACCESS GRANTED

function resetApp() { window.appState = { businessName: "", chatStep: 0, answers: [], planData: null, logoUrl: null, targetRevenue: 0, isGenerating: false }; elements.inputName.value = ""; elements.chatMessages.innerHTML = ""; elements.planContent.innerHTML = ""; elements.logoImg.src = ""; elements.logoImg.classList.add('hidden'); elements.logoPlaceholder.classList.remove('hidden'); // Reset loading steps Object.values(elements.loadSteps).forEach(step => { step.querySelector('i').className = "fa-regular fa-circle text-slate-300 w-5"; step.querySelector('span').classList.remove('text-blue-600', 'font-bold'); }); switchTab('tab-plan'); showScreen('intro'); } // ========================================== // 7. CHAT LOGIC // ========================================== function startChat() { const greetingOverride = getConfig('text', 'greeting'); const initialMsg = greetingOverride || QUESTIONS[0]; setTimeout(() => { addMessage(initialMsg, 'bot'); }, 500); } function addMessage(text, sender) { const wrap = document.createElement('div'); wrap.className = `chat-bubble bubble-${sender}`; wrap.textContent = text; elements.chatMessages.appendChild(wrap); elements.chatMessages.scrollTop = elements.chatMessages.scrollHeight; if (sender === 'bot') { vibrate(40); playSound('receive', 700); } else { playSound('pop', 400); } } function showTyping() { const id = 'typing-' + Date.now(); const wrap = document.createElement('div'); wrap.className = 'typing-indicator'; wrap.id = id; wrap.innerHTML = ''; elements.chatMessages.appendChild(wrap); elements.chatMessages.scrollTop = elements.chatMessages.scrollHeight; return id; } function removeTyping(id) { const el = document.getElementById(id); if (el) el.remove(); } function handleChatSubmit() { const val = elements.inputChat.value.trim(); if (!val || window.appState.isGenerating) return; elements.inputChat.value = ''; addMessage(val, 'user'); window.appState.answers.push(val); window.appState.chatStep++; if (window.appState.chatStep < QUESTIONS.length) { const typingId = showTyping(); setTimeout(() => { removeTyping(typingId); addMessage(QUESTIONS[window.appState.chatStep], 'bot'); }, 800); } else { // Done with chat elements.inputChat.disabled = true; elements.btnSendChat.disabled = true; const typingId = showTyping(); // Extract revenue number const revMatch = val.match(/\d+/g); if (revMatch) { window.appState.targetRevenue = parseInt(revMatch.join(''), 10); } else { window.appState.targetRevenue = 5000; // fallback } setTimeout(() => { removeTyping(typingId); addMessage("Got it! I'm putting everything together now. Give me a moment...", 'bot'); setTimeout(beginGeneration, 1500); }, 1000); } } // ========================================== // 8. GENERATION LOGIC // ========================================== function updateLoadStep(stepId, status) { const el = elements.loadSteps[stepId]; const icon = el.querySelector('i'); const text = el.querySelector('span'); if (status === 'active') { icon.className = "fa-solid fa-spinner fa-spin text-blue-500 w-5"; text.classList.add('text-blue-600', 'font-bold'); } else if (status === 'done') { icon.className = "fa-solid fa-circle-check text-green-500 w-5"; text.classList.remove('text-blue-600', 'font-bold'); text.classList.add('text-green-600'); vibrate(30); } } async function beginGeneration() { window.appState.isGenerating = true; showScreen('loading'); try { // STEP 1: Plan updateLoadStep('plan', 'active'); const promptCfg = window.globalPrompts.planGen; let userPrompt = promptCfg.userPromptTemplate .replace('[NAME]', window.appState.businessName) .replace('[ANS1]', window.appState.answers[0]) .replace('[ANS2]', window.appState.answers[1]) .replace('[ANS3]', window.appState.answers[2]); window.globalPrompts.planGen.systemPrompt = getConfig('prompts', 'system_plan') || window.globalPrompts.planGen.systemPrompt; const textResult = await genText( window.globalPrompts.planGen.systemPrompt, userPrompt, promptCfg.responseSchema ); window.appState.planData = textResult.markdownPlan; updateLoadStep('plan', 'done'); // STEP 2: Logo updateLoadStep('logo', 'active'); const baseLogoPrompt = getConfig('prompts', 'system_logo') || "A clean minimalist vector logo"; const logoPrompt = `${baseLogoPrompt}. Business Name: "${window.appState.businessName}". Concept related to: ${window.appState.answers[0]}`; try { const imgResult = await genImage(logoPrompt); window.appState.logoUrl = imgResult.imageUrl; } catch(e) { console.error("Logo gen failed, using fallback", e); } updateLoadStep('logo', 'done'); // STEP 3: Chart updateLoadStep('chart', 'active'); await new Promise(r => setTimeout(r, 600)); // Fake delay for calculation UX updateLoadStep('chart', 'done'); // Save State sendMessage('save_app_states', { pageSettings: window.appState }, false); // Transition setTimeout(() => { vibrate([50, 50, 100]); playSound('success', 800, 'triangle'); populateDashboard(); showScreen('dashboard'); }, 1000); } catch(e) { console.error("Generation error:", e); alert("Something went wrong during generation. Please try again."); resetApp(); } window.appState.isGenerating = false; elements.inputChat.disabled = false; elements.btnSendChat.disabled = false; } // ========================================== // 9. DASHBOARD & RENDERING // ========================================== function populateDashboard() { elements.dashTitle.textContent = window.appState.businessName; elements.logoBizName.textContent = window.appState.businessName; // Format Markdown (Simple regex replacement for headers and lists) let html = window.appState.planData .replace(/^### (.*$)/gim, '

$1

') .replace(/^## (.*$)/gim, '

$1

') .replace(/^# (.*$)/gim, '

$1

') .replace(/^\* (.*$)/gim, '
  • $1
  • ') .replace(/^- (.*$)/gim, '
  • $1
  • ') .replace(/\n\n/gim, '

    ') .replace(/\*\*(.*?)\*\*/gim, '$1'); // Wrap loose li elements html = html.replace(/<\/li>\s*

  • /g, '
  • '); html = html.replace(/(
  • .*<\/li>)/s, ''); elements.planContent.innerHTML = `

    ${html}

    `; // Logo if (window.appState.logoUrl) { elements.logoImg.src = window.appState.logoUrl; elements.logoImg.classList.remove('hidden'); elements.logoPlaceholder.classList.add('hidden'); } // Chart Texts const fmtRev = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }).format(window.appState.targetRevenue); elements.chartGoalText.textContent = `Goal: ${fmtRev}`; // Draw Chart (will be drawn when tab is shown) switchTab('tab-plan'); } function restoreDashboard() { populateDashboard(); showScreen('dashboard'); } function drawChart() { const canvas = elements.trendCanvas; const ctx = canvas.getContext('2d'); const parent = canvas.parentElement; // Handle retina displays const dpr = window.devicePixelRatio || 1; canvas.width = parent.clientWidth * dpr; canvas.height = parent.clientHeight * dpr; ctx.scale(dpr, dpr); const w = parent.clientWidth; const h = parent.clientHeight; ctx.clearRect(0, 0, w, h); // Data generation (Curve to target) const target = window.appState.targetRevenue || 5000; const points = []; const months = 12; const paddingX = 20; const paddingY = 20; const graphW = w - paddingX * 2; const graphH = h - paddingY * 2; for(let i=0; i { if (i === 0 || i === points.length - 1 || i % 3 === 0) { ctx.beginPath(); ctx.arc(p.x, p.y, 4, 0, Math.PI * 2); ctx.fillStyle = '#fff'; ctx.fill(); ctx.lineWidth = 2; ctx.strokeStyle = primaryColor; ctx.stroke(); } }); } // ========================================== // 10. SHARE LOGIC (SNAPDOM) // ========================================== async function handleShare() { const btn = elements.btnShare; if (btn.dataset.loading === 'true') return; btn.dataset.loading = 'true'; const origHTML = btn.innerHTML; btn.innerHTML = ''; try { // Determine what to share based on active tab const shareZone = document.getElementById('share-zone'); const area = shareZone.offsetWidth * shareZone.offsetHeight; const targetScale = area > 500000 ? 1.5 : 2; const jpgImg = await window.snapdom.toJpg(shareZone, { quality: 0.7, width: shareZone.offsetWidth * targetScale, height: shareZone.offsetHeight * targetScale, }); await sendMessage('invoke_share', { title: `Check out the business plan for ${window.appState.businessName}!`, coverImageBase64: jpgImg.src, appStates: { pageSettings: window.appState } }, false); } catch (e) { console.error('Share failed:', e); } finally { btn.dataset.loading = 'false'; btn.innerHTML = origHTML; } } // ========================================== // 11. PREVIEW EDITING API // ========================================== (function setupPreviewEditingAPI() { window.addEventListener('message', (event) => { const msg = event.data; if (msg?.origin !== 'sekai_gaming_iframe_api') return; switch (msg.type) { case 'get_editable_metadata': window.parent.postMessage({ origin: 'sekai_gaming_iframe_api', type: 'receive_editable_metadata', taskId: msg.taskId, data: window.sekaiEditable || {} }, '*'); break; case 'apply_change': const success = applySingleChange(msg.data.id, msg.data.value, msg.data.name, msg.data.description); window.parent.postMessage({ origin: 'sekai_gaming_iframe_api', type: 'receive_apply_change', taskId: msg.taskId, data: { success } }, '*'); break; case 'get_current_html': window.parent.postMessage({ origin: 'sekai_gaming_iframe_api', type: 'receive_current_html', taskId: msg.taskId, data: { html: document.documentElement.outerHTML } }, '*'); break; case 'reset_changes': location.reload(); break; } }); function applySingleChange(id, value, name, description) { const categories = ['tune', 'images', 'videos', 'music', 'sfx', 'colors', 'text', 'prompts', 'voices']; for (const cat of categories) { const item = window.sekaiEditable[cat]?.find(i => i.id === id); if (!item) continue; item.value = value; if (name) item.name = name; if (description) item.description = description; if (item.cssVar) { document.documentElement.style.setProperty(item.cssVar, value); } else if (item.path) { setNestedValue(window, item.path, value); } else if (item.selector) { const el = document.querySelector(item.selector); if (!el) return false; if (el.tagName === 'AUDIO' || el.tagName === 'VIDEO') { const wasPlaying = !el.paused; el.src = value; el.load(); if (wasPlaying) el.play().catch(() => {}); } else if (item.property === 'src') { el.src = value; } else if (item.property === 'backgroundImage') { el.style.backgroundImage = `url('${value}')`; } else if (item.property === 'placeholder') { el.placeholder = value; } else { el.textContent = value; } } return true; } return false; } })(); // Boot document.addEventListener('DOMContentLoaded', initApp);