File size: 7,222 Bytes
6f7f985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Sample pattern data
const samplePattern = `PATTERN: Nordic Cable Knit Sweater
TYPE: Adult Pullover
DIFFICULTY: Intermediate
SIZE: M (L, XL, 2XL)

MATERIALS:
- Yarn: Worsted weight wool, 1200(1400,1600,1800) yards
- Needles: US 8 (5mm) circular 24", US 6 (4mm) for ribbing
- Stitch markers, cable needle, tapestry needle

GAUGE: 18 sts x 24 rows = 4" in stockinette

PATTERN NOTES:
- Cable panel worked over 12 stitches
- Body worked in round to armholes
- Raglan sleeve construction
- Classic fit with 2" positive ease

ABBREVIATIONS:
CO: Cast on, BO: Bind off, C6F: Cable 6 front, C6B: Cable 6 back`;

// Generation tasks
const tasks = [
    { name: "Parsing pattern structure...", time: 800 },
    { name: "Generating core JSON schema...", time: 1200 },
    { name: "Creating visual diagrams (AI image gen)...", time: 3000 },
    { name: "Generating accessibility layers...", time: 1500 },
    { name: "Building course curricula (LLM)...", time: 2500 },
    { name: "Synthesizing audio (TTS)...", time: 4000 },
    { name: "Rendering 3D assets...", time: 3500 },
    { name: "Creating marketing copy...", time: 1000 },
    { name: "Translating to 5 languages...", time: 3000 },
    { name: "Packaging deliverables...", time: 800 }
];

let currentTask = 0;
let isGenerating = false;

// Initialize Lucide icons
document.addEventListener('DOMContentLoaded', () => {
    lucide.createIcons();
});

function loadSample() {
    document.getElementById('pattern-input').value = samplePattern;
    document.getElementById('source-id').textContent = 'PATTERN-' + Math.random().toString(36).substr(2, 6).toUpperCase();
}

function generateAll() {
    const input = document.getElementById('pattern-input').value.trim();
    if (!input) {
        alert('Please enter a pattern or load a sample first.');
        return;
    }
    
    if (isGenerating) return;
    
    isGenerating = true;
    currentTask = 0;
    
    // UI Updates
    const grid = document.getElementById('deliverables-grid');
    const progress = document.getElementById('generation-progress');
    const progressBar = document.getElementById('progress-bar');
    const progressText = document.getElementById('progress-text');
    const currentTaskEl = document.getElementById('current-task');
    
    grid.classList.remove('opacity-50', 'pointer-events-none');
    progress.classList.remove('hidden');
    
    // Disable all check icons initially
    document.querySelectorAll('.check-icon').forEach(icon => {
        icon.classList.remove('text-green-400');
        icon.classList.add('text-slate-600');
    });
    
    // Update stat badges
    document.querySelectorAll('.status-badge').forEach(badge => {
        badge.textContent = 'Generating...';
        badge.classList.add('text-indigo-400');
    });
    
    document.getElementById('total-status').textContent = 'Processing';
    document.getElementById('total-status').className = 'text-xs bg-indigo-500 text-white px-2 py-1 rounded-full mono animate-pulse';
    
    // Process tasks
    let totalProgress = 0;
    const totalDuration = tasks.reduce((acc, t) => acc + t.time, 0);
    let elapsed = 0;
    
    function processNextTask() {
        if (currentTask >= tasks.length) {
            // Generate complete
            isGenerating = false;
            progress.classList.add('hidden');
            markComplete();
            document.getElementById('download-all-btn').disabled = false;
            document.getElementById('deliverable-count').textContent = '39/39 Generated';
            document.getElementById('total-status').textContent = 'Complete';
            document.getElementById('total-status').className = 'text-xs bg-green-500 text-white px-2 py-1 rounded-full mono';
            
            // Trigger confetti effect (simulated)
            showCompletionEffect();
            return;
        }
        
        const task = tasks[currentTask];
        currentTaskEl.textContent = task.name;
        
        const taskStart = Date.now();
        const taskInterval = setInterval(() => {
            const now = Date.now();
            const taskProgress = Math.min((now - taskStart) / task.time, 1);
            const taskWeightedProgress = (taskProgress * task.time) / totalDuration * 100;
            const totalProgress = (elapsed / totalDuration * 100) + taskWeightedProgress;
            
            progressBar.style.width = Math.min(totalProgress, 100) + '%';
            progressText.textContent = Math.floor(Math.min(totalProgress, 100)) + '%';
            
            if (taskProgress >= 1) {
                clearInterval(taskInterval);
                elapsed += task.time;
                currentTask++;
                processNextTask();
            }
        }, 50);
    }
    
    processNextTask();
    
    // Staggered card animations
    const cards = document.querySelectorAll('.category-card');
    cards.forEach((card, index) => {
        setTimeout(() => {
            card.classList.add('border-indigo-500/50');
            setTimeout(() => {
                card.classList.remove('border-indigo-500/50');
            }, 500);
        }, index * 800);
    });
}

function markComplete() {
    // Mark all items complete
    document.querySelectorAll('.check-icon').forEach((icon, index) => {
        setTimeout(() => {
            icon.classList.remove('text-slate-600');
            icon.classList.add('text-green-400');
        }, index * 50);
    });
    
    document.querySelectorAll('.status-badge').forEach(badge => {
        badge.textContent = 'Ready';
        badge.classList.remove('text-indigo-400');
        badge.classList.add('text-green-400');
    });
}

function downloadAll() {
    // Create a simulated download
    const blob = new Blob(['Pattern Suite Complete Package'], { type: 'application/zip' });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'pattern-suite-39-deliverables.zip';
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    URL.revokeObjectURL(url);
    
    // Show success message
    const btn = document.getElementById('download-all-btn');
    const originalText = btn.innerHTML;
    btn.innerHTML = '<i data-lucide="check" class="w-4 h-4"></i> Downloaded!';
    btn.classList.add('bg-green-600');
    lucide.createIcons();
    
    setTimeout(() => {
        btn.innerHTML = originalText;
        btn.classList.remove('bg-green-600');
        lucide.createIcons();
    }, 2000);
}

function showCompletionEffect() {
    // Simple pulse animation on complete
    document.querySelectorAll('.category-card').forEach((card, i) => {
        setTimeout(() => {
            card.classList.add('animate-pulse-glow');
            setTimeout(() => card.classList.remove('animate-pulse-glow'), 2000);
        }, i * 100);
    });
}

// Add hover effects for deliverable items
document.querySelectorAll('.category-card').forEach(card => {
    card.addEventListener('click', (e) => {
        if (e.target.closest('.flex.items-center.justify-between.text-sm')) {
            e.target.closest('.flex.items-center.justify-between.text-sm').classList.toggle('bg-indigo-900/30');
        }
    });
});