\n\n","main.tsx":"import React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport './index.css';\n\nfunction App() {\n return (\n
\n

سلام دنیا

\n
\n );\n}\n\nconst rootElement = document.getElementById('root');\nif (rootElement) {\n const root = ReactDOM.createRoot(rootElement);\n root.render();\n}\n","App.tsx":"import React from 'react';\nimport './index.css';\n\nfunction App() {\n return (\n
\n
\n

Welcome to Our Startup

\n

Innovative solutions for modern problems

\n
\n
\n

About Us

\n

We are a team of passionate individuals committed to delivering the best solutions.

\n
\n
\n

Our Services

\n
\n

Consulting

\n

Expert advice to guide your business.

\n
\n
\n

Development

\n

Building scalable and efficient solutions.

\n
\n
\n
\n );\n}\n\nexport default App;\n","src/index.css":"@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font@v30.1.0/dist/font-face.css');\n\nbody {\n font-family: 'Vazir', sans-serif;\n}","public/index.html":"\n\n\n \n \n Startup\n \n\n\n
\n\n"}; 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', 'lodash', 'App') // For internal project files, assume they are relative to the root unless explicitly given path. // If base is a file path, e.g., 'App.tsx', then 'lodash' is external. // If base is a folder, e.g. 'components/', then 'Button' might be 'components/Button.tsx' const possibleRelativeToFile = normalizePath(relative); if (window.__SOURCES__[possibleRelativeToFile]) return possibleRelativeToFile; // Assume it's a bare module that needs resolution return relative; } 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 for (let ext of extensions) { if (window.__SOURCES__[cleanPath + '/index' + ext]) return { content: window.__SOURCES__[cleanPath + '/index' + ext], finalPath: cleanPath + '/index' + ext }; } return null; } 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; // Explicitly expose createRoot/hydrateRoot return { __esModule: true, default: dom, createRoot: dom ? dom.createRoot : (c) => createSafeProxy({}, 'ReactDOM.createRoot'), // Fallback createRoot hydrateRoot: dom ? 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) { // Force HashRouter for iframe compatibility without server config return { ...rrd, BrowserRouter: rrd.HashRouter, // Ensure other common exports are present Routes: rrd.Routes, Route: rrd.Route, Link: rrd.Link, useNavigate: rrd.useNavigate, useLocation: rrd.useLocation, useParams: rrd.useParams, // Add any other specific exports commonly used }; } 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; // Catch errors during execution of the transformed 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; } }; // --- BOOTSTRAP --- (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 entryPath is 'index.html', it means it's a static HTML site if ("main.tsx".endsWith('.html')) { // Already handled by initialHtmlContent, ensure it's displayed if root is empty if (!rootEl.innerHTML.trim()) { rootEl.innerHTML = '
Static HTML content should be here.
'; } return; } const entry = "main.tsx"; if (entry && window.__SOURCES__[entry]) { console.info('[Rafiei Builder] Executing entry file: ' + entry); const AppModule = window.require(entry); const App = AppModule.default || AppModule; 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)) + '
'; } } }); })();