// require or destructure or input blocks import Alpine from 'alpinejs'; import DaisyUI from 'daisyui'; import tailwind from 'tailwind'; import Three from 'three'; Alpine.start(); DaisyUI.start(); tailwind.addPlugin(Three); // global scope const comicFactory = new Comicscape(); class Comicscape { constructor() { this.comics = []; this.elem = document.getElementById('comic-factory'); this.btn = document.getElementById('generate-comic-btn'); this.textarea = document.getElementById('comic-textarea'); } fetchComics() { fetch('/comics') .then(response => response.json()) .then(data => { this.comics = data.ebooks; this.render(); }) .catch(error => console.error(error)); } render() { const ebooks = this.comics.map((ebook) => { return `

${ebook.title}

Read Comic Edit Comic
${ebook.title}
${ebook.description})
`; }); this.elem.innerHTML = ebooks.join(''); } generateComic() { this.textarea.value = this.elem.getAttribute('href'); this.textarea.select(); document.execCommand('copy'); console.log('Copied to clipboard!'); } } comicFactory.fetchComics(); comicFactory.btn.onclick = () => { comicFactory.generateComic(); };