\n \n \n \n\n","main.tsx":"import React from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport App from \"./App\";\nimport './index.css';\n\nconst container = document.getElementById(\"root\");\nif (container) {\n const root = createRoot(container);\n root.render(\n \n \n \n );\n}","App.tsx":"import React from \"react\";\n\nconst App: React.FC = () => {\n return (\n
\n

Welcome

\n
\n );\n};\n\nexport default App;","src/index.css":"/* استایل‌های سفارشی برای پروژه */\n\n/* رنگ‌های اصلی */\n:root {\n --color-primary: #6366f1;\n --color-secondary: #a855f7;\n --color-accent: #ef4444;\n --color-neutral-50: #f8fafc;\n --color-neutral-900: #0f172a;\n --color-success: #22c55e;\n --color-warning: #eab308;\n --color-error: #ef4444;\n --color-background: #8b5cf6; /* Added background color variable */\n}\n\n/* تایپوگرافی */\nbody {\n font-family: 'Inter', sans-serif;\n font-size: 1rem;\n line-height: 1.5;\n background-color: var(--color-background); /* Set background color */\n}\n\nh1 {\n font-size: 4rem;\n line-height: 1.1;\n font-family: 'Inter', sans-serif;\n}\n\n/* استایل‌های اضافی */\n.bg-hero {\n background-color: var(--color-secondary);\n}"}; // Raw source code files function normalizePath(path) { return path.replace(/\.\//g, '').replace(/^\//, ''); // Remove leading ./ and / } function resolvePath(base, relative) { if (!relative.startsWith('.')) { // Absolute or bare module import (e.g., 'react', 'App') const possibleRelativeToFile = normalizePath(relative); if (window.__SOURCES__[possibleRelativeToFile]) return possibleRelativeToFile; return relative; // Assume it's an external bare module } const stack = base.split('/'); stack.pop(); // Remove current file name const parts = relative.split('/'); for (let i = 0; i < parts.length; i++) { if (parts[i] === '.') continue; if (parts[i] === '..') stack.pop(); else stack.push(parts[i]); } return stack.join('/'); } function getFileContent(path) { const cleanPath = normalizePath(path); if (window.__SOURCES__[cleanPath]) return { content: window.__SOURCES__[cleanPath], finalPath: cleanPath }; const extensions = ['.tsx', '.ts', '.jsx', '.js', '.css', '.json']; for (let ext of extensions) { if (window.__SOURCES__[cleanPath + ext]) return { content: window.__SOURCES__[cleanPath + ext], finalPath: cleanPath + ext }; } // Try '/index' for directory imports (e.g., import 'components/Button' -> 'components/Button/index.tsx') for (let ext of extensions) { if (window.__SOURCES__[cleanPath + '/index' + ext]) return { content: window.__SOURCES__[cleanPath + '/index' + ext], finalPath: cleanPath + '/index' + ext }; } return null; } // The core 'require' function that transpiles and evaluates modules window.require = function(path, base = '') { // --- BUILT-INS (ALIASES TO GLOBALS) --- if (path === 'react') return window.React; if (path === 'react-dom') return window.ReactDOM; if (path === 'react-dom/client') { const dom = window.ReactDOM; return { __esModule: true, default: dom, createRoot: dom?.createRoot || ((c) => createSafeProxy({}, 'ReactDOM.createRoot')), // Fallback hydrateRoot: dom?.hydrateRoot || ((c) => createSafeProxy({}, 'ReactDOM.hydrateRoot')), }; } if (path === '@supabase/supabase-js') return window.supabase || createSafeProxy({}, '@supabase/supabase-js'); if (path === 'lucide-react') return window.lucideReact || createSafeProxy({}, 'lucide-react'); if (path === 'react-router-dom' || path === 'react-router') { const rrd = window.ReactRouterDOM; if (rrd) { return { ...rrd, BrowserRouter: rrd.HashRouter, // Force HashRouter for iframe srcdoc compatibility Routes: rrd.Routes, Route: rrd.Route, Link: rrd.Link, useNavigate: rrd.useNavigate, useLocation: rrd.useLocation, useParams: rrd.useParams, }; } return createSafeProxy({}, path); } const resolvedPath = resolvePath(base, path); const fileInfo = getFileContent(resolvedPath); if (!fileInfo) { console.warn('Module not found:', path, 'Resolved:', resolvedPath, 'Base:', base); return createSafeProxy({}, path); } const { content, finalPath } = fileInfo; if (window.__MODULES__[finalPath]) return window.__MODULES__[finalPath].exports; if (finalPath.endsWith('.css')) { const style = document.createElement('style'); style.textContent = content; document.head.appendChild(style); window.__MODULES__[finalPath] = { exports: {} }; return {}; } if (finalPath.endsWith('.json')) { try { const json = JSON.parse(content); window.__MODULES__[finalPath] = { exports: json }; return json; } catch(e) { console.error('JSON Parse Error in ' + finalPath, e); return createSafeProxy({}, finalPath); } } const module = { exports: {} }; window.__MODULES__[finalPath] = module; try { const presets = [['env', { modules: 'commonjs' }], 'react']; if (finalPath.endsWith('.ts') || finalPath.endsWith('.tsx')) { presets.push('typescript'); } const transformed = Babel.transform(content, { presets, filename: finalPath }).code; const wrapper = new Function('module', 'exports', 'require', transformed); wrapper(module, module.exports, (p) => window.require(p, finalPath)); return module.exports; } catch (e) { console.error('Compilation or Execution Error in ' + finalPath, e); const ErrorComponent = () => window.React.createElement('div', { style: { color: 'red', padding: 10, background: '#fee2e2', border: '1px solid red', margin: '10px', borderRadius: '5px', fontFamily: 'monospace', whiteSpace: 'pre-wrap' } }, 'Error in ' + finalPath + ':\n' + (e.message || String(e))); window.__MODULES__[finalPath].exports = { default: ErrorComponent, ErrorComponent }; return window.__MODULES__[finalPath].exports; } }; // --- APPLICATION BOOTSTRAP (runs after DOM is ready) --- (function() { document.addEventListener('DOMContentLoaded', function() { console.info('[Rafiei Builder] DOMContentLoaded fired. Bootstrapping preview...'); try { const rootEl = document.getElementById('root'); if (!rootEl) { throw new Error("Bootstrap failed: #root element not found in the preview document."); } // If it's a static HTML site (no main JS entry point), do not attempt React bootstrap. if (false) { console.info('[Rafiei Builder] Static HTML site detected. No JS bootstrap needed.'); return; // The HTML is already rendered } const entry = "main.tsx"; // e.g., 'App.tsx' or 'index.tsx' if (entry && window.__SOURCES__[entry]) { console.info('[Rafiei Builder] Executing entry file: ' + entry); const AppModule = window.require(entry); const App = AppModule.default || AppModule; // Get default export or the module itself if (typeof window.ReactDOM !== 'undefined' && typeof window.ReactDOM.createRoot === 'function' && typeof App === 'function') { window.ReactDOM.createRoot(rootEl).render(window.React.createElement(App)); console.info('[Rafiei Builder] React App rendered successfully.'); } else { rootEl.innerHTML = '
Error: React or ReactDOM not available, or App is not a valid component.
'; console.error('[Rafiei Builder] React/ReactDOM or App component issue.', {ReactDOM: typeof window.ReactDOM, createRoot: typeof window.ReactDOM?.createRoot, AppType: typeof App}); } } else { console.warn('[Rafiei Builder] No valid JS/TS entry file found to execute. Entry path: "' + entry + '"'); rootEl.innerHTML = '
Preview boot failed: No executable entry file found.
'; } } catch (e) { console.error('[Rafiei Builder] Bootstrap Error:', e); const overlay = document.getElementById('error-overlay'); if(overlay) { overlay.style.display = 'block'; overlay.innerHTML = '

Bootstrap Error

' + '
' + (e.message || String(e)) + '
'; } } }); })();