Download script.js from YuriVM/flexdroid-android-flex-design-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/spaces/YuriVM/flexdroid-android-flex-design-studio/resolve/main/script.js
- Command line
-
hf download hf://spaces/YuriVM/flexdroid-android-flex-design-studio/script.js
-
curl -L -o script.js https://huggingface.co/spaces/YuriVM/flexdroid-android-flex-design-studio/resolve/main/script.js
2.95 kB
| // FlexDroid - Android Flex Design Studio | |
| let currentClasses = ['flex', 'flex-col', 'items-center', 'justify-center', 'gap-4']; | |
| let itemCount = 2; | |
| let itemHeight = 'h-24'; | |
| function updateFlex(className) { | |
| // Remove existing flex classes | |
| const flexPrefixes = ['flex-', 'justify-', 'items-', 'gap-']; | |
| currentClasses = currentClasses.filter(cls => | |
| !flexPrefixes.some(prefix => cls.startsWith(prefix)) | |
| ); | |
| // Add new class | |
| currentClasses.push(className); | |
| // Update preview | |
| updatePreview(); | |
| // Update active buttons | |
| document.querySelectorAll('.flex-btn').forEach(btn => { | |
| btn.classList.remove('bg-indigo-100', 'text-indigo-800'); | |
| btn.classList.add('bg-gray-100', 'text-gray-800'); | |
| }); | |
| const activeBtn = document.querySelector(`.flex-btn[onclick="updateFlex('${className}')"]`); | |
| if (activeBtn) { | |
| activeBtn.classList.remove('bg-gray-100', 'text-gray-800'); | |
| activeBtn.classList.add('bg-indigo-100', 'text-indigo-800'); | |
| } | |
| } | |
| function updateItemCount(count) { | |
| itemCount = parseInt(count); | |
| updatePreview(); | |
| } | |
| function updateItemHeight(height) { | |
| itemHeight = height; | |
| updatePreview(); | |
| } | |
| function updatePreview() { | |
| const previewContent = document.getElementById('previewContent'); | |
| previewContent.className = currentClasses.join(' '); | |
| // Generate items | |
| let itemsHTML = ''; | |
| for (let i = 0; i < itemCount; i++) { | |
| itemsHTML += ` | |
| <div class="bg-indigo-100 p-4 rounded-lg ${itemHeight} flex items-center justify-center"> | |
| <p class="text-indigo-800">Flex Item ${i+1}</p> | |
| </div> | |
| `; | |
| } | |
| previewContent.innerHTML = itemsHTML; | |
| // Update code output | |
| updateCodeOutput(); | |
| } | |
| function updateCodeOutput() { | |
| const codeOutput = document.getElementById('codeOutput'); | |
| let itemsCode = ''; | |
| for (let i = 0; i < itemCount; i++) { | |
| itemsCode += ` | |
| <div class="bg-indigo-100 p-4 rounded-lg ${itemHeight} flex items-center justify-center"> | |
| <p class="text-indigo-800">Flex Item ${i+1}</p> | |
| </div>`; | |
| } | |
| const classesStr = currentClasses.map(c => c.replace(/-/g, '\\-')).join(' '); | |
| codeOutput.textContent = `<div class="${classesStr}">${itemsCode} | |
| </div>`; | |
| } | |
| function copyCode() { | |
| const code = document.getElementById('codeOutput').textContent; | |
| navigator.clipboard.writeText(code.replace(/</g, '<').replace(/>/g, '>')); | |
| // Show copied notification | |
| const btn = document.querySelector('[onclick="copyCode()"]'); | |
| const originalText = btn.innerHTML; | |
| btn.innerHTML = '<i data-feather="check"></i> Copied!'; | |
| feather.replace(); | |
| setTimeout(() => { | |
| btn.innerHTML = originalText; | |
| feather.replace(); | |
| }, 2000); | |
| } | |
| // Initialize | |
| document.addEventListener('DOMContentLoaded', () => { | |
| updatePreview(); | |
| }); |