document.addEventListener('DOMContentLoaded', function() { // Make blocks draggable const blocks = document.querySelectorAll('[draggable]'); blocks.forEach(block => { block.addEventListener('dragstart', function(e) { e.dataTransfer.setData('text/plain', block.id); block.classList.add('block-drag'); }); block.addEventListener('dragend', function() { block.classList.remove('block-drag'); }); }); // Code area drop target const codeArea = document.getElementById('codeArea'); codeArea.addEventListener('dragover', function(e) { e.preventDefault(); this.classList.add('border-blue-500'); }); codeArea.addEventListener('dragleave', function() { this.classList.remove('border-blue-500'); }); codeArea.addEventListener('drop', function(e) { e.preventDefault(); this.classList.remove('border-blue-500'); const blockId = e.dataTransfer.getData('text/plain'); const block = document.getElementById(blockId); if (block) { const clone = block.cloneNode(true); clone.removeAttribute('draggable'); clone.classList.remove('hover:shadow-md', 'cursor-move'); clone.classList.add('m-2'); this.appendChild(clone); } }); // Sprite selection const sprites = document.querySelectorAll('.bg-white.cursor-pointer'); sprites.forEach(sprite => { sprite.addEventListener('click', function() { sprites.forEach(s => s.classList.remove('ring-2', 'ring-blue-500')); this.classList.add('ring-2', 'ring-blue-500'); // Update stage with selected sprite const stage = document.getElementById('stage'); const icon = this.querySelector('i'); const iconName = icon.getAttribute('data-feather'); stage.innerHTML = ''; const spriteIcon = document.createElement('i'); spriteIcon.setAttribute('data-feather', iconName); spriteIcon.classList.add('text-6xl', 'text-blue-500'); stage.appendChild(spriteIcon); feather.replace(); }); }); });