import type {DownloadFiles} from './CodeBlock'; export function createStackBlitz( files: DownloadFiles['files'], deps: DownloadFiles['deps'], type: 'vanilla' | 'tailwind' | 's2' = 'vanilla', entry: string = 'Example' ) { let form = document.createElement('form'); form.hidden = true; form.method = 'POST'; form.action = 'https://stackblitz.com/run?file=src/Example.tsx'; form.target = '_blank'; let input = document.createElement('input'); input.type = 'hidden'; input.name = 'project[template]'; input.value = 'node'; form.appendChild(input); input = document.createElement('input'); input.type = 'hidden'; input.name = 'project[title]'; input.value = 'Project'; form.appendChild(input); input = document.createElement('input'); input.type = 'hidden'; input.name = 'project[description]'; input.value = 'description'; form.appendChild(input); let generatedFiles = getFiles(files, deps, type, entry); for (let name in generatedFiles) { input = document.createElement('input'); input.type = 'hidden'; input.name = `project[files][${name}]`; input.value = generatedFiles[name]; form.appendChild(input); } document.body.appendChild(form); form.submit(); form.remove(); } function getFiles( files: DownloadFiles['files'], deps: DownloadFiles['deps'], type: 'vanilla' | 'tailwind' | 's2' = 'vanilla', entry: string = 'Example' ) { let entryName = entry.split('/').pop()!.split('.')[0]; return { 'package.json': JSON.stringify( { name: 'react-aria-starter', private: true, version: '0.0.0', type: 'module', scripts: { dev: 'vite', build: 'vite build', preview: 'vite preview' }, dependencies: { react: '^19', 'react-dom': '^19', ...(type === 's2' ? {'@react-spectrum/s2': 'latest'} : {}), ...deps }, devDependencies: { '@types/react': '^19', '@types/react-dom': '^19', vite: '^6', '@vitejs/plugin-react': '^4', ...(type === 'tailwind' ? { tailwindcss: '^4', '@tailwindcss/vite': '^4', 'tailwindcss-react-aria-components': '^2', 'tw-animate-css': '^1' } : {}), ...(type === 's2' ? { 'unplugin-parcel-macros': '^0.2.0' } : {}) } }, null, 2 ) + '\n', 'vite.config.ts': `import {defineConfig} from 'vite'; import react from '@vitejs/plugin-react';${type === 'tailwind' ? "\nimport tailwindcss from '@tailwindcss/vite';" : ''}${type === 's2' ? "\nimport macros from 'unplugin-parcel-macros';" : ''} export default defineConfig({ plugins: [${type === 's2' ? 'macros.vite(), ' : ''}react()${type === 'tailwind' ? ', tailwindcss()' : ''}], }); `, 'index.html': `