// ============================================ // DEMO RENDERER - Generic rendering for command and skill demos // ============================================ import { getCommandDemo } from './demos/commands/index.js'; import { getSkillDemo } from './demos/skills/index.js'; /** * Initialize a command demo's JS after its HTML has been inserted into the DOM. * Call this after innerHTML is set and split compare is initialized. */ export function initCommandDemo(commandId, container) { const demo = getCommandDemo(commandId); if (demo && typeof demo.init === 'function') { const demoArea = container.querySelector('.split-after .split-content') || container; console.log('[initCommandDemo]', commandId, 'demoArea:', demoArea); demo.init(demoArea); } } /** * Render a command demo with split-screen comparison */ export function renderCommandDemo(commandId) { const demo = getCommandDemo(commandId); if (!demo) { // teach-impeccable is a setup command, not a visual transform — show usage guide instead if (commandId === 'teach-impeccable') { return `
When to run
1. Once per project, before using other commands
2. Again if your brand or design direction changes
What it does
Scans your codebase for existing design patterns
Asks about brand, users, and aesthetic direction
Saves a Design Context to your AI config file
All other commands use this context automatically.
`; } return `
Visual demo for /${commandId} coming soon
`; } // Use split-screen comparison return `
${demo.before}
${demo.after || demo.before}
${demo.caption}
`; } /** * Render a skill demo (with tabs if multiple demos) */ export function renderSkillDemo(skillId) { const skill = getSkillDemo(skillId); if (!skill || !skill.tabs || skill.tabs.length === 0) { return `

Demo for ${skillId.replace(/-/g, ' ')} coming soon

`; } const showTabs = skill.tabs.length > 1; const tabs = showTabs ? skill.tabs.map((tab, i) => ` `).join('') : ''; const panels = skill.tabs.map((tab, i) => `
${renderSkillTabDemo(skillId, tab)}
`).join(''); return `
${showTabs ? `
${tabs}
` : ''}
${panels}
`; } /** * Render a single skill tab demo */ function renderSkillTabDemo(skillId, tab) { const hasToggle = tab.hasToggle !== false; const demoId = `${skillId}-${tab.id}`; return `
${hasToggle ? `
Before After
` : ''}
${tab.before}
${tab.caption}
`; } /** * Setup demo tab switching */ export function setupDemoTabs() { document.querySelectorAll('.demo-tab').forEach(tab => { tab.addEventListener('click', () => { const tabId = tab.dataset.demoTab; const container = tab.closest('.demo-tabbed-container'); container.querySelectorAll('.demo-tab').forEach(t => t.classList.remove('active')); tab.classList.add('active'); container.querySelectorAll('.demo-panel').forEach(p => p.classList.remove('active')); container.querySelector(`[data-demo-panel="${tabId}"]`)?.classList.add('active'); }); }); }