Spaces:
Running
Running
Download index.html from ayoubface/webcraft-3d-builder: direct link, hf CLI and curl.
- Browser
- Download file 26.1 kB
-
https://huggingface.co/spaces/ayoubface/webcraft-3d-builder/resolve/main/index.html
- Command line
-
hf download hf://spaces/ayoubface/webcraft-3d-builder/index.html
-
curl -L -o index.html https://huggingface.co/spaces/ayoubface/webcraft-3d-builder/resolve/main/index.html
26.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>WebCraft 3D Builder - First Prompt</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> | |
| <script src="https://unpkg.com/feather-icons"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.net.min.js"></script> | |
| <style> | |
| .drop-zone { | |
| border: 2px dashed #cbd5e1; | |
| border-radius: 0.5rem; | |
| padding: 2rem; | |
| text-align: center; | |
| transition: all 0.3s ease; | |
| } | |
| .drop-zone.active { | |
| border-color: #3b82f6; | |
| background-color: rgba(59, 130, 246, 0.05); | |
| } | |
| .preview-container { | |
| max-height: 400px; | |
| overflow: auto; | |
| border: 1px solid #e5e7eb; | |
| border-radius: 0.5rem; | |
| padding: 1rem; | |
| background: #f8fafc; | |
| } | |
| #previewFrame { | |
| width: 100%; | |
| height: 400px; | |
| border: none; | |
| background: white; | |
| border-radius: 0.25rem; | |
| } | |
| .model-preview { | |
| width: 100%; | |
| height: 300px; | |
| background: #f1f5f9; | |
| border-radius: 0.5rem; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div id="vanta-bg" class="fixed inset-0 z-0"></div> | |
| <div class="relative z-10 container mx-auto px-4 py-8"> | |
| <header class="text-center mb-12"> | |
| <h1 class="text-4xl font-bold text-gray-800 mb-2">First Prompt Received 🎯</h1> | |
| <p class="text-gray-600">Successfully processed your initial request to modify the WebCraft 3D Builder application</p> | |
| </header> | |
| <div class="grid md:grid-cols-2 gap-8 mb-12"> | |
| <!-- Website Upload Section --> | |
| <div class="bg-white rounded-xl shadow-lg p-6"> | |
| <h2 class="text-2xl font-semibold mb-4 flex items-center"> | |
| <i data-feather="globe" class="mr-2"></i> Website Files | |
| </h2> | |
| <div class="drop-zone" id="websiteDropZone"> | |
| <i data-feather="upload-cloud" class="w-12 h-12 text-gray-400 mx-auto mb-3"></i> | |
| <p class="text-gray-600 mb-2">Drag & drop your website files here</p> | |
| <p class="text-sm text-gray-500 mb-4">HTML, CSS, JS, images and other assets</p> | |
| <button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg transition"> | |
| Select Files | |
| </button> | |
| <input type="file" id="websiteFiles" class="hidden" multiple webkitdirectory> | |
| </div> | |
| <div class="mt-6"> | |
| <h3 class="font-medium mb-3">Uploaded Files</h3> | |
| <div class="bg-gray-100 rounded-lg p-4 max-h-40 overflow-y-auto" id="fileList"> | |
| <p class="text-gray-500 text-sm">No files uploaded yet</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- 3D Model Upload Section --> | |
| <div class="bg-white rounded-xl shadow-lg p-6"> | |
| <h2 class="text-2xl font-semibold mb-4 flex items-center"> | |
| <i data-feather="box" class="mr-2"></i> 3D Models | |
| </h2> | |
| <div class="drop-zone" id="modelDropZone"> | |
| <i data-feather="package" class="w-12 h-12 text-gray-400 mx-auto mb-3"></i> | |
| <p class="text-gray-600 mb-2">Drag & drop your 3D models here</p> | |
| <p class="text-sm text-gray-500 mb-4">OBJ, GLTF, GLB, FBX, STL, and more</p> | |
| <button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg transition"> | |
| Select Models | |
| </button> | |
| <input type="file" id="modelFiles" class="hidden" multiple accept=".obj,.gltf,.glb,.fbx,.stl,.dae,.3ds,.ply"> | |
| </div> | |
| <div class="mt-6"> | |
| <h3 class="font-medium mb-3">Uploaded Models</h3> | |
| <div class="bg-gray-100 rounded-lg p-4 max-h-40 overflow-y-auto" id="modelList"> | |
| <p class="text-gray-500 text-sm">No models uploaded yet</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Preview Section --> | |
| <div class="bg-white rounded-xl shadow-lg p-6 mb-8"> | |
| <h2 class="text-2xl font-semibold mb-4 flex items-center"> | |
| <i data-feather="eye" class="mr-2"></i> Preview | |
| </h2> | |
| <div class="preview-container"> | |
| <iframe id="previewFrame" src="about:blank"></iframe> | |
| </div> | |
| <div class="mt-4 flex space-x-3"> | |
| <button id="refreshPreview" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center"> | |
| <i data-feather="refresh-cw" class="w-4 h-4 mr-2"></i> Refresh Preview | |
| </button> | |
| <button id="clearAll" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg flex items-center"> | |
| <i data-feather="trash-2" class="w-4 h-4 mr-2"></i> Clear All | |
| </button> | |
| </div> | |
| </div> | |
| <!-- 3D Model Preview Section --> | |
| <div class="bg-white rounded-xl shadow-lg p-6"> | |
| <h2 class="text-2xl font-semibold mb-4 flex items-center"> | |
| <i data-feather="box" class="mr-2"></i> 3D Model Preview | |
| </h2> | |
| <div class="model-preview" id="modelPreview"> | |
| <p class="text-gray-500">Upload a 3D model to see preview</p> | |
| </div> | |
| <div class="mt-4 grid grid-cols-1 md:grid-cols-3 gap-4" id="modelControls"> | |
| <!-- Model controls will be added dynamically --> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Initialize Vanta.js background | |
| VANTA.NET({ | |
| el: "#vanta-bg", | |
| mouseControls: true, | |
| touchControls: true, | |
| gyroControls: false, | |
| minHeight: 200.00, | |
| minWidth: 200.00, | |
| scale: 1.00, | |
| scaleMobile: 1.00, | |
| color: 0x3b82f6, | |
| backgroundColor: 0xf8fafc, | |
| points: 12.00, | |
| maxDistance: 22.00, | |
| spacing: 18.00 | |
| }); | |
| // Initialize Feather Icons | |
| feather.replace(); | |
| // File handling variables | |
| let uploadedFiles = new Map(); | |
| let uploadedModels = new Map(); | |
| // Drop zone functionality | |
| const websiteDropZone = document.getElementById('websiteDropZone'); | |
| const modelDropZone = document.getElementById('modelDropZone'); | |
| const websiteFileInput = document.getElementById('websiteFiles'); | |
| const modelFileInput = document.getElementById('modelFiles'); | |
| const fileList = document.getElementById('fileList'); | |
| const modelList = document.getElementById('modelList'); | |
| const previewFrame = document.getElementById('previewFrame'); | |
| const refreshPreviewBtn = document.getElementById('refreshPreview'); | |
| const clearAllBtn = document.getElementById('clearAll'); | |
| const modelPreview = document.getElementById('modelPreview'); | |
| const modelControls = document.getElementById('modelControls'); | |
| // Set up drop zones | |
| ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { | |
| [websiteDropZone, modelDropZone].forEach(zone => { | |
| zone.addEventListener(eventName, preventDefaults, false); | |
| }); | |
| }); | |
| function preventDefaults(e) { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| } | |
| // Highlight drop zone when item is dragged over it | |
| ['dragenter', 'dragover'].forEach(eventName => { | |
| websiteDropZone.addEventListener(eventName, () => websiteDropZone.classList.add('active'), false); | |
| modelDropZone.addEventListener(eventName, () => modelDropZone.classList.add('active'), false); | |
| }); | |
| ['dragleave', 'drop'].forEach(eventName => { | |
| websiteDropZone.addEventListener(eventName, () => websiteDropZone.classList.remove('active'), false); | |
| modelDropZone.addEventListener(eventName, () => modelDropZone.classList.remove('active'), false); | |
| }); | |
| // Handle file drops | |
| websiteDropZone.addEventListener('drop', handleWebsiteDrop, false); | |
| modelDropZone.addEventListener('drop', handleModelDrop, false); | |
| // Handle file selection via buttons | |
| websiteDropZone.querySelector('button').addEventListener('click', () => websiteFileInput.click()); | |
| modelDropZone.querySelector('button').addEventListener('click', () => modelFileInput.click()); | |
| websiteFileInput.addEventListener('change', handleWebsiteFileSelect); | |
| modelFileInput.addEventListener('change', handleModelFileSelect); | |
| function handleWebsiteDrop(e) { | |
| const dt = e.dataTransfer; | |
| const files = dt.files; | |
| handleFiles(files, 'website'); | |
| } | |
| function handleModelDrop(e) { | |
| const dt = e.dataTransfer; | |
| const files = dt.files; | |
| handleFiles(files, 'model'); | |
| } | |
| function handleWebsiteFileSelect(e) { | |
| const files = e.target.files; | |
| handleFiles(files, 'website'); | |
| } | |
| function handleModelFileSelect(e) { | |
| const files = e.target.files; | |
| handleFiles(files, 'model'); | |
| } | |
| function handleFiles(files, type) { | |
| for (let i = 0; i < files.length; i++) { | |
| const file = files[i]; | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| const content = e.target.result; | |
| if (type === 'website') { | |
| uploadedFiles.set(file.name, content); | |
| updateFileList(); | |
| // Auto-refresh preview when new website files are added | |
| refreshPreview(); | |
| } else if (type === 'model') { | |
| uploadedModels.set(file.name, { | |
| content: content, | |
| file: file | |
| }); | |
| updateModelList(); | |
| previewModel(file); | |
| // Auto-upload to server when model is added | |
| uploadModelToServer(file); | |
| } | |
| }; | |
| if (file.type.includes('text') || file.type === '') { | |
| reader.readAsText(file); | |
| } else { | |
| reader.readAsDataURL(file); | |
| } | |
| } | |
| } | |
| function uploadModelToServer(file) { | |
| const formData = new FormData(); | |
| formData.append('model', file); | |
| // Show upload status | |
| const uploadStatus = document.createElement('div'); | |
| uploadStatus.className = 'text-sm text-blue-600 mt-2'; | |
| uploadStatus.innerHTML = `<i data-feather="upload" class="w-3 h-3 mr-1"></i> Uploading ${file.name}...`; | |
| modelList.appendChild(uploadStatus); | |
| feather.replace(); | |
| fetch('/api/upload-model', { | |
| method: 'POST', | |
| body: formData | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.success) { | |
| uploadStatus.innerHTML = `<i data-feather="check" class="w-3 h-3 mr-1 text-green-600"></i> ${file.name} uploaded successfully`; | |
| // Store server file path for later use | |
| uploadedModels.get(file.name).serverPath = data.filePath; | |
| } else { | |
| uploadStatus.innerHTML = `<i data-feather="x" class="w-3 h-3 mr-1 text-red-600"></i> Upload failed: ${data.error}`; | |
| } | |
| feather.replace(); | |
| // Remove status message after 5 seconds | |
| setTimeout(() => { | |
| if (uploadStatus.parentNode) { | |
| uploadStatus.remove(); | |
| } | |
| }, 5000); | |
| }) | |
| .catch(error => { | |
| uploadStatus.innerHTML = `<i data-feather="x" class="w-3 h-3 mr-1 text-red-600"></i> Upload error: ${error.message}`; | |
| feather.replace(); | |
| setTimeout(() => { | |
| if (uploadStatus.parentNode) { | |
| uploadStatus.remove(); | |
| } | |
| }, 5000); | |
| }); | |
| } | |
| function updateFileList() { | |
| if (uploadedFiles.size === 0) { | |
| fileList.innerHTML = '<p class="text-gray-500 text-sm">No files uploaded yet</p>'; | |
| return; | |
| } | |
| fileList.innerHTML = ''; | |
| uploadedFiles.forEach((content, name) => { | |
| const div = document.createElement('div'); | |
| div.className = 'flex justify-between items-center py-2 border-b border-gray-200'; | |
| div.innerHTML = ` | |
| <div class="flex items-center"> | |
| <i data-feather="file" class="w-4 h-4 mr-2 text-gray-500"></i> | |
| <span class="text-sm">${name}</span> | |
| </div> | |
| <button class="text-red-500 hover:text-red-700" data-filename="${name}"> | |
| <i data-feather="x" class="w-4 h-4"></i> | |
| </button> | |
| `; | |
| fileList.appendChild(div); | |
| }); | |
| feather.replace(); | |
| // Add event listeners to remove buttons | |
| fileList.querySelectorAll('button').forEach(btn => { | |
| btn.addEventListener('click', (e) => { | |
| const filename = e.currentTarget.getAttribute('data-filename'); | |
| uploadedFiles.delete(filename); | |
| updateFileList(); | |
| }); | |
| }); | |
| } | |
| function updateModelList() { | |
| if (uploadedModels.size === 0) { | |
| modelList.innerHTML = '<p class="text-gray-500 text-sm">No models uploaded yet</p>'; | |
| return; | |
| } | |
| modelList.innerHTML = ''; | |
| uploadedModels.forEach((modelData, name) => { | |
| const div = document.createElement('div'); | |
| div.className = 'flex justify-between items-center py-2 border-b border-gray-200'; | |
| div.innerHTML = ` | |
| <div class="flex items-center"> | |
| <i data-feather="box" class="w-4 h-4 mr-2 text-gray-500"></i> | |
| <span class="text-sm">${name}</span> | |
| </div> | |
| <button class="text-red-500 hover:text-red-700" data-modelname="${name}"> | |
| <i data-feather="x" class="w-4 h-4"></i> | |
| </button> | |
| `; | |
| modelList.appendChild(div); | |
| }); | |
| feather.replace(); | |
| // Add event listeners to remove buttons | |
| modelList.querySelectorAll('button').forEach(btn => { | |
| btn.addEventListener('click', (e) => { | |
| const modelname = e.currentTarget.getAttribute('data-modelname'); | |
| uploadedModels.delete(modelname); | |
| updateModelList(); | |
| if (uploadedModels.size === 0) { | |
| modelPreview.innerHTML = '<p class="text-gray-500">Upload a 3D model to see preview</p>'; | |
| modelControls.innerHTML = ''; | |
| } | |
| }); | |
| }); | |
| } | |
| function previewModel(file) { | |
| modelPreview.innerHTML = ` | |
| <div class="text-center"> | |
| <i data-feather="box" class="w-12 h-12 text-gray-400 mb-2"></i> | |
| <p class="text-gray-600">${file.name}</p> | |
| <p class="text-sm text-gray-500 mt-1">3D model loaded successfully</p> | |
| </div> | |
| `; | |
| feather.replace(); | |
| // Add basic model controls | |
| modelControls.innerHTML = ` | |
| <div class="bg-gray-100 p-3 rounded-lg"> | |
| <label class="block text-sm font-medium mb-1">Rotation X</label> | |
| <input type="range" min="0" max="360" value="0" class="w-full"> | |
| </div> | |
| <div class="bg-gray-100 p-3 rounded-lg"> | |
| <label class="block text-sm font-medium mb-1">Rotation Y</label> | |
| <input type="range" min="0" max="360" value="0" class="w-full"> | |
| </div> | |
| <div class="bg-gray-100 p-3 rounded-lg"> | |
| <label class="block text-sm font-medium mb-1">Scale</label> | |
| <input type="range" min="50" max="150" value="100" class="w-full"> | |
| </div> | |
| `; | |
| } | |
| // Refresh preview functionality | |
| refreshPreviewBtn.addEventListener('click', refreshPreview); | |
| // Add export functionality | |
| const exportBtn = document.createElement('button'); | |
| exportBtn.className = 'bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg flex items-center'; | |
| exportBtn.innerHTML = '<i data-feather="download" class="w-4 h-4 mr-2"></i> Export Project'; | |
| exportBtn.addEventListener('click', exportProject); | |
| // Add export button to the preview controls | |
| const previewControls = document.querySelector('.mt-4.flex.space-x-3'); | |
| previewControls.appendChild(exportBtn); | |
| function refreshPreview() { | |
| if (uploadedFiles.size === 0) { | |
| previewFrame.srcdoc = '<html><body><div style="display: flex; justify-content: center; align-items: center; height: 100%; color: #666;"><p>Upload website files to see preview</p></div></body></html>'; | |
| return; | |
| } | |
| // Find the main HTML file | |
| let mainHtml = null; | |
| uploadedFiles.forEach((content, name) => { | |
| if (name.toLowerCase().endsWith('.html') && !mainHtml) { | |
| mainHtml = { name, content }; | |
| } | |
| }); | |
| if (!mainHtml) { | |
| previewFrame.srcdoc = '<html><body><div style="display: flex; justify-content: center; align-items: center; height: 100%; color: #666;"><p>No HTML file found in uploaded files</p></div></body></html>'; | |
| return; | |
| } | |
| // Create a complete HTML document with all resources | |
| let htmlContent = mainHtml.content; | |
| // Inject CSS and JS files | |
| uploadedFiles.forEach((content, name) => { | |
| if (name.toLowerCase().endsWith('.css')) { | |
| htmlContent = htmlContent.replace('</head>', `<style>${content}</style></head>`); | |
| } else if (name.toLowerCase().endsWith('.js')) { | |
| htmlContent = htmlContent.replace('</body>', `<script>${content}</script></body>`); | |
| } | |
| }); | |
| // Inject 3D model integration if models are uploaded | |
| if (uploadedModels.size > 0) { | |
| const threeJsScript = ` | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/GLTFLoader.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script> | |
| `; | |
| const modelIntegrationScript = ` | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Create 3D scene container | |
| const container = document.createElement('div'); | |
| container.id = 'threejs-container'; | |
| container.style.position = 'fixed'; | |
| container.style.top = '0'; | |
| container.style.left = '0'; | |
| container.style.width = '100%'; | |
| container.style.height = '100%'; | |
| container.style.zIndex = '1000'; | |
| container.style.pointerEvents = 'none'; | |
| document.body.appendChild(container); | |
| // Initialize Three.js | |
| const scene = new THREE.Scene(); | |
| const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); | |
| const renderer = new THREE.WebGLRenderer({ alpha: true }); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| container.appendChild(renderer.domElement); | |
| // Add lights | |
| const ambientLight = new THREE.AmbientLight(0x404040); | |
| scene.add(ambientLight); | |
| const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5); | |
| directionalLight.position.set(1, 1, 1); | |
| scene.add(directionalLight); | |
| // Load models | |
| const loader = new THREE.GLTFLoader(); | |
| ${Array.from(uploadedModels.values()).map((modelData, index) => ` | |
| loader.load('${modelData.serverPath || URL.createObjectURL(modelData.file)}', function(gltf) { | |
| const model = gltf.scene; | |
| model.position.set(${index * 2}, 0, -5); | |
| scene.add(model); | |
| }); | |
| `).join('')} | |
| camera.position.z = 5; | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| renderer.render(scene, camera); | |
| } | |
| animate(); | |
| window.addEventListener('resize', function() { | |
| camera.aspect = window.innerWidth / window.innerHeight; | |
| camera.updateProjectionMatrix(); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| }); | |
| }); | |
| </script> | |
| `; | |
| htmlContent = htmlContent.replace('</head>', `${threeJsScript}</head>`); | |
| htmlContent = htmlContent.replace('</body>', `${modelIntegrationScript}</body>`); | |
| } | |
| previewFrame.srcdoc = htmlContent; | |
| } | |
| function exportProject() { | |
| if (uploadedFiles.size === 0 && uploadedModels.size === 0) { | |
| alert('No files to export'); | |
| return; | |
| } | |
| // Create project manifest | |
| const manifest = { | |
| version: '1.0', | |
| timestamp: new Date().toISOString(), | |
| files: Array.from(uploadedFiles.keys()), | |
| models: Array.from(uploadedModels.keys()), | |
| modelServerPaths: Array.from(uploadedModels.values()).map(model => model.serverPath) | |
| }; | |
| // Create zip file | |
| const zip = new JSZip(); | |
| // Add website files | |
| uploadedFiles.forEach((content, name) => { | |
| zip.file(name, content); | |
| }); | |
| // Add models | |
| uploadedModels.forEach((modelData, name) => { | |
| zip.file(name, modelData.file); | |
| }); | |
| // Add manifest | |
| zip.file('project-manifest.json', JSON.stringify(manifest, null, 2)); | |
| // Generate and download zip | |
| zip.generateAsync({type: 'blob'}).then(function(content) { | |
| const link = document.createElement('a'); | |
| link.href = URL.createObjectURL(content); | |
| link.download = 'webcraft-project.zip'; | |
| link.click(); | |
| URL.revokeObjectURL(link.href); | |
| }); | |
| } | |
| // Load JSZip library for export functionality | |
| const script = document.createElement('script'); | |
| script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js'; | |
| document.head.appendChild(script); | |
| // Clear all functionality | |
| clearAllBtn.addEventListener('click', () => { | |
| if (confirm('Are you sure you want to clear all uploaded files and models?')) { | |
| uploadedFiles.clear(); | |
| uploadedModels.clear(); | |
| updateFileList(); | |
| updateModelList(); | |
| previewFrame.srcdoc = '<html><body><div style="display: flex; justify-content: center; align-items: center; height: 100%; color: #666;"><p>Upload website files to see preview</p></div></body></html>'; | |
| modelPreview.innerHTML = '<p class="text-gray-500">Upload a 3D model to see preview</p>'; | |
| modelControls.innerHTML = ''; | |
| } | |
| }); | |
| // Initial empty preview | |
| refreshPreview(); | |
| </script> | |
| </body> | |
| </html> | |