import { tutorialStore, webcontainer as webcontainerPromise } from './webcontainer.js'; export function DownloadButton() { return ( ); } async function onClick() { const lesson = tutorialStore.lesson; if (!lesson) { throw new Error('Missing lesson'); } const webcontainer = await webcontainerPromise; const data = await webcontainer.export('/home/tutorial', { format: 'zip', excludes: ['node_modules'] }); let filename = typeof lesson.data.downloadAsZip === 'object' ? lesson.data.downloadAsZip.filename : [lesson.part?.id, lesson.chapter?.id, lesson.id].filter(Boolean).join('-'); if (!filename.endsWith('.zip')) { filename += '.zip'; } const link = document.createElement('a'); link.style.display = 'none'; link.download = filename; link.href = URL.createObjectURL(new Blob([data] as any, { type: 'application/zip' })); document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(link.href); }